Skip to content

Commit c9336c5

Browse files
committed
docs(chat): describe the action-turn branch, and fix two Head Start tool statements
The actions lifecycle flow only covered the edit-only path; it now says what happens when onAction returns chat.turn(). The Head Start step said the bound streamText already carried the caller's tools, and the migration example kept a spread comment for a call with no spread.
1 parent bf6df3d commit c9336c5

3 files changed

Lines changed: 3 additions & 2 deletions

File tree

docs/ai-chat/actions.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export const myChat = chat.agent({
5252

5353
**Lifecycle flow:** Wake → parse action against `actionSchema``hydrateMessages` (if set) → **`onAction`** → apply `chat.history` mutations → emit `trigger:turn-complete` → wait for next message.
5454

55+
When `onAction` returns `chat.turn()`, the flow continues instead of emitting `trigger:turn-complete`: the edit is snapshotted, then a turn runs on the edited history with `trigger: "action-turn"`, so `onTurnStart`, `run()`, `onBeforeTurnComplete` and `onTurnComplete` all fire and the answer is persisted like any turn's. See [Answering after an action](#answering-after-an-action).
56+
5557
## Answering after an action
5658

5759
An action is a state edit. To answer after the edit, return `chat.turn()`: the edit is applied and snapshotted, then a turn runs on the edited history exactly as a message turn does. `onTurnStart`, `run()`, `onBeforeTurnComplete` and `onTurnComplete` fire, the turn counter advances, and the answer gets everything a turn has: the agent's system prompt and tools, steering, compaction, injected instructions and persistence.

docs/ai-chat/fast-starts.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ This is an **import-chain** problem, not a runtime one. A "we'll strip the execu
251251
```
252252
</Step>
253253
<Step title="Build the head-start handler">
254-
Call `chat.headStart({ agentId, run })`. It returns a standard Web Fetch handler: `(req: Request) => Promise<Response>`. The `run` callback receives a `streamText` that already carries the SDK-owned wiring: the converted messages, your schema-only tools, `stopWhen: stepCountIs(1)` and the abort signal. Add your own `model` and `system` on top.
254+
Call `chat.headStart({ agentId, run })`. It returns a standard Web Fetch handler: `(req: Request) => Promise<Response>`. The `run` callback receives a `streamText` that already carries the SDK-owned wiring: the converted messages, `stopWhen: stepCountIs(1)` and the abort signal. Pass your schema-only tools to it explicitly, and add your own `model` and `system` on top.
255255

256256
```ts lib/chat-handler.ts
257257
import { chat } from "@trigger.dev/sdk/chat-server";

docs/ai-chat/migrating-from-a-route-handler.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ export const myChat = chat.agent({
147147
tools,
148148
run: async ({ messages, tools, signal, streamText }) =>
149149
streamText({
150-
// Spread first, so every option below still wins.
151150
tools,
152151
model: anthropic("claude-sonnet-4-5"),
153152
system: "You are a helpful assistant.",

0 commit comments

Comments
 (0)