Chat agent runs are pinned to the worker version they started on. When you deploy a new version, suspended runs resume on the old code. If your deploy includes breaking changes (new tools, changed schemas, updated API contracts), this can cause issues.Documentation Index
Fetch the complete documentation index at: https://trigger-docs-tri-7532-ai-sdk-chat-transport-and-chat-task-s.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
chat.requestUpgrade() lets the agent opt out of the current run so the transport triggers a new one on the latest version.
How it works
Whenchat.requestUpgrade() is called in onTurnStart or onValidateMessages:
run()is skipped — no response is generated on old code- The agent calls the server-side
endAndContinueSessionendpoint, which atomically swaps the Session’scurrentRunIdto a freshly-triggered run on the latest deployment (optimistic-claim againstcurrentRunVersion) - The new run picks up the conversation and produces the response
- The transport’s existing SSE subscription to
session.outkeeps receiving chunks across the swap — no client-side reconnect
chatId is the durable identity; only the underlying currentRunId rotates. The audit log records the new run with reason: "upgrade".
When called from inside run() or chat.defer(), the current turn completes normally first and the run exits afterward. The next message triggers the continuation on the same session.
Contract versioning
Define an explicit version for the contract between your frontend and agent. The frontend sends aprotocolVersion via clientData, and the agent declares which versions it supports. When a breaking change ships (new tools, changed data parts, updated response format), bump the version.
This gives you full control — the frontend can be backwards-compatible across multiple agent versions, and the agent only upgrades when it sees a version it doesn’t support.
app/components/Chat.tsx
clientData in every payload — both the initial trigger and subsequent records on the session’s .in channel — so the agent always has the current value.
This pattern is useful when:
- Your frontend is backwards-compatible across several agent versions, but occasionally ships breaking changes
- You want explicit control over when upgrades happen rather than upgrading on every deploy
- Multiple frontend versions may be active at the same time (e.g., users with cached tabs)
Auto-detect from build ID (Next.js / Vercel)
For automatic upgrade on every deploy, pass your platform’s build ID viaclientData instead of a manual version. The agent stores the ID from the first message and upgrades when it changes:
app/components/Chat.tsx
trigger/chat.ts
Other agent types
chat.agent()andchat.createSession()— usechat.requestUpgrade()as shown abovechat.customAgent()— you control the turn loop, so justreturnfromrun()when you want to exit
See also
- Lifecycle hooks — where
onTurnStartandonChatResumefit in the turn cycle - Database persistence — how continuations interact with session state
- Client Protocol — how clients handle continuations at the wire level

