Skip to main content

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
Operational errors are different from agent errors, which are exceptions intentionally raised by the agent based on your business logic.

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 from AgenticaError, making it easy to catch all SDK-related errors.

Error Hierarchy

All operational errors inherit from AgenticaError. Errors not intentionally raised by the agent may be caught as exceptions inheriting from this base class, which is exported by the SDK under .
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

Connection Errors

Invocation Errors

Inference Service Errors

These errors originate from the inference service and are forwarded through the SDK:

Controlling Token Limits

The MaxTokensError 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.
For more details on 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
When you set , each inference request will stop generating when it reaches that limit. If the natural response would exceed this limit, a MaxTokensError will be raised, which you can catch and handle appropriately (see examples below).
Setting appropriate token limits upfront is more efficient than handling MaxTokensError after the fact, as it prevents wasted compute on overly long responses.

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.
If you need additional retry logic beyond what the platform provides (for example, for application-specific error handling or longer retry windows), you can implement your own retry strategy. You could implement a simple retry strategy like this:
which may be used to wrap any agentic function or agent call:
Since agentic functions are just functions already, you may also use widely available libraries such as to handle logic for retries.
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.
Once you get successful results, consider caching them. After retries produce a good response, you can cache it for future calls with the same inputs. This combines resilience with performance. See Caching for strategies.

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:
Use metrics from these logs to track fallback rates and identify patterns. High fallback rates are a useful diagnostic — they suggest opportunities to choose a model better suited to your task, refine your prompts, or provide additional context.

Caching

Caching with respect to inference is managed internally and specific to the model provider.
Previous agent invocations may be cached client-side. In Python, just use the @functools.cache decorator!

Rate limiting

When rate limits from providers are imposed, exponential backoff is employed with sensible defaults in a blocking fashion. The initial delay 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