Agent Execution
Control agent execution limits – iterations, time, rate limiting, and retries
See also: Five-Layer Agent Stack — Execution is Layer 4 (the Loop).
Execution configuration controls how agents run – maximum iterations, time limits, rate limiting, and retry behavior.
graph LR
subgraph "Execution Limits"
Iter[🔄 Iterations<br/>max_iter=20]
Time[⏱️ Time<br/>max_execution_time]
Rate[📊 Rate<br/>max_rpm]
Retry[🔁 Retries<br/>max_retry_limit]
end
Iter --> Agent[🤖 Agent]
Time --> Agent
Rate --> Agent
Retry --> Agent
classDef limit fill:#F59E0B,stroke:#7C90A0,color:#fff
classDef agent fill:#10B981,stroke:#7C90A0,color:#fff
class Iter,Time,Rate,Retry limit
class Agent agentQuick Start
- Preset Mode
python from praisonaiagents import Agent # Use a preset agent = Agent( name="Fast Agent", instructions="You answer quickly", execution="fast" # Preset: limited iterations ) - Custom Configuration
python from praisonaiagents import Agent, ExecutionConfig agent = Agent( name="Thorough Agent", instructions="You do comprehensive analysis", execution=ExecutionConfig( max_iter=50, # Max iterations max_rpm=100, # Requests per minute max_execution_time=300, # 5 minute timeout max_retry_limit=5, # Retries on failure ) )
Execution Presets
graph TB
subgraph "Presets"
Fast[⚡ fast<br/>max_iter=10]
Balanced[⚖️ balanced<br/>max_iter=20]
Thorough[🔍 thorough<br/>max_iter=50]
Unlimited[♾️ unlimited<br/>No limits]
end
Fast -->|"Quick tasks"| Use[Use Case]
Balanced -->|"Most tasks"| Use
Thorough -->|"Complex tasks"| Use
Unlimited -->|"Long-running"| Use
classDef fast fill:#10B981,stroke:#7C90A0,color:#fff
classDef balanced fill:#189AB4,stroke:#7C90A0,color:#fff
classDef thorough fill:#F59E0B,stroke:#7C90A0,color:#fff
classDef unlimited fill:#6366F1,stroke:#7C90A0,color:#fff
class Fast fast
class Balanced balanced
class Thorough thorough
class Unlimited unlimited| Preset | max_iter | Use Case |
|---|---|---|
fast | 10 | Quick responses |
balanced | 20 | Standard tasks |
thorough | 50 | Complex analysis |
unlimited | None | Long-running jobs |
agent = Agent(instructions="...", execution="fast")
agent = Agent(instructions="...", execution="balanced")
agent = Agent(instructions="...", execution="thorough")
agent = Agent(instructions="...", execution="unlimited")Configuration Options
from praisonaiagents import ExecutionConfig
config = ExecutionConfig(
max_iter=20, # Maximum iterations
max_rpm=None, # Requests per minute (None = no limit)
max_execution_time=None, # Timeout in seconds (None = no limit)
max_retry_limit=2, # Retries on failure
)| Option | Type | Default | Description |
|---|---|---|---|
max_iter | int | 20 | Maximum loop iterations |
max_rpm | int | None | Rate limit (requests/minute) |
max_execution_time | int | None | Timeout in seconds |
max_retry_limit | int | 2 | Max retries on failure |
Iteration Limits
Prevent infinite loops:
sequenceDiagram
participant Agent
participant Counter
loop Until done or max_iter
Agent->>Agent: Execute step
Agent->>Counter: Increment
Counter-->>Agent: Count
alt count >= max_iter
Agent->>Agent: Stop
end
endagent = Agent(
instructions="You solve problems iteratively",
execution=ExecutionConfig(max_iter=30)
)
# Agent stops after 30 iterations even if not doneTime Limits
Prevent runaway execution:
agent = Agent(
instructions="You analyze data",
execution=ExecutionConfig(
max_execution_time=60 # Stop after 60 seconds
)
)graph LR
Start[▶ Start] --> Timer[⏱️ Timer]
Timer --> Execute[Execute]
Execute -->|"Time < limit"| Continue[Continue]
Execute -->|"Time >= limit"| Stop[⏹️ Stop]
Continue --> Execute
classDef timer fill:#F59E0B,stroke:#7C90A0,color:#fff
classDef action fill:#10B981,stroke:#7C90A0,color:#fff
class Timer timer
class Start,Execute,Continue,Stop actionRate Limiting
Control API request rate:
agent = Agent(
instructions="You search the web",
execution=ExecutionConfig(
max_rpm=60 # Max 60 requests per minute
)
)Useful for:
- Respecting API rate limits
- Controlling costs
- Preventing abuse
Retry Behavior
Handle transient failures:
agent = Agent(
instructions="You call external APIs",
execution=ExecutionConfig(
max_retry_limit=3 # Retry up to 3 times
)
)sequenceDiagram
participant Agent
participant API
Agent->>API: Request
API-->>Agent: Error
Note over Agent: Retry 1
Agent->>API: Request
API-->>Agent: Error
Note over Agent: Retry 2
Agent->>API: Request
API-->>Agent: SuccessMulti-Agent Execution
For multi-agent workflows:
from praisonaiagents import AgentTeam, MultiAgentExecutionConfig
team = AgentTeam(
agents=[agent1, agent2],
execution=MultiAgentExecutionConfig(
max_iter=10, # Per task
max_retries=5, # Per task
)
)Combining Limits
Use multiple limits together:
agent = Agent(
instructions="You do comprehensive research",
execution=ExecutionConfig(
max_iter=100, # Allow many iterations
max_execution_time=600, # But stop after 10 minutes
max_rpm=30, # Rate limit API calls
max_retry_limit=3, # Retry failures
)
)Best Practices
Set appropriate iteration limits
Too low = incomplete tasks. Too high = wasted resources. Start with defaults and adjust.
Use time limits for production
Always set max_execution_time in production to prevent runaway agents.
Rate limit external API calls
Use max_rpm when agents call external APIs to respect rate limits.
Enable retries for unreliable operations
Set max_retry_limit for operations that may fail transiently.