← 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.

Deep dive: For conditional flow theory and the Command pattern, see Agentic Workflow — Chapter 4: Control Flow.

How It Works

  1. The Router reads the state variables you select (Input State).
  2. Its system prompt tells it what criteria to use for routing.
  3. It produces a structured output selecting one of the defined Router Values.
  4. Execution follows the matching ConditionalEdge to the target node.

Inspector Fields

FieldPurpose
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

Rule: A Router must have at least 2 outgoing edges. A Router with only one output is functionally identical to a direct edge — there’s no decision to make. The topology validator will block export with:
"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.

Example: Analysis Router
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.

Good Router System Prompt
"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

ASL — Router Node with Edges
// 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

Key Takeaways:
← Chapter 3: The LLM Node Chapter 5: The Worker Node →