Automation Editor
...
Building Automations
AI chatbots

Chatbot goal automations

11min

Goal automations provide a mechanism to steer the conversation with the widget user such that distinct goals are accomplished. For example, when a user first begins to use the widget you may want to collect the user's name and email.

Document image


Unlike chatbot tool automations, goal automations are not invoked by the AI model. Instead, they are a mechanism for building chatbot logic in an easy-to-understand manner.

Goal automations can be nested, such that a high-level goal like "collect user information" may consist of a goal automation that starts by collecting their name, then it invokes a goal automation to collect their email, then that invokes another goal automation to verify the email by sending and confirming a random PIN number to the provided email address.

Generally goal automations will make use of either Conversation memory or Browser storage actions to know when pieces of information have successfully been collected from the chat widget user. The parent automation will lookup information to know whether or not a goal automation needs to be invoked.

When the parent automation invokes the goal automation, the chat conversation is redirected to the goal automation until either of these occur:

  • The goal automation invokes another nested goal automation, or
  • The goal automation indicates the goal has been accomplished by executing the "chat goal accomplished" action

A key concept to grasp is that when goal automations interact with the AI model, they are all conversing with the same conversation thread as identified by the conversation uuid. So the AI model is aware of the full conversation history as the conversation progresses. The goal automations provide instructions to the AI model to focus it on performing the desired goal.

Goal Automation Trigger

To build a goal automation, start by selecting the system utility trigger:

Document image


Then select the Automation Chat Widget:

Document image


Choose the new chat goal message instant trigger:

Document image


The trigger needs no configuration, so just save it to add it to the diagram. This trigger functions the same as the new chat message trigger, in that it emits the conversation uuid and the message the chat widget user has sent.

When the parent chat automation invokes the goal automation, the chat conversation is redirected to the goal automation such that its trigger will fire each time the chat widget user sends a message.

Goal Automation Action Logic

The general pattern of a goal automation will be like this one that collects the chat user's email address:

Document image


The above goal automation that collects the chat user's email can be described textually as:

Each time the user sends a chat message, the AI model will see if they entered an email address. If not, the AI model will provide a message saying that they cannot be helped until their email address is provided. If the AI model's response does not contain JSON with the provided email address, send the chat response back indicating the conversation cannot continue until their email address is provided. Otherwise parse the provided email address from the JSON the AI model returned, save the email in conversation memory, and indicate the goal has been accomplished. The parent automation will then wake up and continue where it left off.

Let's walk through the key parts of this example automation.

The AI model is provided these instructions in the "send agent a message" action:

You are a chatbot. Your only goal is to obtain the user's email. When you know their email, your only response will be JSON in this schema: {"email": "[email protected]"}
Document image


The purpose of emitting JSON when the email is known is so that the automation has a way to parse out the value from the AI model's response.

The condition just checks to see if the AI model's response starts with a "{" which indicates the AI model has emitted the JSON containing the email:

Document image


If JSON is not emitted, the goal automation sends back the AI model's response to the chat widget. Otherwise the JSON is parsed via JavaScript:

Document image


The parsed email is then stored into conversation memory:

Document image


Goal Automation Completion

The "chat goal accomplished" action indicates that the goal automation is finished. The parent automation then continues where it left off.

Document image


Goal Automation Execution

Goal automations are executed by either of these Chat Automation Widget actions:

Document image


The "await chat goal if item not in memory" action is a convenience action that first looks up a named item from the conversation's memory. If the item does not have a value, the selected chat goal automation is executed. Otherwise the parent automation would need to first use an action to fetch the value from conversation memory and a conditional to see if the value existed or not before invoking the "await chat goal" action.

Both actions are similar, in that the parent automation will snooze and the chat conversation will be redirected to the selected goal automation:

Document image


When control passes to the goal automation, a chat message is sent back to the chat widget user. The chat reply should inform the user what they need to do to satisfy the goal, generally by providing a piece of information.

Document image


When the goal automation executes the "chat goal accomplished" action, the parent automation wakes up from its snooze and continues its processing after that action. The chat conversation is redirected back to the parent.

Nested Goal Automations

Goal automations can be nested, when the chat widget user needs to provide multiple pieces of information or perform multiple steps. Just embed one of the "await chat goal" actions within a goal automation:

Document image


Generally the "await chat goal" action is placed right before the "chat goal accomplished" action. In this manner, the first goal has been accomplished and then another goal is being started.

As before, the goal automation is snoozed and the chat conversation redirects to the nested goal automation. When the nested goal has been achieved, the parent goal automation wakes up and continues where it left off.