Skip to content

RouterNode (base)

nae.nodes.decision_node.RouterNode

Routing mixin for nodes that pick the next node instead of appending to the conversation. Owns the Choice list, route(), the node["choice"] > handler wiring (__getitem__), and the __gt__ override that forbids a direct edge off the router.

It is a MIXIN (not a Node subclass): concrete routers combine it with their real base — ConditionNode(RouterNode, Node) and DecisionNode(RouterNode, LLMNode) — and call _setup_choices explicitly from their own __init__. Subclasses decide HOW the label is chosen (DecisionNode via an LLM, ConditionNode via a Python callable) and both write it to a dedicated per-node decision_{name} state field (read by route()), never into messages. Because RouterNode stays in the MRO of both, graph.py's isinstance(node, RouterNode) conditional-edge handling treats them identically.

__getitem__

__getitem__(key: str) -> Choice

Get a Choice object by its name.

Parameters:

Name Type Description Default
key str

Name of the choice to retrieve

required

Returns:

Type Description
Choice

The Choice object

Raises:

Type Description
ValueError

If the choice name is not found

__gt__

__gt__(other) -> None

Prevent direct edge creation from a routing node.

Raises:

Type Description
ValueError

Always, since edges must be created from choices

route

route(state)

Conditional-edge callback: map the chosen label to the next node name.

Registered with LangGraph via add_conditional_edges(name, route, ...). Reads the label this router wrote to state["decision_{name}"], finds the matching Choice, and returns the name of the node wired to it — which LangGraph uses to pick the outgoing edge. Raises ValueError if the label is unknown or its choice was never wired to a node.