> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bagofwords.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Route questions to the right agent

> Help BOW pick the right agent when a question could fit more than one, with clear agent descriptions and one global routing instruction.

When the agent selector is on **Auto**, BOW decides which of your agents should answer each question. Most of the time it gets it right from the tables alone. When two agents both have something about "countries" or "revenue", you can tell it which one to prefer, with a clear agent description and one global routing instruction.

<img src="https://mintcdn.com/bagofwords/LzmRbxSzuLtPXzoA/images/guides/agent-routing/routed-top-countries.png?fit=max&auto=format&n=LzmRbxSzuLtPXzoA&q=85&s=eee1991f4af816b3ef33fd8749d53eef" alt="A question routed to the Music Store agent by a global routing instruction" width="2880" height="1800" data-path="images/guides/agent-routing/routed-top-countries.png" />

This guide uses two agents: **Music Store** (customers, invoices, tracks, artists, genres, employees) and **Financial Market Agent** (stock prices, gold vs bitcoin, GDP and country statistics, bank failures). Both have a notion of "countries", so a short question like "Top 10 countries" could go to either one.

## Before you start

* **You are an admin.** A global instruction applies to every agent, so it needs the org-level permission to manage instructions. To change an agent's description, you need manage access to that agent.
* **You have two or more agents** that people can ask about in the same place.

## Step 1: See what Auto does

On the home page, click the agent selector in the prompt box. **Auto** (**Any agent you can access**) is the default. Below it you see the agents you can use.

<img src="https://mintcdn.com/bagofwords/LzmRbxSzuLtPXzoA/images/guides/agent-routing/auto-selector.png?fit=max&auto=format&n=LzmRbxSzuLtPXzoA&q=85&s=08b5fbb654a6412e6ea5b8c70d2ad4b1" alt="The agent selector set to Auto" width="2880" height="1800" data-path="images/guides/agent-routing/auto-selector.png" />

With **Auto**, BOW can use any agent in this list, and only these. People see only the agents they have access to. In this example a member sees **Music Store** and **Financial Market Agent**, but not the private **Contract Desk** agent.

## Step 2: Give each agent a clear description

The description is the one line that says what an agent covers. Make it a list of the things people actually ask about.

1. Open **Agents** and select the agent.
2. Click the line under the agent's name (or **Add a description…** if it is empty).
3. Type the description and press **Enter**.

<img src="https://mintcdn.com/bagofwords/LzmRbxSzuLtPXzoA/images/guides/agent-routing/agent-description.png?fit=max&auto=format&n=LzmRbxSzuLtPXzoA&q=85&s=975f4e68a0196e750edc6ef292590f7c" alt="An agent with a description listing its topics" width="2880" height="1800" data-path="images/guides/agent-routing/agent-description.png" />

For example:

| Agent | Description |
| - | - |
| Music Store | *Music store sales: customers, invoices, revenue by country, tracks, albums, artists, genres and employees.* |
| Financial Market Agent | *Market and economy data: stock prices (candlesticks, quotes), gold vs bitcoin, GDP and country statistics, bank failures.* |

<Tip>
  Use the words people type, not the table names. "Revenue by country" helps more than "Invoice.BillingCountry".
</Tip>

## Step 3: Create a global routing instruction

A global instruction is not tied to any agent, so it loads before BOW has picked one. That makes it the right place for routing rules.

1. On the **Agents** page, click **New** and choose **Instruction**.

   <img src="https://mintcdn.com/bagofwords/LzmRbxSzuLtPXzoA/images/guides/agent-routing/new-instruction-menu.png?fit=max&auto=format&n=LzmRbxSzuLtPXzoA&q=85&s=4662190b0dad2f3523e0282d57b84acb" alt="The New menu on the Agents page" width="2880" height="1800" data-path="images/guides/agent-routing/new-instruction-menu.png" />

