Execution

Control how agents run – iterations, timeouts, and limits

Configure execution limits to prevent runaway agents and control costs.

Diagram

Execution Control

🤖 Agent

⏱️ Limits

🔄 Max Iterations

⏰ Timeout

Quick Start

  1. Default Execution
    rust
    use praisonai::Agent;
    
    // Uses safe defaults: 10 max iterations
    let agent = Agent::new()
        .name("Assistant")
        .instructions("You are a helpful assistant")
        .build()?;
    
    let response = agent.chat("Hello!").await?;
  2. Custom Iteration Limits
    rust
    use praisonai::Agent;
    
    // Limit tool loops to prevent runaway agents
    let agent = Agent::new()
        .name("Assistant")
        .max_iterations(5)  // Max 5 tool call loops
        .build()?;
    
    let response = agent.chat("Research this topic").await?;
  3. High-Volume Agent
    rust
    use praisonai::Agent;
    
    // Allow more iterations for complex tasks
    let agent = Agent::new()
        .name("Researcher")
        .max_iterations(20)  // Allow more tool calls
        .verbose(true)       // Monitor progress
        .build()?;

Configuration

AgentBuilder MethodTypeDefaultDescription
.max_iterations(n)usize10Maximum tool call loops
.verbose(bool)boolfalseEnable verbose output
.stream(bool)booltrueEnable streaming

Best Practices

Set reasonable iteration limits

5-10 iterations handles most tasks. Higher values risk infinite loops.

Use timeouts for safety

Always set timeouts to prevent stuck agents from running indefinitely.


Related