> For the complete documentation index, see [llms.txt](https://docs.noqo.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.noqo.ai/actions/multiagent-systems/switch-active-bot.md).

# Switch active bot

## Description of the Workflow

Below we will provide some examples where this work scheme is useful, followed by a detailed guide on configuring it in one of the examples.

### Organizing Work with Different Types of Clients

Suppose we have a task to organize the work of a consultant bot. In this case, depending on the status of the interlocutor (whether they are an existing client or not), answers to their questions, as well as the information available to them, are completely different. That means if the interlocutor is already our client, we conduct the dialogue based on one business process, and if not yet a client, then on a completely different one. Solution options:

1. We could do all this on one bot, by instructing it to first determine the client’s status and then, based on the status, provide relevant responses. However, in this case, our bot’s instructions would be overly complex, leading to the following consequences:
   * Increased likelihood of the bot getting confused and delivering information that doesn’t match the client’s status;
   * Responses would be more expensive since the bot's instructions include descriptions of all business processes and also indicate the necessity to determine the client’s status;
   * Supporting such a large instruction set would be complicated;
2. We split the task into 3 subtasks:

   * Determine the client's status;
   * Work with existing clients;
   * Work with prospective clients;

   For each subtask, we create a separate bot, similar to how in real life, there could be a separate employee for each such task: a secretary, client manager, and prospective client manager:

   * "Secretary" bot whose only task is to determine the client’s status and then switch the dialogue to the respective bot;
   * "Client Working" bot which only has information about working with existing clients and knows nothing about the secretary's tasks or the prospective client manager’s responsibilities;
   * "Prospective Client Working" bot which similarly only knows its tasks.

   In this setup, the "Secretary" bot initiates the dialogue, answers the call, identifies the client, determines the status, and switches the client to the appropriate specialist (another bot). The respective bot then takes over the dialogue. Such a setup offers:

   * Scalability potential (adding other specialists, e.g., for working with VIP clients);
   * Each bot's instructions only pertain to its tasks, preventing the bot from reverting to incorrect responses or worse, providing inaccessible information for that client status;
   * The cost of dialogue is significantly cheaper since the response involves only the instructions pertinent to this dialogue and its current state. Furthermore, if the bot makes fewer mistakes, dialogues are shorter since the client gets results without additional unnecessary questions and clarifications.

## Organizing Company Work across Multiple Branches

Another example where a schema with switching the active bot may be useful is organizing a company’s work with multiple branches but a single incoming phone number. Different branches may have varying lists of services, price lists, contact information, delivery times, and so on. Trying to describe all this in one bot would result in chaos, and achieving proper bot operation would likely be unattainable. However, creating a bot for each branch and adding a "Secretary" bot will resolve the issue.

Some companies fundamentally need to implement a schema with multiple bots; these are companies using integration with a CS (have multiple branches and one incoming communication channel), as integration is based on a unique branch identifier, and a bot is created for each branch linked with the CS branch. If a company has one incoming number, there must be someone to determine which branch to switch the client to—hence, an additional "Administrator" bot is necessary. Below, we’ll look at creating such an "Administrator" bot for a company using CS integration.

### Creating Bots

At this stage, standard bot creation actions are performed. Since we've decided to create an example with CS, at this stage we create bots for each branch in accordance with the CS operations manual. After the bots are created and tested, we proceed to create the "Administrator" bot. This bot is created in the personal account, just like any regular bot. Integration with CS isn't required; it should know nothing about CS; its only task is to know what branches exist and find out from the client which branch they want to connect to. Therefore, we add a new bot on the "Bots" tab and write the basic instruction regarding the order of greetings, response styles, and the main task—determine the branch.

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FicCprpOdmMR8DmhNm14Y%2Fimage.png?alt=media&amp;token=cbb3c61a-b564-427e-ba65-ad0fd7440e62" alt=""><figcaption></figcaption></figure>

Once the "Administrator" bot is created, it is essential to set its name and describe its task in the instructions. All other settings are performed individually, based on the specifics of the particular task.

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FMuHlBn8lIOBGTI9G3Twf%2Fimage.png?alt=media&amp;token=070a4c93-2208-441c-8e12-561692aa2362" alt=""><figcaption></figcaption></figure>

### Creating Workflow for implementing bot dialogue switching

In the "Administrator" bot, we navigate to the "Workflows" tab and create a workflow for each branch to switch the active bot:

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FIYo5fT7aFjtQtINrSwhc%2Fimage.png?alt=media&amp;token=0506d914-acd0-4379-acc5-a3bab25790f2" alt=""><figcaption></figcaption></figure>

Click "Add" button.

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FVEgvlhwvb7Fb0jLtRj9F%2Fimage.png?alt=media&amp;token=dad43f86-e785-49c3-9c14-5678c49b22dc" alt=""><figcaption></figcaption></figure>

Choose "Change active bot" step.

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2Fwdp7GGtZB6QPxOU2tftU%2Fimage.png?alt=media&amp;token=2bd65605-5a14-4398-a0b9-84f4d3155d88" alt=""><figcaption></figcaption></figure>

Set the name for the workflow. In this case it will be "Switch to Branch 1". Choose the bot it will switch to. In the "Bot selection setup for response" choose "Active bot" option. Later you will need "Add a step" button to add another step to this workflow.

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FMeB0S807ZJFVZQ6UYelu%2Fimage.png?alt=media&amp;token=6a4ec33c-7529-4126-8d05-bc82be04418d" alt=""><figcaption></figcaption></figure>

Set the function name to the workflow. The bot will call this function to use the workflow for the branch switching. Add a description to the function to ensure its more stable use.

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2F3RoUuWMyHvPsNrNn0ZBS%2Fimage.png?alt=media&amp;token=dbca64c2-3ca8-4f72-9f16-da98ffb8d490" alt=""><figcaption></figcaption></figure>

Add an argument that will contain the message from the client, you can do this on the "Action variables tab".

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FdfVLVNOUd7ZtPYGp6AYx%2Fimage.png?alt=media&amp;token=b66b6710-36f8-4f69-b8da-cbec566a9656" alt=""><figcaption></figcaption></figure>

After setting up the first step, click the **“Add a step”** button to add the second one.

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FMzz5vSwoJ2cHxx7tWmeQ%2Fimage.png?alt=media&amp;token=8ec1f919-74a7-4661-bf94-86aa327fde70" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FlSWvoOAk0rvviAa1KZbn%2Fimage.png?alt=media&amp;token=95f89c51-2894-48df-856a-11a2988e4d6c" alt=""><figcaption></figcaption></figure>

The only thing that needs to be changed here is the bot being called. The client’s message is passed to the bot through the **“query”** argument, which you can view in the **“Request text to the bot”** box.

### Setting the Active Bot Switch

Overall, filling out the function description and workflow name is sufficient for the "Administrator" bot to automatically call the required function and switch dialogue to the respective branch bot. However, there’s an option to directly specify in the "Administrator" bot’s instruction when to call each action:

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FdggxMdP3oIznOdk17iWE%2Fimage.png?alt=media&amp;token=bfa54916-27ef-4108-bb09-ded6953e46cd" alt=""><figcaption></figcaption></figure>

To ensure a smooth dialogue switch, we need the Branch 1 bot to answer the client’s question and then continue the conversation according to the client’s request. To achieve this, we need to add a specific command to the Administrator’s prompt.

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FvQQW2rllP2FWsAqlHUMO%2Fimage.png?alt=media&amp;token=48cb005c-3cd0-4f62-abd4-aca118bb56ae" alt=""><figcaption></figcaption></figure>

### Bot Operation Analysis

You can see the details of this workflow within the dialogue in the dialogue export file.

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FzXXOt6fHSlwCFB1mzEtM%2Fimage.png?alt=media&amp;token=d35dcc46-faf8-45b4-9dab-1d7f594f9eba" alt=""><figcaption></figcaption></figure>

The presented example shows that the dialogue is conducted with the administrator bot, but the last message has already been formed by the branch bot, as this example implements the scheme of transferring the dialogue summary with the administrator to the receiving bot. You can also see that the dialogue has been switched to the Branch 1 bot.

## Procedure for connecting CRM channels

*The correct connection is as follows:*

* **Admin bot** — channel is connected, responses are enabled, additional functions are disabled (filling in the fields, etc.)
* **The bot we switch to** — channel is connected, answers are switched off, additional functions are switched on

{% hint style="success" %}
This connection scheme is relevant for CRM-systems [Bitrix24](https://docs.noqo.ai/channels/crm-systems/bitrix24.md), [Kommo](https://docs.noqo.ai/channels/crm-systems/kommo.md).
{% endhint %}

## The order of connecting the remaining channels

Since the admin is responsible for receiving the first message, **incoming channels must be connected to the admin bot**. Channels to other bots do not need to be connected.

*The general rule is:*

* the bot-administrator has a communication channel connected
* the bot-employee has functions connected

> ***For example:***
>
> * 1 bot is connected only to WhatsApp - responds to client messages
> * 2 bot is connected only to Yclients - records the client for a session
