Open History to see the last commit
1---
2id: uiMessagesToWire
3title: uiMessagesToWire
4---
5
6# Function: uiMessagesToWire()
7
8```ts
9function uiMessagesToWire(messages): WireMessage[];
10```
11
12Defined in: [packages/typescript/ai/src/utilities/ag-ui-wire.ts:47](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/utilities/ag-ui-wire.ts#L47)
13
14Serialize TanStack `UIMessage`s into the AG-UI `RunAgentInput.messages`
15wire shape. Each anchor (system/user/assistant) carries the canonical
16`parts` array verbatim plus AG-UI mirror fields (`content`, `toolCalls`)
17so AG-UI Zod parsing succeeds. Tool results and thinking parts on
18assistant messages are additionally emitted as fan-out
19`{role:'tool',...}` and `{role:'reasoning',...}` entries for strict
20AG-UI server consumers.
21
22## Parameters
23
24### messages
25
26[`UIMessage`](../interfaces/UIMessage.md)\<`unknown`\>[]
27
28## Returns
29
30[`WireMessage`](../type-aliases/WireMessage.md)[]