You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit bd7cc35
Browse filesBrowse the repository at this point in the historyBrowse files
fix(sdk): trace model steps and tool calls in chat.agent by default
`chat.agent` now traces each model step and tool call by default: the
`streamText` passed to `run()` turns AI SDK telemetry on even when no
prompt is stored with `chat.prompt.set()`. An agent with `telemetry: {
recordUserMessage: false }` gets these spans without prompt and response
content, including when it stores a prompt (whose variables are left out
of the span metadata). Pass `experimental_telemetry: { isEnabled: false
}` to turn them off, or `recordInputs` / `recordOutputs: false` to keep
them without content.
Mono-RevId: 8c1936ba08de8d3b6199a5d9e23384440b81f7d5
The `streamText` passed to a `chat.agent`'s `run()` now turns AI SDK telemetry on by default, so each model step and tool call shows up as a span in the run trace even when the agent doesn't store a prompt with `chat.prompt.set()`. An agent with `telemetry: { recordUserMessage: false }` gets these spans without prompt and response content, including when it stores a prompt (whose variables are left out of the span metadata). Pass `experimental_telemetry: { isEnabled: false }` at the call site to turn them off, or `recordInputs: false` / `recordOutputs: false` to keep them without content.
The managed `streamText` carries the stored prompt's `system`, `model` (resolved through the agent's `registry`), sampling config, and `experimental_telemetry`. Options you pass at the call site win, apart from `system`, which throws when the prompt already set one.
275
+
The managed `streamText` carries the stored prompt's `system`, `model` (resolved through the agent's `registry`), sampling config, and `experimental_telemetry`. AI SDK telemetry is on even without a stored prompt, so model steps and tool calls show in the run trace. Options you pass at the call site win, apart from `system`, which throws when the prompt already set one.
276
276
277
277
`chat.toStreamTextOptions()` remains available for the same job, and is the only option in a [custom agent](#custom-agents), which has no `run` argument to take a bound `streamText` from. A `chat.headStart` route does get one, and there it also owns `messages`, `stopWhen` and `abortSignal`, since the handover depends on them. Pass `{ registry }` when a prompt names a provider-prefixed model, and `{ tools }` when you want HITL tool approvals, so the SDK knows which calls pause on `needsApproval`.
description: "Stop a chat agent recording user messages and clientData on its spans, turn off AI SDK prompt and response recording, or redact span content with a span processor before it leaves the worker."
5
5
---
6
6
7
-
A chat agent's run trace records conversation content by default: the user's message and the `clientData` your frontend sends. When AI SDK telemetry is on, it also records the prompts and responses of each model call. This page covers the three controls that change that, and what they don't cover.
7
+
A chat agent's run trace records conversation content by default: the user's message, the `clientData` your frontend sends, and, through AI SDK telemetry, the prompts and responses of each model call. This page covers the three controls that change that, and what they don't cover.
8
8
9
9
## What the run trace records
10
10
@@ -13,7 +13,7 @@ A chat agent's run trace records conversation content by default: the user's mes
13
13
|`chat turn N`| The last user message (`chat.user_message`) and its first 80 characters as the span preview |`telemetry.recordUserMessage`|
14
14
|`chat turn N`| The raw `clientData` (`chat.client_data`) |`telemetry.recordClientData`|
15
15
|`pending message injected`| Messages sent mid-turn (`pending.messages`) |`telemetry.recordUserMessage`|
16
-
| AI SDK model call spans, when AI SDK telemetry is on | Prompt messages, response text, tool calls |`experimental_telemetry` on the model call |
16
+
| AI SDK model call spans (on by default with the `streamText` from `run`) | Prompt messages, response text, tool calls |`telemetry.recordUserMessage` for the default config, or`experimental_telemetry` on the model call |
17
17
| Any span | Everything above, plus your own attributes and span events | A span processor |
The spans still appear in the trace with their timings and token usage. The turn spans have no preview text.
35
+
The spans still appear in the trace with their timings and token usage. The turn spans have no preview text.`recordUserMessage: false` also keeps prompts and responses out of the AI SDK spans that the `streamText` passed to `run()` turns on, with or without a prompt stored by `chat.prompt.set()`, and leaves a stored prompt's variables out of the span metadata, unless the call passes its own `experimental_telemetry`.
36
36
37
37
## Stop the AI SDK recording prompts and responses
38
38
39
-
AI SDK model call spans appear when AI SDK telemetry is on: [`chat.prompt.set()`](/ai-chat/backend#using-prompts) turns it on for you, or you pass `experimental_telemetry`yourself. Those spans include prompts and responses unless you turn that off with `recordInputs` and `recordOutputs`:
39
+
The `streamText` passed to `run()` turns AI SDK telemetry on, so each model call and tool call is a span in the run trace (pass `experimental_telemetry: { isEnabled: false }` to turn the spans off). If you call `streamText` from `ai` yourself, pass `experimental_telemetry`to get them. Those spans include prompts and responses unless you turn that off with `recordInputs` and `recordOutputs`:
0 commit comments