Skip to main content

AI agent

The AI agent block in J‑Graph lets you create and configure AI agents. Agents use LLMs to engage in dialogs and handle any user requests.

Each agent has its own role and goal. For example, an agent can be a translator who works with multiple languages.

AI agent block

To get started:

  1. Set up connection to Caila.
  2. Add an AI agent block.

LLMs for agent

The agent connects to LLMs through the openai-proxy service on the Caila platform.

caution

LLMs are available only with a paid Caila plan.

Add a secret to JAICP to get started.

Access token for Caila

To use services and generative models from Caila in third-party applications, including JAICP, you need a personal access token. To issue a token:

  1. Go to Caila.

    tip

    Caila and Conversational Cloud use a shared account base, so if you are registered on Conversational Cloud, you do not need to register additionally on Caila.

  2. Go to the My spaceAPI tokens section.

  3. In the upper right corner, click Create token.

  4. Give a name to the token, generate it, and copy it to the clipboard.

Next, add a secret to JAICP:

  1. Go to JAICP.

  2. In the Secrets and variables section add a new secret:

    • Name is LLM_API_KEY.
    • Value is the received Caila token.

Add block

To add a block to the script:

  1. Click Add reaction on a state in J‑Graph.
  2. Select AI agent in the Generative AI section.
  3. Specify the agent parameters.
  4. Click Save.

Parameters

General

  • Agent ID: each agent in the script must have a unique ID. In one state, there can be only one AI agent block.

  • LLM: specify the LLM that the agent uses. To access the LLM, the agent uses the openai-proxy service on the Caila platform. You can view available models and their prices on the service page.

    caution

    Parameters for transitions only work if the LLM supports function calling. For a list of models that support function calling, see the OpenAI documentation.

    The OpenAI website is not available for Russian IP addresses.

  • Agent role: the agent role or character in the dialog. For example: Bank employee. Affects the conversation tone and how the agent talks about itself.

  • Agent goal: in the dialog, the agent tries to achieve this goal. For example: Help the user make an order.

  • Instructions: instructions for the agent. Use it to specify the behavior of the agent. Example: Answer only in the user’s language. First, make sure you understood the question correctly.

tip

Sometimes an LLM might give unexpected responses or inaccurate data.

We recommend that you fill in the role, goal, and instructions with detailed information. This way, you can get more predictable and consistent results.

In all fields, you can use value substitutions inside the {{}} brackets. The brackets can contain any valid JavaScript expression, such as a built-in variable reference.

Dialog history

You can pass the previous bot dialog history to the agent. This will allow the agent to take into account the context of the dialog:

  1. Enable the Pass the bot dialog history to the agent parameter.
  2. Fill in the Number of recent messages from the history parameter.

Transition to steps

caution
  • If the user is in the dialog with the agent:

    • By default, the bot can transition to another state only using global intents.
    • The bot does not react to events.
  • Use the parameters below to change the logic of state transitions.

  • Allow the agent to transfer the dialog to other agents in the script: if the setting is enabled, the agent can transition the dialog to other states containing the AI agent block.

    note

    For this parameter, possible transitions between agents are not displayed on the J‑Graph canvas.

    When selecting a state, the agent takes into account:

    • Roles and goals of other agents.

    • Names of the states that contain agents.

      tip

      We recommend giving states names that are very different from each other. The agent might make more mistakes if the script contains states with similar names, for example: NoMatch1 and NoMacth2.

  • Next state if the agent achieved the goal: the bot transitions to this state if the agent considers the goal achieved and the user has no more questions.

  • Next state if agent has no information: the bot transitions to this state if the agent considers that the user request is not related to the goal.

RAG knowledge base

You can connect a knowledge base to the agent. The agent takes the knowledge base data into account when generating responses. For more information on how the agent works and how to connect the knowledge base, see Use knowledge base.

Analytics

The agent adds the following comment to each user phrase: Phrase processed by the AIAgent tag.

In the AnalyticsDialogsPhrases section, by this comment you can find the phrases that were processed by the agent.

Examples

This example uses a single AI agent that translates texts into any language.

Example with AI agent block
Block parameters
  • Agent ID: translator_agent.
  • LLM: gpt-4o.
  • Agent role: Professional translator.
  • Agent goal: Translate text into another language.
  • Instructions: If necessary, ask the user for the target language. Give 3 best translation variants.
  • Next state if the agent achieved the goal: Feedback.
  1. If the user writes translate the word “happy”, the dialog transitions to the Translation state.

  2. In the Translation state, the agent communicates with the user:

    1. The agent asks what language to translate the word into.
    2. The agent suggests 3 translation variants.
  3. If the user has no more questions, the dialog transitions to the Feedback state.

tip

You can use multiple agents in a single script. See the Multiagent bot in J‑Graph article.