Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/ag-ui-events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@tanstack/ai': minor
'@tanstack/ai-openai': minor
'@tanstack/ai-anthropic': minor
'@tanstack/ai-gemini': minor
'@tanstack/ai-ollama': minor
---

feat: Add AG-UI protocol events to streaming system

All text adapters now emit AG-UI protocol events only:

- `RUN_STARTED` / `RUN_FINISHED` - Run lifecycle events
- `TEXT_MESSAGE_START` / `TEXT_MESSAGE_CONTENT` / `TEXT_MESSAGE_END` - Text message streaming
- `TOOL_CALL_START` / `TOOL_CALL_ARGS` / `TOOL_CALL_END` - Tool call streaming

Comment on lines +14 to +19
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Document all AG-UI event types introduced in this PR.

The changeset omits several event types mentioned in the broader PR changes. Based on the AI summary, the following event types are also part of the AG-UI protocol but are not documented here:

  • RUN_ERROR — error lifecycle event
  • STEP_STARTED / STEP_FINISHED — step lifecycle events
  • STATE_SNAPSHOT / STATE_DELTA — state events
  • CUSTOM — custom events

Include all introduced event types in the changeset description to provide a complete changelog for users.

🤖 Prompt for AI Agents
In @.changeset/ag-ui-events.md around lines 14 - 19, Update the changeset text
to document all AG-UI protocol events introduced in the PR by adding the missing
event types and short descriptions: include RUN_ERROR (error lifecycle event),
STEP_STARTED and STEP_FINISHED (step lifecycle events), STATE_SNAPSHOT and
STATE_DELTA (state events), and CUSTOM (custom events), alongside the already
listed RUN_STARTED/RUN_FINISHED, TEXT_MESSAGE_*, and TOOL_CALL_* entries; ensure
each event name (e.g., RUN_ERROR, STEP_STARTED, STATE_SNAPSHOT, CUSTOM) appears
in the list with a one-line description so the changelog fully reflects the
protocol surface.

Only AG-UI event types are supported; previous legacy chunk formats (`content`, `tool_call`, `done`, etc.) are no longer accepted.
23 changes: 13 additions & 10 deletions docs/guides/streaming.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,33 @@ messages.forEach((message) => {
});
```

## Stream Chunks
## Stream Events (AG-UI Protocol)

Stream chunks contain different types of data:
TanStack AI implements the [AG-UI Protocol](https://docs.ag-ui.com/introduction) for streaming. Stream events contain different types of data:

- **Content chunks** - Text content being generated
- **Thinking chunks** - Model's internal reasoning process (when supported)
- **Tool call chunks** - When the model calls a tool
- **Tool result chunks** - Results from tool execution
- **Done chunks** - Stream completion
### AG-UI Events

- **RUN_STARTED** - Emitted when a run begins
- **TEXT_MESSAGE_START/CONTENT/END** - Text content streaming lifecycle
- **TOOL_CALL_START/ARGS/END** - Tool invocation lifecycle
- **STEP_STARTED/STEP_FINISHED** - Thinking/reasoning steps
- **RUN_FINISHED** - Run completion with finish reason and usage
- **RUN_ERROR** - Error occurred during the run

### Thinking Chunks

Thinking chunks represent the model's reasoning process. They stream separately from the final response text:
Thinking/reasoning is represented by AG-UI events `STEP_STARTED` and `STEP_FINISHED`. They stream separately from the final response text:

```typescript
for await (const chunk of stream) {
if (chunk.type === "thinking") {
if (chunk.type === "STEP_FINISHED") {
console.log("Thinking:", chunk.content); // Accumulated thinking content
console.log("Delta:", chunk.delta); // Incremental thinking token
}
}
```

Thinking chunks are automatically converted to `ThinkingPart` in `UIMessage` objects. They are UI-only and excluded from messages sent back to the model.
Thinking content is automatically converted to `ThinkingPart` in `UIMessage` objects. It is UI-only and excluded from messages sent back to the model.

## Connection Adapters

Expand Down
Loading
Loading