Exceptions¶
Custom exception classes.
Exception Hierarchy¶
AgentError (base)
├── ConfigurationError
├── ModelBackendError
│ └── RateLimitError
├── ToolExecutionError
├── ContextOverflowError
├── MCPError
├── AuthenticationError
└── TimeoutError
Quick Example¶
from mamba_agents.errors import (
AgentError,
ModelBackendError,
RateLimitError,
AuthenticationError,
ToolExecutionError,
ContextOverflowError,
)
try:
result = await agent.run(query)
except RateLimitError as e:
print(f"Rate limited, retry after: {e.retry_after}s")
except AuthenticationError:
print("Invalid API key")
except ModelBackendError as e:
print(f"Model error: {e}")
except ToolExecutionError as e:
print(f"Tool {e.tool_name} failed: {e}")
except ContextOverflowError as e:
print(f"Context overflow: {e.current_tokens}/{e.max_tokens} tokens")
except AgentError as e:
print(f"Agent error: {e}")
API Reference¶
AgentError
¶
Bases: Exception
Base exception for all agent errors.
All custom exceptions in this framework inherit from this class, allowing for easy catching of all agent-related errors.
| ATTRIBUTE | DESCRIPTION |
|---|---|
message |
Human-readable error message.
|
cause |
Original exception that caused this error.
|
details |
Additional error context as key-value pairs.
|
Details can be accessed as attributes (e.g., error.config_key).
Initialize the error.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Human-readable error message.
TYPE:
|
cause
|
Original exception that caused this error.
TYPE:
|
**details
|
Additional error context.
TYPE:
|
Source code in src/mamba_agents/errors/exceptions.py
ConfigurationError
¶
Bases: AgentError
Error in agent configuration.
Raised when configuration is invalid, missing required fields, or contains incompatible settings.
Attributes from details: config_key, expected, actual.
Source code in src/mamba_agents/errors/exceptions.py
ModelBackendError
¶
Bases: AgentError
Error from the model backend.
Raised when the underlying model API returns an error, times out, or is unavailable.
Attributes from details: model, status_code, response_body, retryable (default: False).
Source code in src/mamba_agents/errors/exceptions.py
RateLimitError
¶
Bases: ModelBackendError
Rate limit exceeded.
Raised when the model API rate limit is hit.
Attributes from details: retry_after.
Source code in src/mamba_agents/errors/exceptions.py
AuthenticationError
¶
Bases: AgentError
Authentication failed.
Raised when API authentication fails, typically due to invalid or expired credentials.
Source code in src/mamba_agents/errors/exceptions.py
ToolExecutionError
¶
ToolExecutionError(
message: str,
*,
tool_name: str | None = None,
tool_args: dict[str, Any] | None = None,
**kwargs: Any,
)
Bases: AgentError
Error during tool execution.
Raised when a tool fails to execute properly, either due to invalid arguments, permission issues, or runtime errors.
Attributes from details: tool_name, tool_args.
Source code in src/mamba_agents/errors/exceptions.py
ContextOverflowError
¶
Bases: AgentError
Context window exceeded.
Raised when the conversation context exceeds the model's maximum context window and cannot be compacted further.
Attributes from details: current_tokens, max_tokens, compaction_attempted (default: False).
Source code in src/mamba_agents/errors/exceptions.py
MCPError
¶
Bases: AgentError
Error from MCP server interaction.
Raised when communication with an MCP server fails, the server returns an error, or authentication fails.
Attributes from details: server_name, server_url.
Source code in src/mamba_agents/errors/exceptions.py
TimeoutError
¶
Bases: AgentError
Operation timed out.
Raised when an operation exceeds its timeout limit.
Attributes from details: timeout_seconds, operation.