← Back to Agentish Framework Guide
Chapter 4 The Router Node
Conditional branching powered by an LLM
The Router Node is an LLM-powered decision maker. It reads state, reasons about which path to take, and sends execution to one of its targets. Unlike a simple if/else, the Router uses an LLM to make the decision — so it can handle nuanced, context-dependent routing.
How It Works
- The Router reads the state variables you select (Input State).
- Its system prompt tells it what criteria to use for routing.
- It produces a structured output selecting one of the defined Router Values.
- Execution follows the matching ConditionalEdge to the target node.
Inspector Fields
| Field | Purpose |
|---|---|
| Node title | Display name. Must be unique. |
| Input State | State variables to include in the Router’s context for decision making. |
| System prompt | Instructions for the routing decision. Should clearly describe when to choose each option. |
| Router Values | A table of routing options. Each row has a node name (matching a connected target node’s title) and a description (explaining when to pick this option). |
The Minimum Two-Output Rule
"Router node 'My Router' (id=3) has 1 outgoing flow edge(s).
Routers must have at least 2."Router Values and Edge Matching
Each Router Value corresponds to one output slot on the node. The node name in the Router Values table must match the title of the target node connected to that output slot.
Router Values:
Node: "Malware Analyst"
Description: "Choose this when the alert appears to involve malware
(suspicious binaries, known malware hashes, obfuscated code)."
Node: "Network Investigator"
Description: "Choose this when the alert involves network anomalies
(unusual traffic, port scanning, suspicious connections)."
Node: "False Positive Handler"
Description: "Choose this when the alert appears to be benign
(normal system behavior, known safe processes)."Writing Good Router Prompts
The Router’s system prompt should give clear criteria for each routing option. Be specific about what conditions lead to each choice. Vague prompts lead to inconsistent routing.
"You are a routing agent. Based on the analysis_result, decide:
- Route to 'Orchestrator' if the analysis is incomplete, too short
(under 200 words), or explicitly says more work is needed.
- Route to 'Finalizer' if the analysis is comprehensive, addresses
all aspects of the problem, and is ready for final formatting.
When in doubt, route to Orchestrator for another iteration."Routers and Loops
Routers are the only way to create loops in Agentish. When a Router has an output edge that points back to an earlier node in the graph, that creates a cycle. The Router’s LLM decides whether to loop again or exit.
See Chapter 7: Loops for how to properly configure looping workflows, including loop mode and exit conditions.
ASL Representation
// The Router node:
{
"id": "3",
"type": "RouterBlock",
"label": "Category Router",
"config": {
"title": "Category Router",
"input_state_keys": ["analysis_result"],
"system_prompt": "Route based on the analysis category...",
"router_values": [
{ "node": "Malware Analyst",
"description": "Alert involves malware indicators." },
{ "node": "Network Investigator",
"description": "Alert involves network anomalies." }
]
}
}
// Conditional edges from the Router:
{ "from": "3", "to": "4", "type": "ConditionalEdge",
"condition": "Malware Analyst" }
{ "from": "3", "to": "5", "type": "ConditionalEdge",
"condition": "Network Investigator" }Chapter Summary
- The Router is an LLM-powered conditional branch — it decides which path to take.
- Must have at least 2 outgoing edges.
- Router Values map to output slots — the node name must match the target’s title.
- Routers are the only way to create loops (back-edges) in Agentish.
- Write specific routing criteria in the system prompt.