Exception handling for agent runs, model errors, and validation.
from agno.exceptions import (
AgnoError,
AgentRunException,
RetryAgentRun,
StopAgentRun,
RunCancelledException,
ModelAuthenticationError,
ModelProviderError,
ModelRateLimitError,
InputCheckError,
OutputCheckError,
EvalError,
CheckTrigger
)
class AgnoError(Exception):
"""Base exception for all Agno errors"""
def __init__(self, message: Optional[str] = None, **kwargs): ...
class AgentRunException(Exception):
"""Exception during agent run (does not inherit from AgnoError)"""
def __init__(self, message: Optional[str] = None, **kwargs): ...
class RetryAgentRun(AgnoError):
"""Retry the agent run"""
def __init__(self, message: Optional[str] = None, **kwargs): ...
class StopAgentRun(AgnoError):
"""Stop the agent run"""
def __init__(self, message: Optional[str] = None, **kwargs): ...
class RunCancelledException(AgnoError):
"""Run was cancelled"""
def __init__(self, message: Optional[str] = None, **kwargs): ...
class ModelAuthenticationError(AgnoError):
"""Model authentication failed"""
def __init__(self, message: Optional[str] = None, **kwargs): ...
class ModelProviderError(AgnoError):
"""Model provider error"""
def __init__(self, message: Optional[str] = None, **kwargs): ...
class ModelRateLimitError(AgnoError):
"""Model rate limit exceeded"""
def __init__(self, message: Optional[str] = None, **kwargs): ...
class InputCheckError(AgnoError):
"""Input validation failed"""
def __init__(
self,
message: Optional[str] = None,
trigger: Optional[CheckTrigger] = None,
**kwargs
): ...
class OutputCheckError(AgnoError):
"""Output validation failed"""
def __init__(
self,
message: Optional[str] = None,
trigger: Optional[CheckTrigger] = None,
**kwargs
): ...
class EvalError(AgnoError):
"""Evaluation error"""
def __init__(self, message: Optional[str] = None, **kwargs): ...
class CheckTrigger(str, Enum):
"""Enum for when a check is triggered"""
input = "input"
output = "output"from agno.exceptions import RetryAgentRun
try:
response = agent.run("Query")
except RetryAgentRun:
# Retry logic
response = agent.run("Query")from agno.agent import Agent
# Start long-running task
response = agent.run("Complex task", stream=True)
# Cancel if needed
Agent.cancel_run(response.run_id)