---
title: "AI agent routing"
description: "Reassign an ongoing conversation to a different AI agent with a dialog that adds a tag and a rule that checks it."
---

# AI agent routing

> Reassign an ongoing conversation to a different AI agent with a dialog that adds a tag and a rule that checks it.

[Rules](https://docs.moveo.ai/docs/environments/environments-rules.md) can perform actions after the conversation starts. This guide reassigns the
conversation to a different [AI agent](https://docs.moveo.ai/docs/ai-agents/overview.md) with rules and
[tags](https://docs.moveo.ai/docs/ai-agents/operations/tag.md) in a dialog.

## The plan

This example continues with the agent created in [Build your first AI agent](https://docs.moveo.ai/docs/ai-agents/quickstart.md).
In this example, a gym's **Upsell Agent** handles membership payments. When the user wants to
change their membership plan, a rule assigns the conversation to a different AI agent, the
**Change plan Agent**. This AI agent is of the **Customer Support** type.

To do this, create a dialog in Agent 1 that triggers when the user asks
to change their membership plan. This dialog uses a tag that the rule evaluates. The rule then assigns the conversation to the **Change plan Agent**.

:::note
To create an AI agent from scratch, see
[Build your first AI agent](https://docs.moveo.ai/docs/ai-agents/quickstart.md).
:::

## Create the dialog

A [dialog](https://docs.moveo.ai/docs/ai-agents/dialogs.md) is a set of messages that the AI agent sends to the user. In
this case, create a dialog in the **Upsell Agent** that triggers from an
[intent](https://docs.moveo.ai/docs/ai-agents/intents.md) matching when the user asks to change their membership plan.

### Intent

1. Go to **AI Agents**.
2. Select the **Upsell Agent**.
3. Go to **Workflows > Intents**.
4. Select **Create intent**.
5. Name the intent **Change plan**.
6. Add examples of what the user says when they want to change their membership plan. For
   example:
   - I want to change my membership plan.
   - Can I change my membership plan?
   - How can I change my membership plan?
7. Select **Save**.

### Dialog

The key point of this dialog is the replay action. This action triggers a message on the
user's behalf. The user does not see this message, but the rule evaluates it and the logs show
it.

1. Go to **Workflows > Dialogs**.
2. Select **Create dialog**.
3. Name the dialog **Change plan**.
4. Drag the **Intent** action from the right sidebar to the canvas.
5. Select the **Change plan** intent in the dropdown list.
6. Add a [text response](https://docs.moveo.ai/docs/ai-agents/responses/text.md) message to the dialog. For example:
   - Sure, I can help you with that. Let me assign you to our **Customer Support Agent**.
7. Add a [tag](https://docs.moveo.ai/docs/ai-agents/operations/tag.md) to the dialog. The rule evaluates this tag. For example: `change_plan`.
8. Finally, add a replay action to the dialog.

## Create the rules

With the dialog ready, you need a way to connect the AI agent to the user. First, create a rule that assigns the conversation to the **Upsell Agent**. This rule triggers
when the user starts a conversation. Then, create a second rule that assigns the
conversation to the **Change plan Agent** when it evaluates the tag `change_plan`.

:::warning
You **cannot** test this routing with the AI agent
[test](https://docs.moveo.ai/docs/ai-agents/test.md) feature, because that feature tests the
AI agent only, not rules. Test the routing in a real conversation.
:::

### Assign to Upsell Agent

1. Go to **Deploy > Rules**.
2. Select **Create**. The **Create rule** panel opens next to the rule list.
3. Enter a **Name** and select **Continue**.
4. Set the **Trigger** field to **Customer starts conversation**.
5. Set the **Actions** field to **Assign AI agent** and select the **Upsell Agent**.
6. Select **Done**. Moveo creates the rule as active.

### Assign to Change plan Agent

Follow the same steps as the [previous rule](#assign-to-upsell-agent), with these changes:

- Set the **Trigger** field to **AI agent has replied**. The AI agent adds the tag while it replies,
  so a rule that runs before the reply cannot see the tag.
- Set the **Conditions (optional)** field to **Tag** is **change_plan**.
- Set the **Actions** field to **Assign AI agent** and select the **Change plan Agent**.

## Next steps

- [Rules](https://docs.moveo.ai/docs/environments/environments-rules.md)
- [Tag](https://docs.moveo.ai/docs/ai-agents/operations/tag.md)
- [Different language, different AI agent](https://docs.moveo.ai/docs/environments/environments-rules-language.md)
