Chatbot goal automations
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.

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.
To build a goal automation, start by selecting the system utility trigger:

Then select the Automation Chat Widget:

Choose the new chat goal message instant trigger:

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.
The general pattern of a goal automation will be like this one that collects the chat user's email address:

The above goal automation that collects the chat user's email can be described textually as:
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:

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:

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:

The parsed email is then stored into conversation memory:

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

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

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:

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.

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.
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:

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.