Middleware that automatically retries failed tool calls with configurable backoff.
Supports retrying on specific exceptions and exponential backoff.
ToolRetryMiddleware(
self,
*,
max_retries: int = 2,
tools: list[BaseTool | str] | None = None,
retry_on: RetryOn = (Exception,),
on_failure: OnFailure = 'continue',
backoff_factor: float = 2.0,
initial_delay: float = 1.0,
max_delay: float = 60.0,
jitter: bool = True
)| Name | Type | Description |
|---|---|---|
max_retries | int | Default: 2Maximum number of retry attempts after the initial call. Must be |
tools | list[BaseTool | str] | None | Default: NoneOptional list of tools or tool names to apply retry logic to. Can be a list of If |
retry_on | RetryOn | Default: (Exception,)Either a tuple of exception types to retry on, or a callable
that takes an exception and returns Default is to retry on all exceptions. |
on_failure | OnFailure | Default: 'continue'Behavior when all retries are exhausted. Options:
Deprecated values (for backwards compatibility):
|
backoff_factor | float | Default: 2.0Multiplier for exponential backoff. Each retry waits Set to |
initial_delay | float | Default: 1.0Initial delay in seconds before first retry. |
max_delay | float | Default: 60.0Maximum delay in seconds between retries. Caps exponential backoff growth. |
jitter | bool | Default: TrueWhether to add random jitter ( |
Start the shell session and run startup commands.
Async start the shell session and run startup commands.
Check model call limits before making a model call.
Async check model call limits before making a model call.
Check for parallel write_todos tool calls and return errors if detected.
Check for parallel write_todos tool calls and return errors if detected.
Update the system message to include the todo system prompt.
Update the system message to include the todo system prompt.
Run shutdown commands and release resources when an agent completes.
Async run shutdown commands and release resources when an agent completes.