Skip to content

Commit 488683b

Browse files
committed
docs(ai-agents): address review feedback on the chat agent guide
Describe the chat agent lifecycle as a durable session rather than a single run, add an authorization note to the token-minting example, switch the guide code fences to the typescript language tag, and enable telemetry on the news verifier's claim-extraction call so it matches the guide's description.
1 parent 92f1135 commit 488683b

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

docs/guides/ai-agents/chat-agent.mdx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ description: "Create a durable, multi-turn chat agent with chat.agent(), then ad
66

77
## Overview
88

9-
Build a **durable, multi-turn chat agent**. One Trigger.dev run holds the whole conversation, streams tokens to your UI, and stays alive across many back-and-forth messages. The other guides in this section are one-shot workflows (trigger a task, run a fixed sequence of LLM calls, return a result); a chat agent instead owns the session for its whole lifetime.
9+
Build a **durable, multi-turn chat agent**. A durable session owns the conversation, streams tokens to your UI, and stays alive across many back-and-forth messages. The other guides in this section are one-shot workflows (trigger a task, run a fixed sequence of LLM calls, return a result); a chat agent instead owns the session for its whole lifetime.
1010

1111
[`chat.agent()`](/ai-chat/overview) handles the queuing, retries, resumability and streaming for you. You write the model call, Trigger.dev owns the session. For the full feature set (sessions, fast starts, compaction, sub-agents, the frontend transport), see the [AI chat docs](/ai-chat/overview).
1212

1313
## A minimal agent
1414

1515
Define an agent with `chat.agent()`. The `run` function receives the conversation `messages` (already converted from the frontend's `UIMessage[]`) and an abort `signal`. Return a `StreamTextResult` and it's piped to the frontend automatically.
1616

17-
```ts trigger/chat.ts
17+
```typescript trigger/chat.ts
1818
import { chat } from "@trigger.dev/sdk/ai";
1919
import { anthropic } from "@ai-sdk/anthropic";
2020
import { streamText, stepCountIs } from "ai";
@@ -45,7 +45,7 @@ export const myChat = chat.agent({
4545

4646
A chat agent uses tools exactly like any other AI SDK agent. Declare them on the config so their results survive across turns, then pass the `tools` you receive in `run` straight to `streamText`:
4747

48-
```ts trigger/chat.ts
48+
```typescript trigger/chat.ts
4949
import { chat } from "@trigger.dev/sdk/ai";
5050
import { anthropic } from "@ai-sdk/anthropic";
5151
import { streamText, stepCountIs, tool } from "ai";
@@ -80,7 +80,7 @@ Swap `getCurrentTime` for whatever your agent needs to do: query a database, cal
8080

8181
The browser talks to Trigger.dev directly through the [chat transport](/ai-chat/frontend), so there's no API route to maintain. Expose two server actions (one to start the session, one to mint a session-scoped token) and pass them to `useTriggerChatTransport`, then hand the transport to the AI SDK's `useChat`:
8282

83-
```ts app/actions.ts
83+
```typescript app/actions.ts
8484
"use server";
8585

8686
import { auth } from "@trigger.dev/sdk";
@@ -89,6 +89,9 @@ import { chat } from "@trigger.dev/sdk/ai";
8989
export const startChatSession = chat.createStartSessionAction("my-chat");
9090

9191
export async function mintChatAccessToken(chatId: string) {
92+
// Authorize the caller for this chatId before minting: confirm the logged-in
93+
// user owns this session (e.g. look it up in your database). Otherwise anyone
94+
// who learns a session ID could mint read/write access to it.
9295
return auth.createPublicToken({
9396
scopes: { read: { sessions: chatId }, write: { sessions: chatId } },
9497
expirationTime: "1h",

docs/guides/ai-agents/overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ description: "Real world AI agent example tasks using Trigger.dev"
7878

7979
## Chat agents
8080

81-
Build a durable, multi-turn chat agent with [`chat.agent()`](/ai-chat/overview). One run per conversation, with streaming, sessions and resumability handled for you.
81+
Build a durable, multi-turn chat agent with [`chat.agent()`](/ai-chat/overview). A durable session per conversation, with streaming and resumability handled for you.
8282

8383
<CardGroup cols={2}>
8484
<Card

docs/guides/ai-agents/verify-news-article.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ export const extractClaims = task({
6868
const response = await generateText({
6969
model: anthropic("claude-sonnet-4-5"),
7070
messages,
71+
experimental_telemetry: {
72+
isEnabled: true,
73+
functionId: "extract-claims",
74+
},
7175
});
7276

7377
const claims = response.text

0 commit comments

Comments
 (0)