Rust
Delete an AI execution context
delete_execution_context
pub async fn delete_execution_context(id: &str) -> Result<()>
Result<()>
use wacht::api::execution_context::*; let context_id = "ctx_123"; delete_execution_context(context_id).await?; println!("Execution context deleted successfully");
use wacht::api::execution_context::*; // Delete multiple contexts with error handling async fn cleanup_old_contexts(context_ids: Vec<String>) -> Result<()> { let mut deleted = 0; let mut errors = Vec::new(); for context_id in context_ids { match delete_execution_context(&context_id).await { Ok(()) => { deleted += 1; println!("Deleted context: {}", context_id); } Err(e) => { errors.push((context_id, e)); } } } println!("Successfully deleted {} contexts", deleted); if !errors.is_empty() { println!("Failed to delete {} contexts:", errors.len()); for (id, error) in errors { println!(" {}: {}", id, error); } } Ok(()) } // Clean up contexts for a specific agent async fn cleanup_agent_contexts(agent_id: &str) -> Result<()> { let options = ListExecutionContextsOptions { agent_id: Some(agent_id.to_string()), ..Default::default() }; let contexts = fetch_execution_contexts(Some(options)).await?; let context_ids: Vec<String> = contexts.data .into_iter() .filter_map(|c| c.id) .collect(); cleanup_old_contexts(context_ids).await }
match delete_execution_context("ctx_123").await { Ok(()) => { println!("Context deleted successfully"); } Err(Error::Api { status, message, .. }) => { match status.as_u16() { 404 => println!("Context not found: {}", message), 403 => println!("Access denied: {}", message), 409 => println!("Context in use: {}", message), _ => println!("API error {}: {}", status, message), } } Err(e) => println!("Delete failed: {}", e), }