- Transient errors: Temporary issues like network failures or rate limits. Restate automatically retries these until they succeed or the retry policy is exhausted.
- Terminal errors: Permanent failures like invalid input or business rule violations. Restate does not retry these. The invocation fails permanently. You can catch these errors and handle them gracefully.
Retrying LLM calls
LLM API calls can suffer from transient failures (rate limits, network issues, provider outages). Restate retries failed LLM calls so your agents recover automatically.Default behavior
Vercel AI
OpenAI Agents
Google ADK
Pydantic AI
Restate TS
Restate Py
The Vercel AI SDK and the Restate middleware each have their own retry layer, and they compose.The Vercel AI SDK does the first layer of retries based on what is set for
maxRetries on generateText (default: 2) . Once those are exhausted, the AI SDK throws an error.Restate then takes over and retries the invocation. Each Restate retry replays the call, which goes through maxRetries Vercel AI SDK attempts again.By default, Restate’s retries follow the policy configured at the service or handler level, or otherwise the Restate server’s default policy.
Restate will go through a limited set of retries with exponential backoff (see default policy), after which the invocation will be paused. This gives you time to fix the issue, and then resume the invocation.Setting a retry policy
Vercel AI
OpenAI Agents
Google ADK
Pydantic AI
LangChain
Restate TS
Restate Py
To set a separate retry policy for LLM calls, pass If you set a maximum number of retry attempts, Restate will still go through the AI SDK’s
RunOptions to the durableCalls middleware:errorhandling/fail-on-terminal-tool-agent.ts
maxRetries for each attempt, so the two limits multiply (e.g. maxRetryAttempts: 3 × maxRetries: 2 = up to 6 attempts).Once Restate’s retries are exhausted, the invocation fails with a TerminalError and won’t be retried further. You can catch the Terminal Error in your handler and act accordingly.Tool execution errors
Restate makes tool execution resilient by retrying transient errors and propagating terminal ones.Transient errors
Vercel AI
OpenAI Agents
Google ADK
Pydantic AI
Restate TS
Restate Py
By default, the Vercel AI SDK converts any errors in tool executions into a message to the LLM, and the agent decides how to proceed. This is often desirable, as the LLM can decide to use a different tool or provide a fallback answer.When you wrap external calls in Restate Context actions like Restate then retries the whole invocation according to the policy configured at the service or handler level, or otherwise the Restate server’s default policy.
ctx.run, Restate retries transient errors within the Context action before the result reaches the agent. This makes your tools resilient to network failures, database hiccups, and other temporary issues. For all operations that might suffer from transient errors, use Context actions:Setting a retry policy on run actions
Vercel AI
OpenAI Agents
Google ADK
Pydantic AI
Restate TS
Restate Py
If you do run actions in your tools, you can override the default retry policy by passing See custom retry policies for more options. When retries are exhausted, the tool will fail with a Terminal Error.
RunOptions:Terminal errors
For errors that should not be retried (invalid input, business rule violations, resource not found), use aTerminalError in your tool. Restate does not retry these:
Vercel AI
OpenAI Agents
Google ADK
Pydantic AI
LangChain
Restate TS
Restate Py
Fail the agent on terminal tool errors
Fail the agent on terminal tool errors
To fail the agent on terminal tool errors, rethrow the error in
onStepFinish:errorhandling/fail-on-terminal-tool-agent.ts
Stop the agent on terminal tool errors
Stop the agent on terminal tool errors
To stop the agent on terminal tool errors and handle it after the agent finishes, you can use
hasTerminalToolError in stopWhen and then inspect the steps for errors:errorhandling/stop-on-terminal-tool-agent.ts