Execution Modes
Run (Blocking)
The simplest way to execute an agent - start and wait for completion:- Simple scripts
- Synchronous workflows
- You don’t need to do other work while the agent runs
Start + Wait (Non-blocking)
Start the agent and wait for completion separately:- You need to start multiple agents in parallel
- You want to do other work while the agent runs
- You need more control over execution
Async Execution
Run agents asynchronously withasync/await:
async_agent.py
- Building async applications
- Running multiple agents concurrently
- Integrating with async frameworks (FastAPI, aiohttp)
Agent States
Agents transition through these states during execution:Running
Agent is actively executing:Completed
Agent successfully finished the task:Failed
Agent encountered an error:Stopped (Max Steps)
Agent reached maximum step limit:Monitoring Progress
Status Checking
Check agent progress at any time:Live Log Streaming
Stream agent logs in real-time via WebSocket:Polling Pattern
Check status periodically:Parallel Execution
Multiple Independent Agents
Run multiple agents simultaneously:parallel_agents.py
Batch Execution
UseBatchRemoteAgent for parallel execution with strategies:
Stopping Agents
Manual Stop
Stop a running agent:Timeout Pattern
Implement custom timeouts:Response Structure
Agent responses contain execution details:Step Details
Inspect individual steps:Error Handling
Graceful Degradation
Handle failures gracefully:Retry Pattern
Retry failed agents:agent_retry.py
Agent Fallback
UseAgentFallback for automatic error recovery:

