Overview
By default the Agent SDK yields complete AssistantMessage objects after each
response. To receive incremental updates as text and tool calls are generated,
enable partial message streaming. This powers chat UIs and progress indicators.
Enable streaming
Set includePartialMessages (TS) / include_partial_messages (Python) to true.
The SDK then also yields StreamEvent messages (TypeScript:
SDKPartialAssistantMessage with type: "stream_event") carrying raw API events.
for await (const message of query({
prompt: "List the files in my project",
options: { includePartialMessages: true, allowedTools: ["Bash", "Read"] },
})) {
if (message.type === "stream_event") {
const event = message.event;
if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
process.stdout.write(event.delta.text);
}
}
}
Read the deltas
- Text:
content_block_delta events where delta.type is text_delta carry text
chunks.
- Tool calls:
content_block_start (tool begins), content_block_delta with
input_json_delta (accumulate partial_json), and content_block_stop (call
complete). Parse the accumulated JSON once complete.
Message flow
With partial messages on, you receive message_start, content_block_start,
content_block_delta chunks, content_block_stop, message_delta,
message_stop, then the complete AssistantMessage, and finally a
ResultMessage. Without it, you receive the complete messages but no
StreamEvents.
Build a streaming UI
Track an inTool flag from content_block_start/content_block_stop to show a
status like [Using Read...] while a tool runs, and stream text only when not in
a tool. Print a completion marker on ResultMessage.
Known limitation
Structured output does not stream as deltas; the JSON appears only in the final
ResultMessage.structured_output.
Source