AI Router icon

AI Router

Route workflow execution based on AI decision

Overview

The AI Router node routes workflow execution dynamically based on an AI model's interpretation of input text. It analyzes the provided text and decides which predefined branch the workflow should follow, enabling intelligent branching without manual condition setup.

This node is useful in scenarios such as:

  • Customer support workflows where incoming messages need to be routed to different departments (e.g., questions, complaints, requests).
  • Chatbots that must decide user intent and route accordingly.
  • Automations requiring dynamic decision-making based on natural language input.

For example, given a user message "I want to know your refund policy," the node can route this to a "Question" branch, while a message like "My order arrived damaged" could be routed to a "Complaint" branch.

Properties

Name Meaning
Input Text The text to analyze for routing decision. Can be entered directly or set via an expression referencing incoming data fields (e.g., {{$json.text}}).
System Prompt A prompt guiding the AI's routing decision. It includes instructions and a list of available branches with their descriptions. The AI must respond with only the exact branch name matching the user's intent or "fallback".
Branches A collection of branches to route to. Each branch has:
- Branch Name: The exact name used for routing and output connection.
- Description: Helps AI understand when to route here.
- Keywords (Optional): Comma-separated keywords to assist AI recognition.
Options Additional settings controlling AI behavior:
- Temperature: Controls randomness; lower values make responses more deterministic.
- Max Tokens: Maximum tokens allowed in AI response.
- Include Confidence Score: Whether to include token usage info in output.
- Fallback on Error: Whether to route to fallback branch if AI call fails.

Output

The node outputs one item per input, routed into one of multiple output connections corresponding to the defined branches plus an additional fallback branch.

Each output item's JSON contains:

  • All original input JSON fields.
  • selectedBranch: The name of the branch chosen by the AI or "fallback" if no match or error occurred.
  • aiDecision: The raw AI response string indicating the selected branch.
  • inputText: The analyzed input text.
  • routingReason: Explanation of why the branch was selected (e.g., matched branch name or fallback reason).
  • Optionally, if enabled, confidenceInfo object with token usage statistics (totalTokens, promptTokens, completionTokens).

If the node encounters an error during AI invocation and fallback is enabled, it routes the item to the fallback branch with an error field describing the issue.

No binary data is produced by this node.

Dependencies

  • Requires connection to an AI language model node configured in the workflow. This AI model must support chat-style invocation with system and user messages.
  • No direct external API keys or credentials are managed by this node itself; it relies on the connected AI model node for authentication and API access.

Troubleshooting

  • Error: "At least one branch must be defined"
    Occurs if no branches are configured. Solution: Add at least one branch with a name and description.

  • Error: "AI Language Model must be connected"
    Happens if the AI model input is not connected. Solution: Connect a compatible AI language model node to the second input.

  • Routing to fallback unexpectedly
    Could be due to input text being empty or AI failing to match any branch. Check that input text is correctly passed and branches are well described.

  • AI routing failed errors
    If AI invocation fails (e.g., network issues, API limits), and fallback is disabled, the node throws an error stopping execution. Enable fallback on error to route such cases to fallback branch instead.

  • Incorrect branch selection
    Improve branch descriptions and optionally add keywords to help the AI better distinguish intents.

Links and References

Discussion