Quick Start
Configuration Options
| Parameter | Type | Default | Description |
|---|---|---|---|
max_iter | int | 20 | Maximum tool-calling iterations. Now propagated to the LLM instance, so it controls every internal loop (previously some loops were hardcoded to 5/10/20/50). Both the ExecutionConfig default and the LLM-direct-construction default are 20 (aligned as of PR #1898). |
max_rpm | int | None | None | Max requests per minute (rate limit) |
max_execution_time | int | None | None | Max execution time in seconds |
max_retry_limit | int | 2 | Max retries on failure |
max_tool_calls_per_turn | int | 10 | Maximum tool calls allowed in a single chat turn. When exceeded, execution stops with a clear message instead of looping forever. |
context_compaction | bool | ContextCompactionPolicy | False | Proactive context-overflow protection. True uses the BALANCED_POLICY preset. Pass a ContextCompactionPolicy instance for custom routing. Default flips to True in the next release — a DeprecationWarning is emitted today when left at False. See Context Compaction Policy. |
max_budget | float | None | None | Hard USD cap per agent run. None = no limit. |
on_budget_exceeded | str | callable | "stop" | Action when limit is hit: "stop" raises BudgetExceededError, "warn" logs and continues, or a callable(total_cost, max_budget). |
For simple budget limits, use the
Agent(max_budget=...) convenience parameter instead of importing ExecutionConfig. See Agent max_budget for details.Execution Presets
| Preset | max_iter | Description |
|---|---|---|
"fast" | 10 | Quick tasks, fewer iterations |
"balanced" | 20 | Default, balanced approach |
"thorough" | 50 | Complex tasks, more iterations |
"unlimited" | 1000 | Long-running tasks |
Iteration Propagation
ExecutionConfig.max_iter is now the single source of truth for iteration limits, replacing previously hardcoded internal caps.
Before: Internal LLM loops were hardcoded to different limits (5, 10, 20, 50)
After: All loops respect the configured max_iter value
Proactive Context Compaction
Context compaction proactively prevents overflow before LLM calls instead of reacting after errors.Common Patterns
Pattern 1: Rate-Limited Agent
Pattern 2: Time-Bounded Agent
Pattern 3: Resilient Agent
Pattern 4: Loop-Protected Agent
Best Practices
Set Iteration Limits
Set Iteration Limits
Always set
max_iter to prevent runaway agents consuming resources.Use Rate Limiting for APIs
Use Rate Limiting for APIs
Set
max_rpm when calling external APIs to avoid rate limit errors.Set Timeouts for Production
Set Timeouts for Production
Use
max_execution_time in production to prevent hung processes.Configure Loop Protection
Configure Loop Protection
Adjust
max_tool_calls_per_turn based on your tools: lower for experimental tools (3-5), higher for complex multi-tool workflows (20-30).Related
Context Compaction Policy
Proactive context overflow protection
LLM Error Classification
Iteration control and error handling integration
Async Execution
Async agent execution
Background Tasks
Run agents in background
Structured LLM Errors
LLM error handling and retry policies

