---
title: "Rules"
description: "Create rules that assign AI agents, departments, tags, and bundles from triggers and conditions, and manage and reorder them."
---

# Rules

> Create rules that assign AI agents, departments, tags, and bundles from triggers and conditions, and manage and reorder them.

Rules let you automate actions in conversations, such as assigning the conversation to a specific AI
agent or tagging a conversation.

Rules automate your workflows, so your team works efficiently and your customers get a better
experience.

An [environment](https://docs.moveo.ai/docs/environments/environments-overview.md) can have one or more rules. The rule list and the rule editor are
on the same page. When you open or create a rule, the editor opens in a panel next to the list.

To create a rule:

1. Go to **Deploy → Rules** and select **Create**. The **Create rule** panel opens.
2. Enter a **Name** and, optionally, a **Description**. Then select **Continue**.
3. Set the **Trigger**, the **Conditions (optional)** and the **Actions** of the rule.
4. Select **Done**.

Moveo creates the rule as active, adds it to the list and shows **Rule created successfully**.

## Customize your rule

### Create the trigger

In the **Trigger** field, set the triggers that start the rule. If any of the selected triggers
is true, the rule runs. The available triggers are:

| Trigger                            | API value          | When the rule runs                                                      |
| ---------------------------------- | ------------------ | ----------------------------------------------------------------------- |
| **Customer starts conversation**   | `first_message`    | On the first message of a new conversation, before the AI agent replies |
| **Customer responds to a message** | `any_user_message` | On every customer message, before the AI agent replies                  |
| **AI agent has replied**           | `post_message`     | After the AI agent has sent its reply                                   |

The API value is the trigger in the [rules API](/api/rest/add-rule) and in the
`moveo_create_rule` tool of the Moveo MCP server. The MCP resource
`moveo://schemas/rule-condition-operators` lists the triggers, conditions, and actions. The
filter of the rule list uses other words for the same triggers: **Starting a conversation**,
**Responding to a message**, and **After the AI agent replies**.

The first two triggers evaluate the rule **before** the message reaches the AI agent, so the
conditions see the conversation as the message arrives. **AI agent has replied** evaluates
the rule **after** the AI agent has answered, against the conversation state the AI agent returned
in that turn. Use this trigger when a rule needs to react to something the AI agent did while
replying, such as adding a [tag](https://docs.moveo.ai/docs/ai-agents/operations/tag.md) as it
[hands over](https://docs.moveo.ai/docs/ai-agents/operations/handover.md) the conversation. A rule that runs before the
reply cannot see that tag, so it never matches. See
[Route a handover to a department](#route-a-handover-to-a-department) for a complete example.

#### Rules that run after the AI agent replies

Keep the following in mind before you create a rule with the **AI agent has replied**
trigger, or move an existing rule to it:

- **The trigger is the opt-in.** A rule runs after the reply only if it carries this trigger. An
  existing rule with **Customer responds to a message** does not start running after the reply.
- **Replace the trigger instead of adding it.** A rule that has both **Customer responds to a
  message** and **AI agent has replied** runs twice in every turn, once before the
  reply and once after it. If the rule only routes a handover, replace its trigger. If the rule
  also does other things, leave it unchanged and create a separate rule with the new trigger.
- **Conditions see the conversation after the handover.** When the AI agent hands over, it has
  already left the conversation by the time the rule runs. A condition such as **AI agent
  assigned** is **known** matches before the reply but not after it. Review any **Agent assigned**
  and **AI agent assigned** conditions before you move a rule to this trigger.
- **Actions apply to the next message, not to the reply that the AI agent sent.** The customer already has the
  reply when the rule runs. **Assign AI agent**, **Assign knowledge base** and **Apply bundle**
  change how Moveo handles the next customer message. **Assign department** and **Close
  conversation** take effect immediately.
- **The rule cannot undo a handover.** Moveo ignores **Assign AI agent** after the handover, so a
  rule with this trigger cannot return a conversation to the AI agent after a human agent took it
  over.
- **It runs only after an AI agent reply.** The trigger does not fire when an agent transfers a
  conversation manually, for a handover through the API, for campaign messages, or in the
  AI agent test chat and simulations. It does fire when the AI agent sends an inactivity reminder,
  because the reminder is a reply. A rule that closes the conversation on this trigger also closes
  it after a reminder.

### Apply the condition

A condition is optional. A rule without a condition evaluates as true and triggers the
action. Available conditions include:

- **Availability**

  - Business hours

- **User**

  - Name
  - Email
  - Phone
  - Language
  - Timezone
  - Country
  - City
  - Browser
  - Platform

- **Conversation**

  - Channel
  - Message content
  - Tags
  - Customer/referral URL
  - Agent assigned
  - AI agent assigned
  - Integration

Combine these conditions with **and**/**or** statements.

### Then

Finally, select the **actions** that run when the conditions match, such as assigning an AI agent
to answer the message or tagging the conversation.

List of actions:

- Add [tag](https://docs.moveo.ai/docs/ai-agents/operations/tag.md)
- Assign [AI agent](https://docs.moveo.ai/docs/ai-agents/overview.md)
- Assign [knowledge base](https://docs.moveo.ai/docs/knowledge-base/knowledge-base-overview.md)
- Close conversation
- [Apply bundle](https://docs.moveo.ai/docs/environments/context-bundles.md)
- Assign [department](https://docs.moveo.ai/docs/chat/chat-departments.md)

Moveo creates each rule as active. A rule that you deactivate or duplicate stays inactive until you
activate it.

See the [AI agent routing guide](https://docs.moveo.ai/docs/environments/environments-rules-route-agent.md) for examples of assigning different AI
agents based on [tags](https://docs.moveo.ai/docs/environments/environments-rules-route-agent.md) and
[language](https://docs.moveo.ai/docs/environments/environments-rules-language.md).

## Route a handover to a department

When the AI agent hands over a conversation, it can add a tag that says which team should take it.
Because the AI agent adds the tag while it replies, the rule that reads the tag must use the
**AI agent has replied** trigger. A rule with **Customer responds to a message** runs
before the reply, does not see the tag, and leaves the conversation unassigned.

1. In the dialog that hands over the conversation, add a [tag](https://docs.moveo.ai/docs/ai-agents/operations/tag.md)
   action next to the [handover](https://docs.moveo.ai/docs/ai-agents/operations/handover.md) action. For example:
   `handover-sales`.
2. Go to **Deploy → Rules** and select **Create**.
3. Enter a name for the rule and select **Continue**.
4. Set the **Trigger** field to **AI agent has replied**.
5. Set the **Conditions (optional)** field to **Tag** is **handover-sales**.
6. Set the **Actions** field to **Assign department** and select the department. For example:
   **Sales**.
7. Select **Done**.

The rule assigns the [department](https://docs.moveo.ai/docs/chat/chat-departments.md) as soon as the AI agent hands over, and
the department distributes the conversation to its agents according to its assignment method.

:::warning
Rules do not run in the AI agent [test](https://docs.moveo.ai/docs/ai-agents/test.md) chat
or in simulations. Test this routing in a real conversation.
:::

## Manage your rules

Each rule in the list shows its name and description, and when it last ran. A rule that never ran
shows **Not used yet**. Inactive rules appear muted. Hover over a rule to see its name, description
and actions.

Select a rule to open it in the **Edit rule** panel next to the list. The **Save** button is
available after you change a field. If you close the panel or open another rule with unsaved
changes, Moveo shows a confirmation message first.

The **⋮** menu of each rule has these options:

- **Activate** or **Deactivate**: Turns the rule on or off.
- **Edit…**: Opens the rule in the **Edit rule** panel.
- **Rename…**: Opens the panel to change the name and the description.
- **Duplicate**: Creates a copy of the rule with the same triggers, conditions and actions. The copy
  gets a numbered name, for example `Name (1)`. Moveo adds the copy as inactive at the end of the
  list.
- **Delete…**: Deletes the rule.
- **Send to top** or **Send to bottom**: Moves the rule to the first or the last position.

## Reorder your rules

Reorder rules by priority. Drag a rule by the icon at the start of the tile and drop it in the
position that you want.

Put the highest-priority rule at the top and the lowest-priority rule at the bottom. In this video,
the **Outside business hours** rule moves from the third position to the second, so Moveo checks it
before the **Sales handovers** rule.

## Next steps

- [AI agent routing](https://docs.moveo.ai/docs/environments/environments-rules-route-agent.md)
- [Different language, different AI agent](https://docs.moveo.ai/docs/environments/environments-rules-language.md)
- [Context bundles](https://docs.moveo.ai/docs/environments/context-bundles.md)
- [Business hours](https://docs.moveo.ai/docs/environments/environments-business-hours.md)