2. Name it **Agent routing** and write one rule per line:

   * *Questions about customers, invoices, sales, revenue, tracks, artists, genres or employees → use the Music Store agent.*
   * *Questions about stock prices, gold, bitcoin, GDP, country economics or bank failures → use the Financial Market Agent.*
   * *If a question about 'countries' doesn't say which, default to Music Store sales by country.*

3. Check the settings under **Details**:
   * **Active**, so it is live.
   * **Always**, so it loads on every question. A **Smart** instruction loads only when the question matches it, which is too late for routing.
   * **All agents**. Leave the agents empty. This is what makes the instruction global.

4. Click **Create**. It appears under **Global instructions** on the left.

<img src="https://mintcdn.com/bagofwords/LzmRbxSzuLtPXzoA/images/guides/agent-routing/routing-instruction-editor.png?fit=max&auto=format&n=LzmRbxSzuLtPXzoA&q=85&s=c613dbcf9dd10c6c4d172adfdd140506" alt="The new global routing instruction, set to Active, Always and All agents" width="2880" height="1800" data-path="images/guides/agent-routing/routing-instruction-editor.png" />

<Note>
  An instruction that is linked to specific agents loads only when one of those agents is in use. That works for rules that apply after BOW has picked an agent, but not for choosing the agent.
</Note>

## Step 4: Test it with Auto

Start a **New report**, leave the selector on **Auto**, and ask a question that could fit either agent:

> *Top 10 countries*

The first line of the answer says which rule BOW followed, and the step below it shows the agent icon and the tables it used. Here it reads "Per the agent routing instruction…" and uses the Music Store **Invoice** and **InvoiceLine** tables.

To check that the instruction loaded, click **N instructions** under the answer. **Agent routing** is in the **Instructions loaded** list.

<img src="https://mintcdn.com/bagofwords/LzmRbxSzuLtPXzoA/images/guides/agent-routing/instructions-loaded.png?fit=max&auto=format&n=LzmRbxSzuLtPXzoA&q=85&s=5e77aa43e4684b564f4b80b58574f422" alt="The Instructions loaded list, with Agent routing at the bottom" width="2880" height="1800" data-path="images/guides/agent-routing/instructions-loaded.png" />

Now ask a question that names a finance topic:

> *Top 10 countries by GDP per capita*

BOW goes to the Financial Market Agent and its **country\_stats\_scatter** table. The "countries" default applies only when the question doesn't say what kind of country data it wants.

<img src="https://mintcdn.com/bagofwords/LzmRbxSzuLtPXzoA/images/guides/agent-routing/routed-gdp-per-capita.png?fit=max&auto=format&n=LzmRbxSzuLtPXzoA&q=85&s=0d667ffa9c4db4ea8f9986caf40680ef" alt="A GDP question routed to the Financial Market Agent" width="2880" height="1800" data-path="images/guides/agent-routing/routed-gdp-per-capita.png" />

A question that needs both agents uses both:

> *Compare revenue by country with GDP per capita*

The steps show tables from each agent, and the final query combines them.

<img src="https://mintcdn.com/bagofwords/LzmRbxSzuLtPXzoA/images/guides/agent-routing/routed-both-agents.png?fit=max&auto=format&n=LzmRbxSzuLtPXzoA&q=85&s=7b55871ae1d096c5f4a53f1a511c3c5c" alt="One answer that uses tables from both agents" width="2880" height="1800" data-path="images/guides/agent-routing/routed-both-agents.png" />

<Note>
  The two agents are separate databases, so a cross-agent answer only matches rows that exist in both. In this example the finance data has 9 countries, so the comparison has 4 rows.
</Note>

## Step 5: Pin an agent when you already know

If you know which agent you want, pick it in the selector instead of **Auto**. Click the selector, choose the agent, then click anywhere outside the menu to close it. The selector now shows the agent's name.

