Skip to main content
Agents support multiple execution patterns - from simple blocking calls to advanced asynchronous monitoring. Choose the right pattern for your use case.

Execution Modes

Run (Blocking)

The simplest way to execute an agent - start and wait for completion:
run_blocking.py
When to use:
  • 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
When to use:
  • 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 with async/await:
async_agent.py
When to use:
  • 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

Stopping Agents

Manual Stop

Stop a running agent:
manual_stop.py
Note: You cannot stop agents once they complete a step - they must finish the current action.

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

Use AgentFallback for automatic error recovery:
agent_fallback_example.py
See Agent Fallback for details.

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

Next Steps

Configuration

Configure agent parameters

Agent Fallback

Automatic error recovery

Replay

Debug with visual replays