Model retry middleware for agents.
Base middleware class for an agent.
Subclass this and implement any of the defined methods to customize agent behavior between steps in the main agent loop.
State schema for the agent.
Model request information for the agent.
Response from model execution including messages and optional structured output.
The result will usually contain a single AIMessage, but may include an additional
ToolMessage if the model used a tool for structured output.
Middleware that automatically retries failed model calls with configurable backoff.
Supports retrying on specific exceptions and exponential backoff.
Type for specifying failure handling behavior.
Can be either:
'error' or 'continue')
'error': Re-raise the exception, stopping agent execution.'continue': Inject a message with the error details, allowing the agent to continue.
For tool retries, a ToolMessage with the error details will be injected.
For model retries, an AIMessage with the error details will be returned.Type for specifying which exceptions to retry on.
Can be either:
isinstance checks)True if it should be retried