Flow and branches¶
Declare the edges between nodes and route by the state. See Graphs and flow.
| Name | What it is |
|---|---|
| Start, end and edges | |
START | The entry of a flow: START >> node names the first node of a graph. |
END | The end of a flow: node >> END, a branch target, or a goto target. |
FlowStartEdge | Edge from START to the first node. |
FlowEdge | Static edge between two nodes, written as a >> b. |
FlowBranchEdge | Conditional edge, written as a >> branch(...). |
StartSentinel | Marker for the entry of a graph flow, used as START >> node. |
EndSentinel | Marker for the end of a graph flow. |
| Branches | |
branch | Route to one of several targets by a key computed from the state. |
when | Route to target when a predicate holds, else to otherwise. |
FlowBranch | Conditional routing table produced by branch or when. |
Start, end and edges¶
START¶
START = StartSentinel()
The entry of a flow: START >> node names the first node of a graph.
END¶
END = EndSentinel()
The end of a flow: node >> END, a branch target, or a goto target.
FlowEdge¶
FlowEdge(source, target)
Static edge between two nodes, written as a >> b.
source | Node | |
target | Node | EndSentinel | |
FlowBranchEdge¶
FlowBranchEdge(source, branch)
Conditional edge, written as a >> branch(...).
source | Node | |
branch | FlowBranch | |
StartSentinel¶
Marker for the entry of a graph flow, used as START >> node.
EndSentinel¶
Marker for the end of a graph flow.
Branches¶
branch¶
branch(router, mapping, *, ref=None) -> FlowBranch
Route to one of several targets by a key computed from the state.
router | Callable[[Any], Any] |
Receives the state and returns a key of |
mapping | Mapping[Any, Node | EndSentinel] |
Router keys to target nodes or |
ref | str | None |
Import path of the router, for |
TypeError |
If |
GraphConfigError |
If |
when¶
when(predicate, target, *, otherwise) -> FlowBranch
Route to target when a predicate holds, else to otherwise.
predicate | Callable[[Any], bool] |
Receives the state and returns a |
target | Node | EndSentinel |
Target when the predicate is true. |
otherwise | Node | EndSentinel |
Target when the predicate is false. |
TypeError |
If |
FlowBranch¶
FlowBranch(router, mapping, router_ref=None, requires_bool=False)
Conditional routing table produced by branch or when.
router | Callable[[Any], Any] |
Called with the state; its result picks the target in |
mapping | Mapping[Any, Node | EndSentinel] |
Router result to the next node or |
router_ref | str | None |
|
requires_bool | bool |
The router must return a |