Streaming
session.stream(prompt) yields incremental events as the turn runs, so you can render text as it arrives and react to tool activity in real time. Use it when you want a live UI or a CLI that prints output token-by-token instead of waiting for the full result from send or run.
Each event carries the stable envelope fields version, type, payload, and optional metadata. The common kinds are agent_start, text_delta / reasoning_delta, tool_start / tool_end, agent_end, and error. Verification data is carried by the agent_end payload and convenience fields.
Notes:
- Rust receives
AgentEventvalues from a Tokio channel and awaits the returned lifecycle handle. Node.js iterates theEventStreamwithfor await(or callsstream.next()directly). Python'sEventStreamsupports bothforandasync for. Go drainsstream.Eventsbefore reading the terminal error fromstream.Done. Canceling the Go context also requests cancellation of the active native run. - All four SDKs expose the canonical event type. Node.js and Python add convenience projections; Go keeps
PayloadandMetadataasjson.RawMessageand providesDecodePayload. Unknown future event types remain lossless in every SDK. tool_startfires when the model begins emitting a tool call;tool_execution_startfires when the tool actually runs, andtool_endcarries its output and exit code.- With a confirmation policy enabled, the stream also carries human-in-the-loop signals:
confirmation_required, thenconfirmation_receivedonce an answer arrives. A pending confirmation stays parked until it is answered; no timer settles it.confirmation_timeoutis emitted, withaction_taken, only when the confirmation channel closes before an answer (for example, on cancel or close).
Runnable streaming examples ship under sdk/node/examples/streaming/.
A complete human-in-the-loop confirmation loop ships at
sdk/node/examples/streaming/hitl_confirmation_loop.ts, with the
matching Python version under sdk/python/examples/ and Go stream
coverage in sdk/go/session_test.go.