> For the complete documentation index, see [llms.txt](https://whitepaper.aitech.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whitepaper.aitech.io/agentforge/blocks/router.md).

# router

The Router block uses AI to intelligently decide which path your workflow should take next. Unlike Condition blocks that use simple rules, Router blocks can understand context and make smart routing decisions based on content analysis.

### Overview

{% stepper %}
{% step %}

#### Intelligent content routing

Use AI to understand intent and context
{% endstep %}

{% step %}

#### Dynamic path selection

Route workflows based on unstructured content analysis
{% endstep %}

{% step %}

#### Context-aware decisions

Make smart routing choices beyond simple rules
{% endstep %}

{% step %}

#### Multi-path management

Handle complex workflows with multiple potential destinations
{% endstep %}
{% endstepper %}

### Router vs Condition Blocks

<details>

<summary>When to Use Router</summary>

* AI-powered content analysis needed
* Unstructured or varying content types
* Intent-based routing (e.g., "route support tickets to departments")
* Context-aware decision making required

</details>

<details>

<summary>When to Use Condition</summary>

* Simple, rule-based decisions
* Structured data or numeric comparisons
* Fast, deterministic routing needed
* Boolean logic sufficient

</details>

### How It Works

The Router block:

{% stepper %}
{% step %}

#### Analyze content

Uses an LLM to understand input content and context
{% endstep %}

{% step %}

#### Evaluate targets

Compares content against available destination blocks
{% endstep %}

{% step %}

#### Select destination

Identifies the most appropriate path based on intent
{% endstep %}

{% step %}

#### Route execution

Directs workflow to the selected block
{% endstep %}
{% endstepper %}

### Configuration Options

#### Content/Prompt

The content or prompt that the Router will analyze to make routing decisions. This can be:

* A direct user query or input
* Output from a previous block
* A system-generated message

#### Target Blocks

The possible destination blocks that the Router can select from. The Router will automatically detect connected blocks, but you can also:

* Customize the descriptions of target blocks to improve routing accuracy
* Specify routing criteria for each target block
* Exclude certain blocks from being considered as routing targets

#### Model Selection

Choose an AI model to power the routing decision:

**OpenAI**: GPT-4o, o1, o3, o4-mini, gpt-4.1\
**Anthropic**: Claude 3.7 Sonnet\
**Google**: Gemini 2.5 Pro, Gemini 2.0 Flash\
**Other Providers**: Groq, Cerebras, xAI, DeepSeek\
**Local Models**: Any model running on Ollama

**Recommendation**: Use models with strong reasoning capabilities like GPT-4o or Claude 3.7 Sonnet for more accurate routing decisions.

#### API Key

Your API key for the selected LLM provider. This is securely stored and used for authentication.

#### Accessing Results

After a router makes a decision, you can access its outputs:

* **`<router.content>`**: Summary of the routing decision made
* **`<router.selected_path>`**: Details of the chosen destination block
* **`<router.tokens>`**: Token usage statistics from the LLM
* **`<router.model>`**: The model used for decision-making

### Advanced Features

#### Custom Routing Criteria

Define specific criteria for each target block:

```javascript
// Example routing descriptions
Target Block 1: "Technical support issues, API problems, integration questions"
Target Block 2: "Billing inquiries, subscription changes, payment issues"
Target Block 3: "General questions, feedback, feature requests"
```

#### Multi-Model Routing

Use different models for different routing scenarios:

```javascript
// Fast routing for simple cases
Model: GPT-4o-mini
Criteria: Simple, common routing patterns

// Complex routing for nuanced decisions
Model: Claude 3.7 Sonnet
Criteria: Complex content analysis required
```

#### Fallback Handling

Implement robust fallback mechanisms:

```javascript
// Router configuration
Primary Targets: ["Support", "Sales", "Technical"]
Fallback Target: "General" // Default when no specific match
Confidence Threshold: 0.7 // Minimum confidence for routing
```

### Inputs and Outputs

{% tabs %}
{% tab title="Configuration" %}

* **Content/Prompt**: Text to analyze for routing decisions
* **Target Blocks**: Connected blocks as potential destinations
* **Model**: AI model for routing analysis
* **API Key**: Authentication for selected LLM provider
  {% endtab %}

{% tab title="Variables" %}

* **router.content**: Summary of routing decision
* **router.selected\_path**: Details of chosen destination
* **router.tokens**: Token usage statistics
* **router.model**: Model used for decision-making
  {% endtab %}

{% tab title="Results" %}

* **Routing Decision**: Primary path selection result
* **Decision Context**: Analysis summary and reasoning
* **Access**: Available in blocks after the router
  {% endtab %}
  {% endtabs %}

### Example Use Cases

#### Customer Support Triage

{% stepper %}
{% step %}

#### Scenario: Route support tickets to specialized departments

1. User submits support request via form
2. Router analyzes ticket content and context
3. Technical issues → Engineering support agent
4. Billing questions → Finance support agent
   {% endstep %}
   {% endstepper %}

#### Content Classification

{% stepper %}
{% step %}

#### Scenario: Classify and route user-generated content

1. User submits content or feedback
2. Router analyzes content type and sentiment
3. Feature requests → Product team workflow
4. Bug reports → Technical support workflow
   {% endstep %}
   {% endstepper %}

#### Lead Qualification

{% stepper %}
{% step %}

#### Scenario: Route leads based on qualification criteria

1. Lead information captured from form
2. Router analyzes company size, industry, and needs
3. Enterprise leads → Sales team with custom pricing
4. SMB leads → Self-service onboarding flow
   {% endstep %}
   {% endstepper %}

#### Example

Router prompt:

```json
<function1.result>

Support Path: "Technical/support issues, bugs, API problems"
Billing Path: "Invoices, refunds, payment, subscription changes"
General Path: "Feedback, feature requests, anything else"
```

### Best Practices

* **Provide clear target descriptions**: Help the Router understand when to select each destination with specific, detailed descriptions
* **Use specific routing criteria**: Define clear conditions and examples for each path to improve accuracy
* **Implement fallback paths**: Connect a default destination for when no specific path is appropriate
* **Test with diverse inputs**: Ensure the Router handles various input types, edge cases, and unexpected content
* **Monitor routing performance**: Review routing decisions regularly and refine criteria based on actual usage patterns
* **Choose appropriate models**: Use models with strong reasoning capabilities for complex routing decisions


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://whitepaper.aitech.io/agentforge/blocks/router.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