<img src="https://mintcdn.com/bagofwords/LzmRbxSzuLtPXzoA/images/guides/agent-routing/pinned-agent-selector.png?fit=max&auto=format&n=LzmRbxSzuLtPXzoA&q=85&s=cb744ecf8e7e3a158302fa7454bc8b10" alt="Financial Market Agent picked in the agent selector" width="2880" height="1800" data-path="images/guides/agent-routing/pinned-agent-selector.png" />

A picked agent is a hard limit. BOW can't go outside it, even when a routing rule points to another agent. Asked "Top 10 countries" with only the Financial Market Agent picked, BOW looked for the Music Store agent, didn't find it, and asked which country ranking to show from the finance data instead.

<img src="https://mintcdn.com/bagofwords/LzmRbxSzuLtPXzoA/images/guides/agent-routing/pinned-agent-clarify.png?fit=max&auto=format&n=LzmRbxSzuLtPXzoA&q=85&s=05db881c05540011336109e02802fff0" alt="With one agent picked, BOW asks a clarifying question instead of switching agents" width="2880" height="1800" data-path="images/guides/agent-routing/pinned-agent-clarify.png" />

## Optional: Share one rule across several agents

Some rules are not about routing but apply to more than one agent, like *For 'top X by Y' questions, use a bar chart.* Instead of copying it into each agent, create one instruction and select every agent it applies to in the agents menu under **Details**.

<img src="https://mintcdn.com/bagofwords/LzmRbxSzuLtPXzoA/images/guides/agent-routing/shared-instruction-agents.png?fit=max&auto=format&n=LzmRbxSzuLtPXzoA&q=85&s=04d406fd4408f27e62f9e7c35743b170" alt="One instruction linked to two agents" width="2880" height="1800" data-path="images/guides/agent-routing/shared-instruction-agents.png" />

This instruction loads whenever any of the selected agents is in use. It applies after BOW has picked an agent, so it doesn't help with routing.

## What to expect

With only a few agents, BOW loads every agent's tables and **Always** instructions on every question, so it often picks the right agent from the tables alone. In our tests the five questions above went to the same agents with or without the routing instruction. What the instruction changed was the reasoning: without it, BOW said "Top 10 countries" could mean several things and guessed. With it, BOW cited the rule and chose Music Store sales every time.

The routing instruction matters most when:

* **Agents overlap.** Both have countries, revenue, customers or dates.
* **Short questions are common.** "Top 10 countries", "revenue last month", "best customers".
* **You have many agents.** BOW then works from each agent's description first, before it looks at tables. Clear descriptions and a routing instruction help it pick the right one.

## More prompts to try

| Goal | Prompt |
| - | - |
| Check an ambiguous default | *Top 10 countries* |
| Check a topic that names one agent | *How did gold do vs bitcoin last year?* |
| Check a question for the other agent | *Which customers spent the most?* |
| Check a question that needs both | *Compare revenue by country with GDP per capita* |

## Tips

* **Write rules as "topic → agent".** List the words people use, then name the agent exactly as it appears in **Agents**.
* **Give every ambiguous word a default.** "Countries", "revenue" and "customers" are common overlaps.
* **Keep routing in one global instruction.** Agent-specific rules belong on the agent.
* **Test in a new report with Auto.** Ask the same short question twice. If BOW picks different agents, add a default for it.
* **Pinning wins.** A routing rule can't send a question to an agent that isn't picked.

## Troubleshooting

**BOW still picks the wrong agent.** Click **N instructions** under the answer and check that **Agent routing** is listed. If it isn't, make sure it is **Active**, set to **Always**, and has no agents selected.

**BOW asks which agent to use, or says an agent isn't available.** An agent is picked in the selector. Switch it back to **Auto**.

## Related

* [Instructions and knowledge](/agents/instructions)
* [Agents overview](/agents/overview)
* [Train an agent](/agents/train-an-agent)
* [Reports](/using-bow/reports)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.