Open History to see the last commit
1---
2id: uiMessagesToWire
3title: uiMessagesToWire
4---
5
6```ts
7function uiMessagesToWire(messages, options?): WireMessage[];
8```
9
10Defined in: [packages/ai/src/utilities/ag-ui-wire.ts:85](https://github.com/TanStack/ai/blob/main/packages/ai/src/utilities/ag-ui-wire.ts#L85)
11
12Serialize TanStack `UIMessage`s and `ModelMessage`s into the AG-UI
13`RunAgentInput.messages` wire shape. Anchors are spec-only (`id`, `role`,
14`name`, `content`, `toolCalls`, `metadata`). Tool results and thinking parts
15on assistant messages are additionally emitted as fan-out
16`{role:'tool',...}` and `{role:'reasoning',...}` entries for strict AG-UI
17server consumers. Set `includeSnapshotStructuredOutput` to retain complete
18structured-output metadata for UI snapshots.
19
20## Parameters
21
22### messages
23
24(
25 \| [`UIMessage`](../interfaces/UIMessage.md)\<`unknown`\>
26 \| [`ModelMessage`](../interfaces/ModelMessage.md)\<
27 \| `string`
28 \| [`ContentPart`](../type-aliases/ContentPart.md)\<`unknown`, `unknown`, `unknown`, `unknown`, `unknown`\>[]
29 \| `null`\>)[]
30
31### options?
32
33#### includeSnapshotStructuredOutput
34
35`boolean`
36
37## Returns
38
39[`WireMessage`](../type-aliases/WireMessage.md)[]