Skip to content

teff.graph.edge

teff.graph.edge

Graph edge model and hook protocol.

Classes:

Name Description
Edge

A directed edge between two nodes with an optional condition.

Attributes:

Name Type Description
Hook

Signature for observability hooks: (node_id, node, state).

Hook module-attribute

Hook = Callable[..., Any]

Signature for observability hooks: (node_id, node, state).

Hooks may be synchronous or asynchronous — async hooks are awaited by the executor. on_node_end additionally receives the result dict and on_node_error additionally receives the exception.

Edge dataclass

A directed edge between two nodes with an optional condition.

Attributes:

Name Type Description
source_id str

ID of the source node.

target_id str

ID of the target node.

condition str | Callable[[dict], bool] | None

Expression key=value, key!=value, comma-separated disjunction key=a,b, or numeric comparison key>=N / key<=N / key>N / key<N. None means unconditional. A callable (state) -> bool is accepted for programmatic graphs (arbitrary predicates — list membership, length checks, …); it is evaluated against the state and cannot be serialised to YAML. "__error__" matches when the source node raises an exception.

Source code in teff/graph/edge.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
@dataclass
class Edge:
    """A directed edge between two nodes with an optional condition.

    Attributes:
        source_id: ID of the source node.
        target_id: ID of the target node.
        condition: Expression ``key=value``, ``key!=value``,
            comma-separated disjunction ``key=a,b``, or numeric comparison
            ``key>=N`` / ``key<=N`` / ``key>N`` / ``key<N``.
            ``None`` means unconditional.
            A callable ``(state) -> bool`` is accepted for programmatic
            graphs (arbitrary predicates — list membership, length checks,
            …); it is evaluated against the state and cannot be serialised
            to YAML.
            ``"__error__"`` matches when the source node raises an exception.
    """

    source_id: str
    target_id: str
    condition: str | Callable[[dict], bool] | None = None