Streaming
Real-time token streaming for agents and chat. Theazo uses Server-Sent Events (SSE) under the hood and exposes an AsyncIterable interface in the SDK — no callbacks, no event emitters, just for await...of.
Agent streaming
Use agent.stream(task) to receive events as the agent works. Each event has a type field that tells you what happened: text, tool_call, tool_result, progress, or done.
const stream = agent.stream('Write a detailed report on market trends')
for await (const event of stream) {
switch (event.type) {
case 'text':
process.stdout.write(event.text) // incremental text chunk
break
case 'tool_call':
console.log('calling:', event.name, event.input)
break
case 'tool_result':
console.log('result:', event.name, event.output)
break
case 'progress':
console.log(event.message) // 'Searching the web...'
break
case 'done':
console.log('output:', event.result.output)
console.log('cost:', event.result.cost) // { amount: 61, currency: 'usd' }
break
}
}Chat streaming
Chat conversations support the same streaming pattern. Use session.chat.stream() to stream a reply token by token. Each chunk carries a type field so you can distinguish between text output, tool calls, and the final completion signal.
const stream = await session.chat.stream('conv_abc', {
content: 'What were the key findings from the last report?',
})
for await (const chunk of stream) {
switch (chunk.type) {
case 'text':
process.stdout.write(chunk.text)
break
case 'tool_call':
console.log('tool:', chunk.name, chunk.input)
break
case 'tool_result':
console.log('result:', chunk.name, chunk.output)
break
case 'done':
console.log('messageId:', chunk.messageId)
console.log('cost:', chunk.cost) // { amount: 12, currency: 'usd' }
console.log('tokens:', chunk.tokenCount) // { input: 340, output: 128 }
break
}
}SSE Protocol
Under the hood, the SDK connects to the GET /v1/agents/:id/stream endpoint, which returns a standard text/event-stream response. If you are building a client in another language, you can consume the raw SSE format directly.
event: text
data: {"text": "The market for"}
event: text
data: {"text": " cloud infrastructure"}
event: tool_call
data: {"name": "web_search", "input": {"query": "cloud infra market size 2025"}}
event: tool_result
data: {"name": "web_search", "output": "The global cloud infrastructure market..."}
event: progress
data: {"message": "Compiling findings into report..."}
event: done
data: {"output": "## Market Analysis\n...", "cost": {"amount": 61, "currency": "usd"}, "duration": 14320}Each SSE frame has an event field (the event type) and a data field (JSON payload). The connection closes after the done event is sent.
Stream events reference
All events emitted during a stream, for both agent and chat streaming.
textIncremental text output. Contains a text string with the new token(s). Concatenate all text chunks to build the full output.tool_callThe agent is invoking a tool. Contains name (tool name) and input (the arguments object passed to the tool).tool_resultA tool has returned. Contains name (tool name) and output (the result from the tool execution).progressA human-readable status update from the agent. Contains a message string describing what the agent is currently doing.doneThe stream is complete. For agents: contains the full RunResult (output, artifacts, cost, duration, toolCalls). For chat: contains messageId, cost, and tokenCount. The connection closes after this event.errorAn error occurred during execution. Contains code, message, and optional details. The connection closes after this event.AsyncIterable — no callbacks. Use for await...of syntax to consume events. The iterable completes automatically when the done event is received.