Context
Error handling in any tool.
Problem
Agents don't know whether to retry or try something different.
Solution
Classify errors clearly:
- Retryable: Transient, will likely succeed later
- Permanent: Won't succeed without changes
- User action needed: Requires human input
- Authentication: Need to re-auth
- Retryable: Transient, will likely succeed later
- Permanent: Won't succeed without changes
- User action needed: Requires human input
- Authentication: Need to re-auth
Examples
Python
class ErrorType(Enum):
RETRYABLE = "retryable" # Try again later
PERMANENT = "permanent" # Won't work without changes
AUTH_REQUIRED = "auth" # Need to re-authenticate
USER_INPUT = "user_input" # Need human input
@tool
def api_call(endpoint: str) -> Result:
try:
return api.call(endpoint)
except RateLimitError:
raise ToolError(
type=ErrorType.RETRYABLE,
message="Rate limited",
retry_after=60
)
except NotFoundError:
raise ToolError(
type=ErrorType.PERMANENT,
message="Resource not found"
)
except AuthError:
raise ToolError(
type=ErrorType.AUTH_REQUIRED,
message="Token expired"
) Considerations
- Use consistent error types across tools
- Include retry-after for retryable errors
- Map external API errors to your classification