Skip to content

teff.stream

teff.stream

Streaming events for graph execution.

Constitution Principle IX: observability is mandatory. graph.stream() emits :class:StreamEvent objects as a run progresses, so callers can render tokens, progress, and routing decisions before the run finishes — instead of waiting for a fully materialised result from graph.run().

Classes:

Name Description
StreamEvent

A single event emitted while a graph streams.

StreamEvent dataclass

A single event emitted while a graph streams.

Attributes:

Name Type Description
type str

Event type — run_start, node_start, node_end, node_error, edge, token, llm, tool_call, structured, interrupt, interrupt_resume, checkpoint, or run_end.

node_id str | None

Graph node id the event belongs to, if any.

node_type str | None

Node type string, if any.

data dict[str, Any]

Type-specific payload (token text, error, condition, etc.).

Source code in teff/stream.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@dataclass
class StreamEvent:
    """A single event emitted while a graph streams.

    Attributes:
        type: Event type — ``run_start``, ``node_start``, ``node_end``,
            ``node_error``, ``edge``, ``token``, ``llm``, ``tool_call``,
            ``structured``, ``interrupt``, ``interrupt_resume``, ``checkpoint``,
            or ``run_end``.
        node_id: Graph node id the event belongs to, if any.
        node_type: Node type string, if any.
        data: Type-specific payload (token text, error, condition, etc.).
    """

    type: str
    node_id: str | None = None
    node_type: str | None = None
    data: dict[str, Any] = field(default_factory=dict)