Streaming

techrevati.runtime.streaming

Streaming — structured event stream for async model turns.

arun_turn_stream reemits caller-produced text chunks as StreamEvent values plus a single terminal final event. Consumers iterate with async for and may break early — upstream cancellation is propagated through the session's cancellation flag because the consumer is no longer listening for another stream event.

This module owns the wire format; the actual iteration loop lives in orchestrator.AsyncOrchestrationSession.arun_turn_stream so it has access to the existing usage tracker, governance plane, and hook chain.

StreamEvent dataclass

StreamEvent(type, payload=dict(), emitted_at=_now_iso())

One event in a turn-level structured stream.

Frozen so consumers can fan it out to multiple sinks without worrying about concurrent mutation. payload is a free-form dict whose shape is documented per type below.

type required payload keys
text_delta delta (str)
tool_call tool (str), args (dict)
tool_result tool (str), result (Any)
handoff target_role (str), reason
final status (StreamFinalStatus); optional usage, detail
error error_type (str), message (str)

Use the classmethod constructors below for type-safe construction.