AI Assistants is a Twilio Alpha project that's in Developer Preview.
View the current limitations for details about feature limits during developer preview.
Transitions are crucial for keeping humans in the loop and escalating conversations with your AI Assistant when necessary. Currently, these transitions can be configured by giving your AI Assistant a Tool. In the future, Assistants will support native transitions.
In this guide, you will learn how to transition a conversation with your AI Assistant to a Flex agent.
To begin, you will need the following:
After you've connected your AI Assistant to Twilio Conversations, your AI Assistant will listen to any message that has only one participant (your customer) in the conversation. To hand off the conversation to a human agent, the AI Assistant has to call a Tool that uses the Flex Interactions API to hand off to a Flex agent.
You can do this either by using a Twilio Function that was already deployed into your Twilio account as part of the Conversations setup above, or by creating your own HTTP endpoint.
Either way, once a second participant joins the conversation, your AI Assistant will automatically stop listening.
If you followed the AI Assistants with Twilio Conversations guide, one of the Twilio Functions that you deployed as part of this was a Flex Handover tool.
To make sure you hand off the conversation to the right Flex agents, configure environment variables for your Twilio Functions that specify the TaskRouter Workspace SID and TaskRouter Workflow SID for the handoff.
In the ai-assistants-samples
project that you cloned and deployed, run the following commands:
1twilio serverless:env:set --key=FLEX_WORKFLOW_SID --value=<your-taskrouter-workflow-sid>2twilio serverless:env:set --key=FLEX_WORKSPACE_SID --value=<your-taskrouter-workspace-sid>
Make sure to replace <your-taskrouter-workflow-sid>
and <your-taskrouter-workspace-sid>
with the respective values.
To use this webhook as a Tool, you will need your Functions domain from the AI Assistants Samples deployment. If you can't find your Functions domain, head to the Twilio Console and click on Service Details next to your ai-assistants-samples
Service. You can find the domain in the Environments section.
Once you have both your Flow SID and your Functions domain, you can go into your AI Assistant in the Twilio Console and create a new Tool with the following configuration:
Field | Example Configuration | Notes |
---|---|---|
Name | Flex Agent Handover | You can modify this if you have multiple handovers. |
Description | You MUST use this if you don't know how to fulfill the request to let another customer service agent handle the conversation. | Use this description to tell the AI Assistant when to use the tool. |
Input |
| |
Method | POST | |
URL | https://<your-functions-domain>.twil.io/tools/flex-handover | Make sure to replace <your-functions-domain> with your own value. |
Alternatively to using Twilio Functions for your Tool, you can host an HTTP endpoint yourself and use the Flex Interactions API to route the conversation to a Flex Agent.
Here is an example of calling the API using the Twilio Python helper library:
1interaction = twilio_client.flex_api.v1.interaction.create(2channel={3'type': 'chat', # can be chat or SMS4'initiated_by': 'customer',5'properties': {6'media_channel_sid': conversation_sid # Stored in the `X-Session-Id` request header7}8},9routing={10'properties': {11'workspace_sid': taskrouter_workspace_sid, # your taskrouter workspace sid12'workflow_sid': taskrouter_workflow_sid, # your taskrouter workflow sid13'attributes': {14'from': 'Customer Name' # the name of the customer (you can use the `X-Identity` header to look up the customer's identity)15}16}17}18)
Now you've configured your AI Assistant to hand off a conversation to a Flex agent if it cannot fulfill a user's request.