RetryAgentRun exception allows you to provide instructions to the model for how to change its behavior and have the model retry within the current agent run. The exception message is passed to the model as a tool call error, allowing the model to adjust its approach in the next iteration of the LLM loop.
This does not retry the full agent run—it only provides feedback to the model within the current run’s tool call loop.
Constructor
Parameters
The error message to pass to the model. This message provides instructions or feedback to help the model adjust its behavior in the next iteration.
An optional message to display to the user about the retry.
An optional message from the agent’s perspective about the retry.
An optional list of messages to add to the conversation history.
When to Use
UseRetryAgentRun when:
- Validation fails: Input doesn’t meet requirements, and you want the model to try again with corrected input
- State requirements: The current state doesn’t meet prerequisites, and you want the model to perform additional actions
- Business logic: A condition isn’t met, and you want to guide the model on how to proceed
- Iterative refinement: You want the model to improve its approach based on feedback
Behavior
WhenRetryAgentRun is raised:
- The exception message is added to the tool call result as an error
- The model receives this error in the next LLM call
- The model can adjust its approach and retry the tool call or try a different approach
- The agent run continues (does not stop or exit)
- All messages and tool calls are preserved in the session