Error Handling in Multi-Agent Systems
Proper error handling is critical in multi-agent systems where failures can cascade across multiple agents. This guide covers best practices for building resilient multi-agent applications.Core Principles
1. Fail Fast and Gracefully
PraisonAI now ships a built-in tool circuit breaker that wraps every tool call automatically. See Tool Circuit Breaker. The examples below show how to extend or customise that pattern.
2. Implement Circuit Breakers
Prevent cascading failures by implementing circuit breaker patterns:Error Handling Strategies
1. Agent-Level Error Handling
Each agent should have its own error handling logic:2. Task-Level Error Handling
Implement error boundaries at the task level:3. System-Level Error Handling
Implement comprehensive error handling at the system level:Error Recovery Patterns
1. Compensation Pattern
Implement compensating actions when errors occur:2. Saga Pattern
For long-running multi-agent transactions:Monitoring and Alerting
1. Error Metrics Collection
2. Health Checks
Implement health checks for your agents:Best Practices
-
Use Structured Logging: Always include context in your error logs
-
Implement Timeouts: Prevent hanging operations
-
Use Error Boundaries: Contain errors at appropriate levels
-
Implement Graceful Degradation: Provide reduced functionality rather than complete failure
Handling Empty Agent Responses
An agent can return an empty string when the model produces no content — a content filter, a safety refusal, or alength truncation with zero output tokens.
Check for an empty reply and branch accordingly:
achat results for an empty string:
Empty-response handling is symmetric across sync (
chat) and async (achat) as of PR #4255. The async path previously returned an SDK object repr — for example ChatCompletion(...) — for these cases; it now returns an empty string to match the sync path.finish_reason, the agent logs a WARNING. See Understanding Agent WARNING Logs for what each reason means and how to respond.
Getting the specific reason
The empty string is only half the story — the agent also records a distinctlast_stop_reason alongside it, so you can branch on why nothing came back.
Structured outcome
For a typed result instead of an empty-string check, opt intoreturn_outcome=True — a blocked run returns a RunOutcome whose reason is the specific provider block.
Common Pitfalls to Avoid
- Silent Failures: Always log errors, even if handled
- Retry Storms: Implement exponential backoff for retries
- Error Propagation: Don’t let errors cascade unnecessarily
- Resource Leaks: Ensure cleanup in error paths
- Ignoring Partial Failures: Handle partial success scenarios

