Automation Editor
...
Building Automations
AI chatbots

Building an AI chatbot

13min

This is the simplest AI-powered chatbot automation:

Document image


Each time someone enters a chat message, the trigger fires, the AI model generates a response, and the response is sent back to the chat widget.

Follow the instructions below to build the simplest possible AI chatbot.

Chat Message Trigger

Begin by adding a trigger and select System Utility:

Document image


Then choose Automation Chat Widget:

Document image


Then choose the "new chat message (instant)" trigger:

Document image


The widget settings appears, which allow customization of the widget's appearance.

Document image


The default settings result in a widget like this:

Document image


Here is an example of a customized widget:

Document image


To test edits made to the widget's appearance, save the automation and click its play icon from the dashboard:

Document image


The widget will load in a separate web page. Then you can make edits to the widget's appearance settings, save the automation, and reload the test page to view your edits.

Be sure to scroll all the way down the settings, where the widget's embed code appears:

Document image


Use the copy icon shown above to copy the widget embed code to place the widget in your web page.

AI Model Action

The brain of the chatbot is the AI model that responds to the chat widget user's prompts. Start by adding an action and choose to add an app:

Document image


Select "OpenAI Agent". You will need an OpenAI API key from https://platform.openai.com/api-keys to connect to their API, if you have not connected already.

Document image


Select the "send agent a message" action:

Document image


The settings will appear:

Document image


Let's walk through all of these settings:

Vector Store

The AI model can utilize information found in files uploaded to a vector store. To do that, first go to your OpenAI dashboard and open the Vector Storage page at https://platform.openai.com/storage/vector_stores. Then create a new vector store and upload files into it. Once the vector store has been created, it will then be selectable from the dropdown.

Enable Web Search

The AI model can optionally be allowed to make web searches to help it generate responses.

Model

OpenAI has many AI models with varied performance and intelligence. In general, faster models have worse intelligence. You can review their models at https://platform.openai.com/docs/models.

Output Formatting Instructions

These inform the AI model on how to format its output. The default instructions are suitable for use with the chat widget, where all output is done as HTML.

Conversation UUID

This identifies the conversation thread with a single chat widget user. When the widget first loads in a web page, a random conversation uuid is generated. Then that uuid is sent with all subsequent chat messages the user sends. Map the conversation uuid to the same field output by the new chat message instant trigger.

Document image


This OpenAI action utilizes the Conversation UUID to keep the conversation history with the AI model. This results in the AI model knowing the back-and-forth conversation history with the chat widget user.

Model Instructions

Provide instructions on how the model is to behave. This is where you define the conversational tone, the chatbot's purpose, and place guardrails on what the model should avoid doing.

Model Instructions

This is the input message to the model. For the chatbot, map the message emitted from the new chat message instant trigger.

Document image


Chat Response Action

To send the AI model's response back to the chat widget, start by adding an action and select "system utility":

Document image


Then select Automation Chat Widget:

Document image


Finally, select the "send chat response" action:

Document image


As with the AI model action, map the Conversation UUID field to the output from the new chat message instant trigger. Then map the message field to the response from the AI model.

Document image


That's it! You now have an AI-powered chatbot widget you can place on your web page.

Document image


Continue reading the following sections to learn how to build tool and goal automations to extend the functionality of chatbots.