Execution Modes
Run (Blocking)
The simplest way to execute an agent - start and wait for completion:run_blocking.py
- 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:start_wait.py
- 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:state_running.py
Completed
Agent successfully finished the task:state_completed.py
Failed
Agent encountered an error:state_failed.py
Stopped (Max Steps)
Agent reached maximum step limit:state_max_steps.py
Monitoring Progress
Status Checking
Check agent progress at any time:status_checking.py
Live Log Streaming
Stream agent logs in real-time via WebSocket:live_log_streaming.py
Polling Pattern
Check status periodically:polling_pattern.py
Parallel Execution
Multiple Independent Agents
Run multiple agents simultaneously:parallel_agents.py
Batch Execution
UseBatchRemoteAgent for parallel execution with strategies:
batch_execution.py
Stopping Agents
Manual Stop
Stop a running agent:manual_stop.py
Timeout Pattern
Implement custom timeouts:timeout_pattern.py
Response Structure
Agent responses contain execution details:response_structure.py
Step Details
Inspect individual steps:step_details.py
Error Handling
Graceful Degradation
Handle failures gracefully:graceful_degradation.py
Retry Pattern
Retry failed agents:agent_retry.py
Agent Fallback
UseAgentFallback for automatic error recovery:
agent_fallback_example.py
Best Practices
1. Use Appropriate Execution Mode
bp_execution_mode.py
2. Always Check Success
bp_check_success.py
3. Set Appropriate Step Limits
bp_step_limits.py
4. Clean Up Resources
bp_cleanup.py

