Queue Docs
Get Started
Integrations
SDK
Streaming
Handle streamed token and event responses in your app.
Streaming
Stream token-by-token responses from your agent to display real-time output in your UI without waiting for the full result.
Streaming in TypeScript
Call client.agents.stream() to get an async iterable. Iterate over events to receive token deltas, tool call events, and a final result.
Streaming in Python
Use client.agents.stream() as an async context manager. Yield events with async for and handle different event types like token, tool_call, and done.
Event Types
The stream emits: token (text delta), tool_call (when a tool is invoked), tool_result (after a tool returns), step (a complete reasoning step), and done (final result).
Why streaming?
Agent runs can take anywhere from a few seconds to several minutes. Streaming lets you display real-time progress to users — each token, tool call, and step shows up as it happens rather than waiting for the entire run to finish.
Event types
token
A single text token emitted by the model. Accumulate these to build the full response text in real time.
tool_call
Emitted when the agent decides to call a tool. Contains the tool name and input. Useful for showing “Agent is reading src/auth.ts…” in your UI.
tool_result
The result returned by the tool, before it is fed back to the model. Contains the tool name, input, and output.
step
Emitted at the end of each complete reasoning step. Contains the step number, a summary, and token usage for that step.
done
The final event. Contains the full RunResult: output text, step count, total token usage, and a link to the trace.
error
Emitted if the run fails. Contains the error type and message. Always handle this event to avoid silent failures.
TypeScript streaming example
const stream = await client.agents.stream({ agent: ‘my-agent’, goal: input }); let output = ‘’; for await (const event of stream) { switch (event.type) { case ‘token’: output += event.data; updateUI(output); break; case ‘tool_call’: showStatus(`Using ${event.tool}...`); break; case ‘done’: finalize(event.result); break; case ‘error’: handleError(event.error); break; } }
Server-Sent Events in the browser
For browser UIs, proxy the stream through your API server and send it to the client as Server-Sent Events. The Queue SDK returns a standard async iterable — wrap it with your framework’s SSE response helper. Never expose your Queue API key in browser code.
On this page