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.

Node.js
Python

Notes:

  • Node iterates the stream manually with stream.next(), checking next.done and next.value. In the current build the Python SDK exposes streaming as a synchronous iterator, so you consume it with a plain for loop (orchestration APIs such as parallel and pipeline remain async).
  • Both SDKs expose the canonical event.type; Python retains event.event_type as a compatibility alias. event.payload is the complete lossless payload, and unknown future types are preserved. Convenience fields follow each language's casing: toolName / exitCode / verificationSummaryText in Node, tool_name / exit_code / verification_summary_text in Python.
  • Streamed events can also include human-in-the-loop confirmation signals (confirmation_required, confirmation_received, confirmation_timeout) when a confirmation policy is enabled.

Runnable streaming examples ship under crates/code/sdk/node/examples/streaming/. A complete human-in-the-loop confirmation loop ships at crates/code/sdk/node/examples/streaming/hitl_confirmation_loop.ts, and the matching Python version ships at crates/code/sdk/python/examples/hitl_confirmation_loop.py.