> 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/calling-a-subordinate-bot.md).

# Calling a subordinate bot

### Work Description

Suppose, within the task of setting up a sales bot, you have the following initial data:

* The company sells windows.
* The company has 5 price tables from different suppliers.
* Two CRM requests need to be called: for order placement and order status.
* The instruction has lengthy descriptions over 3 A4 pages.
* The knowledge base contains at least 50 files.

In such a situation, we get quite a large volume of context, as we have extensive instructions with their own conditions + 5 described functions for tables + 2 described functions for web-hook calls and a knowledge base processing function. With such a volume, a model is 100% likely to forget important points in instructions, or have issues working with tables and web-hooks, sometimes making insignificant, and sometimes significant, errors. Due to errors, all the "magic" of working with the model will be lost.

Problems of attention loss can be resolved in this situation by the following solution:

1. A separate bot is created for working with tables, in which these tables exist. The main bot will not have tables.
2. A separate bot is also created for working with web-hooks.
3. For some blocks, specific bots are also created.
4. In instances when specific bots need to be called, they are invoked by writing standard function calls (more in the [article on functions](https://docs.noqo.ai/main-settings/system-prompt/functions.md)).

Thus, instead of 8 large functions for the main bot, we get only 3 concise ones (or slightly more if we decide to allocate pieces of the instruction into separate blocks).

This will immediately increase the model's accuracy with 100% probability, and also reduce costs. Before optimization, we would transmit a large volume of functions with each request. After optimization, separate pieces are called only at specific moments.

### Creating a Subordinate Bot

Initially, we need to create a standard bot:

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FXzKfGNkmc2zeTpLkLtzJ%2FSubordinate_bot_1.jpg?alt=media&amp;token=33f699ea-86b6-4ec0-8a4e-0acc7102a761" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2Fs7ZRL8f0ZiaTFw0KjQrT%2FSubordinate_bot_2.jpg?alt=media&amp;token=e18fa6ba-0843-47da-910c-12afa5c6b82d" alt=""><figcaption></figcaption></figure>

Remove the standard instruction for the subordinate bot, as greeting elements, tonality, general information, etc., may not have functional significance, and it should focus only on performing a specific task. Based on the example above, describe its personal instruction:

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2Fk9WWkKcudMuq1j46GQF9%2FSubordinate_bot_3.jpg?alt=media&amp;token=207ce37b-5467-4d80-b097-6815989479a4" alt=""><figcaption></figcaption></figure>

1. Set **Wait time in seconds** to 0 since we don't need delays here.
2. Inside the instruction, describe the essence of the specific task as concisely as possible, which the bot should perform. You can even add that it is a technical bot, and its task is to return a response in a specific format, for example, in JSON.

In this case, we described the bot’s task as calculating the cost in tables.

Next, let’s understand how the main bot will call the subordinate, described further below.

### Adding a Subordinate Bot to the Main Bot

In the main bot, you need to add the subordinate bot through the **Workflows** section:

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FMw319yXhUxZWwfVbUFUn%2FSubordinate_bot_4.jpg?alt=media&amp;token=c56b9b94-44b5-4d5f-98bc-da7e3c1e8d91" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2F6jetJL4YNnkEN0SW1IHI%2FSubordinate_bot_5.jpg?alt=media&amp;token=9a15e3fb-54bf-4a87-a88b-a4776a2f1d40" alt=""><figcaption></figcaption></figure>

**Action name** - simply the name for display in the list.

**Bot -** selecting a subordinate bot.

**Request text to the bot** - request text to be sent to the subordinate bot.

**Mode of saving sub-dialog with bot in a custom action** - this parameter controls how the main bot interacts with a subordinate bot and what context is passed between them.

> * **For every call, a new sub-dialog** - when this mode is activated, each call to a subordinate bot creates a new isolated dialog session.
> * **Each bot in an action has its own dialog box** - In this mode, each subordinate bot gets its own separate dialogue context, which is preserved across multiple invocations within a single session.
> * **One sub-dialog for the entire main dialog** - this mode allows you to create a single sub-dialogue into which all calls to the subordinate bot are sequentially added throughout the main dialogue. The subordinate bot receives the full context of the main dialogue history and remembers all its previous responses.

**Transfer history** - this setting allows the subordinate bot to receive the dialog history with the primary bot. The subordinate bot can use the context of previous conversations and take it into account when generating a response.

**Put the response of slave bot into a varible** - this option allows you to save the subordinate bot’s response to a user variable, which can then be used by the primary bot.

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FnkPr9Yh85jKzXldrObg1%2FSubordinate_bot_6.jpg?alt=media&amp;token=532004fd-eeaf-4f66-8690-ec305f2b94b5" alt=""><figcaption></figcaption></figure>

**Function name** - the name of the function that the LLM model will see. This name is specified in English without spaces. The name should reflect the general essence of the action.

**Function description** - a more detailed description of the essence of the action. Based on this description, Noqo will understand when it needs to be called.

### Call of a Subordinate Bot

Overall, having filled in the description and names of the action, this is enough for the bot to be automatically called from the main bot. But just in case, to level potential non-obvious instances for the main bot, we can explicitly state in the instruction the moment when we need to call the subordinate bot, referring to it by the function name specified in the Action:

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FvUbl0asLRC4sH5Jh9xW3%2FSubordinate_bot_7.jpg?alt=media&amp;token=4b3e3347-ac06-4166-b19b-ce7db133ae15" alt=""><figcaption></figcaption></figure>

### Analysis of Subordinate Bot Calls

When implementing Noqo, the longest process is debugging and tweaking instructions. Detailed work with debugging was discussed in a separate [section](https://docs.noqo.ai/main-settings/system-prompt/best-practices/instruction-debugging.md). Debugging of subordinate bots operates on a similar principle, and we will consider two methods: through chat and via an export file.

#### Analysis through Chat

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2F3O0OPoHq6p2L7IVtLqoX%2Fgenerated-image.png?alt=media&amp;token=56365fc0-f025-4871-9288-405ec79085ad" alt=""><figcaption></figcaption></figure>

In the response, which was expectedly formed by the subordinate bot, click the button with the i icon and examine the opened modal window:

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FiIR3M2Ul9QtXDZfIIk7S%2FSubordinate_bot_9.jpg?alt=media&amp;token=b3f39521-2243-4c2d-bf3c-5526cb58f454" alt=""><figcaption></figcaption></figure>

The response received from the subordinate bot is modified by the main bot - this is normal and correct.

#### Analysis through Export File

1. Find the needed dialogue with the main bot through the **History** tab and export the file through Actions -> Export:

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2Fke2s0TWLxEHKI19JH80m%2FSubordinate_bot_10.jpg?alt=media&amp;token=b9d16632-7d97-47e4-ae87-55073295c320" alt=""><figcaption></figcaption></figure>

The file is saved into the **Downloads** folder; open it as a regular file:

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FuQGQZuFKgkBexUSVgCPX%2FSubordinate_bot_11.jpg?alt=media&amp;token=d701ff06-cbea-440d-9da7-ecc7e31c2da2" alt=""><figcaption></figcaption></figure>

In the export file, function calls are displayed in a more convenient form.

If the function represents a call to a subordinate bot, we will see an icon of a robot head next to the i icon. Clicking on it will open a separate modal window with a dedicated export specifically for this bot:

<figure><img src="https://1782981877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKvUDH16L29QcaH0CuUhn%2Fuploads%2FgiMacbP7gPAApCHuzbBX%2FSubordinate_bot_12.jpg?alt=media&amp;token=1a331541-8ca0-40e0-8af0-b4e708788bb0" alt=""><figcaption></figcaption></figure>

Further analysis proceeds similarly; if it called anything, or any functions inside itself, we will see it in the form of service labels (which are absent in the screenshot above).
