Overview
Agentic operations can fail due to factors outside your code — infrastructure issues, network problems, or service limitations. These operational errors originate from the platform or external services, not from your application logic or the agent’s decisions. Common operational errors include:- Inference errors: When the underlying model fails to respond
- Network/API errors: Connection failures, rate limits
- Sandbox errors: Communication issues between the model and its execution environment
- Internal server errors: Platform infrastructure problems
When Errors Reach You
The platform handles most operational errors automatically. The Agentica SDK employs retry strategies with exponential backoff and jitter for transient failures like inference rate limits, temporary network issues, and service unavailability. You only see errors that are unrecoverable at the platform level. When an error bubbles up to your code, it means the platform has exhausted its retry attempts and the operation cannot be completed without intervention. This design keeps your error handling focused on genuinely exceptional situations. For errors that do reach your code, you should handle them as you would for any other async network operation — with try/catch blocks, additional retry logic if appropriate, and fallback strategies. Some of these errors may represent limitations or bugs in the Agentica SDK itself, please see Reporting Bugs for information about how to report such bugs to us.Error Types
The Agentica SDK exports a comprehensive set of error classes to help you handle different failure scenarios. All errors inherit fromAgenticaError, making it easy to catch all SDK-related errors.
Error Hierarchy
All operational errors inherit fromAgenticaError. Errors not intentionally raised by the agent may be caught as exceptions inheriting from this base class, which is exported by the SDK under .
Complete Error Reference
Complete Error Reference
All errors inherit from
AgenticaError. The hierarchy organizes errors by their source: connection issues, agent invocation problems, or errors from the inference service.Base Exceptions
| Error | Description |
|---|---|
AgenticaError | Base exception for all Agentica SDK errors. Catch this to handle any error not purposefully raised by the agent. |
ServerError | Base class for errors during remote operations. Parent of GenerationError. |
GenerationError | Base class for errors during agent generation. Parent of inference-related errors. |
InferenceError | Base class for HTTP errors from the inference service. Parent of most API errors below. |
Connection Errors
| Error | Parent | Description |
|---|---|---|
ConnectionError | AgenticaError | General connection failure |
WebSocketConnectionError | ConnectionError | WebSocket connection failed or was interrupted |
WebSocketTimeoutError | ConnectionError | WebSocket connection timed out |
Invocation Errors
| Error | Parent | Description |
|---|---|---|
InvocationError | AgenticaError | General error during agent invocation |
TooManyInvocationsError | InvocationError | Exceeded maximum number of invocations |
NotRunningError | InvocationError | Attempted to use an agent that is not running |
Inference Service Errors
These errors originate from the inference service and are forwarded through the SDK:| Error | Parent | Description |
|---|---|---|
MaxTokensError | GenerationError | Response exceeded maximum token limit |
ContentFilteringError | GenerationError | Content was filtered by safety systems |
APIConnectionError | InferenceError | Failed to connect to the inference API |
APITimeoutError | InferenceError | Inference API request timed out |
RateLimitError | InferenceError | Rate limit exceeded, slow down requests |
BadRequestError | InferenceError | Request was malformed or invalid (400) |
UnauthorizedError | InferenceError | Authentication failed or missing (401) |
PermissionDeniedError | InferenceError | Insufficient permissions (403) |
NotFoundError | InferenceError | Requested resource not found (404) |
ConflictError | InferenceError | Request conflicts with current state (409) |
UnprocessableEntityError | InferenceError | Request understood but cannot be processed (422) |
RequestTooLargeError | InferenceError | Request payload too large for inference service |
InternalServerError | InferenceError | Internal server error (500) |
ServiceUnavailableError | InferenceError | Service temporarily unavailable (503) |
OverloadedError | InferenceError | Inference service is overloaded, try again later |
DeadlineExceededError | InferenceError | Operation exceeded its deadline |
Controlling Token Limits
TheMaxTokensError occurs when a response exceeds the maximum token limit. You can proactively control this by setting when creating agents or agentic functions. When an integer is supplied, this is the maximum number of output tokens for an invocation (across all rounds of inference). For more fine-grained control, use a MaxTokens object.
MaxTokens, see the .
Use cases for token limits:
- Cost control: Limit token usage per inference request to manage costs
- Response length: Ensure individual inference outputs meet length requirements
- Error prevention: Avoid unexpectedly long responses in a single inference request
MaxTokensError will be raised, which you can catch and handle appropriately (see examples below).
Catching Specific Errors
You can catch specific error types to implement different handling strategies. The error hierarchy lets you handle errors at different levels of granularity:Retry Strategies
The platform already retries most failures automatically using exponential backoff and jitter. When an error reaches your code, it means the platform’s built-in retry logic has been exhausted. You typically don’t need additional retry logic, but you may add it for application-specific requirements.
Remember that the platform has already retried transient failures before an error reaches your code. If an operation consistently fails even with your own additional retry logic, consider adjusting your prompts, providing more context, or choosing a different model rather than increasing retry attempts.
Error Logging
Proper logging of agentic operations helps you monitor reliability, debug failures, and identify patterns in errors. Log enough context to diagnose issues, but be mindful of sensitive data.Basic Structured Logging
Log agent failures with structured data that includes the operation, error type, and relevant context. This example shows agent-driven test generation with comprehensive logging:Sensitive Data Handling
Never log sensitive user data. Redact or omit PII while preserving enough context for debugging:Tracking Degraded Performance
When using fallback strategies, log which tier succeeded. Frequent fallbacks suggest reviewing your approach — consider trying a different model better suited to the task, refining your prompts, or providing additional context. This example shows agentic code review with quality tracking:Caching
Caching with respect to inference is managed internally and specific to the model provider.Rate limiting
When rate limits from providers are imposed, exponential backoff is employed with sensible defaults in a blocking fashion. The initialdelay is multiplied by a factor of exponential_base * (1 + jitter * random_float) with every retry till max_retries is reached, where 0.0 <= random_float < 1.0.
Next Steps
Agent Errors
Handle custom exceptions raised by agents
Best Practices
Production deployment best practices
Multi-Agent Systems
Handle errors in multi-agent systems
How It Works
Understand execution modes and RPC (Warp)
Reporting Bugs
Report bugs in the Agentica SDK