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

# Multi-Agent Routing

> Run several agents from one workspace with a single script, and show the right agent on each page.

Have more than one agent? You can run them all from a **single script tag**
instead of pasting a different snippet on every page. Each agent's **Display
Rules** decide which pages it shows on, and one default agent covers
everything else.

A SaaS app, for example, might put a **Sales** agent on `/pricing` and `/plans`,
and a **Support** agent everywhere else – all from the same one line of code.

## How it works

Instead of one agent's `apiKey`, the workspace script uses a **workspaceKey**.
That one key loads your whole workspace, then Chatref picks which agent to
show on each page:

* It checks every agent's **Display Rules** against the page URL.
* If a page matches an agent's rules, that agent shows.
* If no agent matches, your **default** agent shows.

## Set it up

<Steps>
  <Step title="Copy the workspace script" icon="copy">
    On the **Deploy** page, switch to the **Multi-Agent Routing** tab and copy
    the workspace script. It uses a `workspaceKey` instead of one agent's
    `apiKey`:

    ```html theme={null}
    <script src="https://widget.chatref.ai/loader.js?workspaceKey=YOUR_WORKSPACE_KEY" async></script>
    ```

    Paste it once into your site, just before `</head>` – the same place as a
    single-agent script. See [Embed on Your Website](/deploy/embed-on-website)
    for where that is on each platform.
  </Step>

  <Step title="Set each agent's Display Rules" icon="sliders">
    Open each agent and set its **Display Rules** to the pages it should appear
    on. For the example above, the Sales agent matches `/pricing` and `/plans`.
  </Step>

  <Step title="Pick the default agent" icon="robot">
    Choose one agent as the **default**. It shows on every page that no other
    agent's rules match – so the Support agent covers the rest of the site.
  </Step>
</Steps>

<Tip>
  Start with two agents and one default, then add more as you grow. Keep the
  default agent broad so no page is ever left without an agent.
</Tip>

## Next steps

<CardGroup cols={2}>
  <Card title="Display Rules" icon="sliders" href="/widget/display-rules">
    Control which pages each agent shows on with URL match rules.
  </Card>

  <Card title="Embed on your website" icon="code" href="/deploy/embed-on-website">
    Where to paste the script on WordPress, Shopify, Webflow, and more.
  </Card>
</CardGroup>
