# Use an AI assistant in your chatbot

To use an AI assistant in your chatbot, add the **AI assistant** element.

The process is as follows:

1. In your chatbot, [capture the end user's message](https://www.infobip.com/docs/ai-hub/ai-assistant/add-assistant-to-chatbot#save-user-input-in-attribute) in an attribute.
2. [Add the AI assistant element](https://www.infobip.com/docs/ai-hub/ai-assistant/add-assistant-to-chatbot#add-assistant-to-chatbot) and configure it. In the AI assistant element, pass the attribute as an input to the AI assistant.
3. The assistant generates a response based on the input, the assistant configuration, and the documentation uploaded to the assistant.
4. In the AI assistant element, get the assistant's response and save it in another attribute.
5. [Share the response](https://www.infobip.com/docs/ai-hub/ai-assistant/add-assistant-to-chatbot#share-assistant-response-with-user) with the end user.

## Save end user's message in an attribute [#save-user-input-in-attribute]

To save the message, follow one of these options:

- Use the predefined attribute **lastReceivedTextMessage**, which captures the last message sent by the end user.
- Save the end user's response in a standard attribute by using the **Save user response** element.

## Add the AI assistant element to your chatbot [#add-assistant-to-chatbot]

Use the AI assistant element to add an AI assistant to your chatbot.

### Guidelines [#guidelines-add-assistant]

- You can select only 1 AI assistant in the element.
- You can add only 1 AI assistant element to a dialog.
- You can have more than 1 AI assistant in your chatbot.

### Configure the AI assistant element [#configure-ai-assistant-element]

Configure the AI assistant element as follows:

#### Configure the basic fields

1. Select an existing assistant from the list.

2. In the **User Message** field, select the attribute in which the end user’s message is stored. The chatbot sends this attribute value to the AI assistant service.

#### Configure additional options

- **External content source:** If you set this source, the AI assistant ignores data that is defined in its main content source, and uses the external content source instead.
- **Memory key:** Use the memory key to share memory between assistants and other GenAI components that have the same key.
- **Return contexts:** If you set this field to **True**, the assistant returns the parts of the documentation that were used to generate the response.
- **Prompt variable:** This field is used if the **Prompt template** section in the selected AI assistant contains _\{prompt_var\}_. The value from the **Prompt variable** field is passed to _\{prompt_var\}_. This helps you personalize chats or give context to the AI assistant.

  Example: In the **Prompt variable** field, add _Refer to the end user as _\{\{name\}\}_.

#### Save the assistant's response

The AI assistant returns an answer to the user question in a JSON schema:

{
    "response": "Assistant's response"
}

Extract the response and save it by using **Response body attributes**. To extract the response text, select the attribute in which you want to save the response and define the JSON path.

Example: `$.response`.

You can use the JSON response and the extracted value for further processing, or return the value to the end user.

#### Add fallback

The fallback action is triggered if the AI assistant service is not responding. You can either redirect the end user to a different dialog or transfer the conversation to an agent.

For more information, refer to the [Add fallback](https://www.infobip.com/docs/answers/chatbot-elements/how-to#fallback) documentation in Answers.

## Send the response to the end user [#share-assistant-response-with-user]

To return the assistant's response, use a **Text** element and add the attribute in which you saved the assistant's response.

## Create conversational AI chatbots [#conversational-chatbot]

To configure a more advanced AI assistant experience, use Infobip's other [Generative AI tools](https://www.infobip.com/docs/ai-hub#genai-tools).

Example:

After the assistant answers the end user's question, send the response in a Text element.

Then, in another dialog, ask the end user for a new user input. Use the [**GenAI Intent detection**](https://www.infobip.com/docs/ai-hub/genai-intent-detection) element to determine where to route the conversation. In the target dialog, you can define a way to route the conversation back to the AI assistant, resulting in a conversational AI experience.