Model calls
- Fit the timeouts to your slowest model call. Restate receives no journal entry while a model call runs. After the inactivity timeout, 1 minute by default, Restate asks the handler to suspend. If the attempt is still running after the abort timeout, 10 more minutes by default, Restate aborts it. If your model calls can take longer, increase these timeouts for the handlers that make the model calls: the agent’s handlers, or the gateway’s handler with
modelGateway. See Timeouts between Restate and the service. - Set the retry policy of the model. By default, a model call makes three attempts, retried after 50 and 100 milliseconds unless the provider requests a longer delay, and the run then fails. Set
retryon the model to recover from longer provider outages. See Retries. - Set
maxOutputTokensif you expect long replies. When it’s unset, the provider chooses the limit, and a reply cut off at the limit fails the run. See Reply limit. - Limit concurrent agents. Use concurrency limits to control model spend.
Limits and context
- Check the run limits. By default, a run takes at most 10 steps (
maxSteps) and makes at most 128 tool calls (maxToolCalls). A run that reaches a limit returns the statusstopped, so handle that status in your handler. See Limits. - Set
contextWindowto the model’s context window. Without it, compaction starts at 170,000 tokens, so a model with a window under 200,000 tokens overflows first, and the run recovers from an overflow only when the provider returns HTTP413or the error codecontext_length_exceeded. Any other overflow error fails the run. See Context window.
Tools
- Set a retry policy on tools that call external APIs. By default, an async tool makes three attempts, retried after 50 and 100 milliseconds, and the model then receives the error. See Async tools.
- Make external writes idempotent. A tool can run again after a retry or a crash. Build an idempotency key from
invocationId, the run’sname, andcallId. See Async tools.
Sessions
- Preload only the conversation’s metadata and summary. By default, every invocation of the object receives the whole conversation. With Restate 1.8 or later, set
state: {preload: ["conversation/meta", "conversation/summary"]}in the options of each object that usesConversation, so that each invocation fetches only the chunks that it reads. See Lazy state. - Send requests with an idempotency key, so that a client that retries a request doesn’t add a second turn to the conversation. See Long runs.
- Cancel stuck agents instead of killing them. A cancelled run records a
cancelledresult with the reason for each unfinished tool call. See Failed runs.