Agent chat
Stream SSE agent chat in the AI SDK UIMessage format.
The streaming module speaks the same wire protocol as the bundled UI: AI SDK UIMessage chunks, SSE-framed, resumable. A task is one conversation thread; client-generated UUIDs are fine (the first message creates the task).
These examples assume an authenticated lunnoa client from the overview.
Stream a turn
agent-chat.ts
Chunk types include start, text-start, text-delta, text-end, tool-input-available, tool-output-available, reasoning-*, finish, and error.
Framework notes
- React: use
@ai-sdk/react'suseChatwith a transport pointed at${baseUrl}/api/agents/${agentId}/tasks/${taskId}/stream-messageand anAuthorizationheader. Use@lunnoa/clientfor everything non-chat. - Non-React: iterate
AgentChatStream, or passstream.toUIMessageStream()to the AI SDK'sreadUIMessageStreamfor assembledUIMessagesnapshots. - History:
tasks.get(taskId, { expansion: ['messages'] })returns the persisted conversation in UIMessage format. - Non-streaming:
tasks.message(agentId, taskId, text)waits for the full turn.
Next
- Errors: handle 401 / 403 / 429 during streaming
- Codegen: call agents by generated name
- TypeScript client SDK: overview and auth patterns