Skip to main content
Handle errors gracefully to build robust agent applications.

Quick Start

1

Handle Errors

use praisonai::Agent;

let agent = Agent::new()
    .name("Assistant")
    .build()?;

match agent.chat("Hello").await {
    Ok(response) => println!("{}", response),
    Err(e) => println!("Error: {}", e),
}
2

With Retries

use praisonai::{Agent, ExecutionConfig};

let config = ExecutionConfig::new()
    .max_retries(3);

let agent = Agent::new()
    .name("Reliable Bot")
    .execution(config)
    .build()?;

Error Types

ErrorCauseSolution
ApiErrorAPI call failedCheck API key, retry
TimeoutErrorRequest too slowIncrease timeout
ToolErrorTool execution failedCheck tool logic
ConfigErrorInvalid configurationCheck config values

Common Patterns

Graceful Fallback

let response = agent.chat("Question").await
    .unwrap_or_else(|_| "Sorry, I encountered an error.".to_string());

Logging Errors

if let Err(e) = agent.chat("Question").await {
    log::error!("Agent error: {}", e);
    // Handle gracefully
}

Best Practices

Never use unwrap() in production code.
3 retries is usually enough for transient failures.
Keep detailed logs to diagnose issues later.