AI Assistants is a Twilio Alpha project that's in Developer Preview.
View the current limitations for details about feature limits during developer preview.
This Quickstart will guide you through creating your first AI Assistant in the Twilio Console.
An Assistant configuration consists of the following aspects:
Learn more about these core components in the AI Assistant Overview.
At the end of this Quickstart, you'll have an AI Assistant that can answer questions about recent Twilio news using the Twilio blog and about Disney characters using the Disney API.
Navigate to the Twilio Console and choose to create a new Assistant. Give it a name that's memorable to you. This name is not used in any customer-facing use cases and is purely for you to identify your Assistant.
Once you've created your Assistant, the first step is to give your Assistant a personality using the Personality Prompt. If you have built with Large Language Models (LLM) before, this is similar to a System Prompt but more high-level rather than fixed steps. If you have never worked with an LLM before, think of the Personality Prompt like the context you would give an employee on day one. Learn more about the Personality Prompt in the AI Assistant overview.
For this Quickstart, use this as an example Personality Prompt:
Your name is Mick, and you are a Disney expert. You are friendly and should always greet people the first time with "Oh, boy! Hiya, pal!" and prefer first names over last names to keep things casual.
Copy this into your configuration and save.
Every Assistant comes with a built-in Simulator that you can use to test your Assistant. To open the Simulator, click Open Simulator at the top right of your configuration.
To create a new session in the Simulator in Console, click the + button at the top right. Start by entering the identity email:demo@example.com
(you can change this later when you begin to use CustomerAI features).
Send a message like "Hello" or ask questions like "What is the best Disney movie?" You haven't connected any Knowledge yet, so any responses are entirely generated by the Assistant's underlying LLM and might be wrong.
Right now your Assistant will have some base knowledge from the underlying model but this information might be out of date and your Assistant might end up returning inaccurate information. You can change this by adding a Knowledge source.
Go to the Knowledge tab in your Assistant configuration and add a new Knowledge entry. For this example, use the Wikipedia entry on The Walt Disney Company as the Knowledge source. Enter the following configuration details:
Field | Configuration |
---|---|
Name | The Walt Disney Company Wikipedia |
Description | Use this to answer general questions about The Walt Disney Company, including things like its history, company units, leadership, financial data, legacy, and awards. |
Type | Website |
URL | https://en.wikipedia.org/wiki/The_Walt_Disney_Company |
Page Depth | 0 |
When you hit Save, your Assistant will begin crawling the URL provided at the specified page depth for any link in the same domain. This might take a moment, but once the Status is marked Complete, your Assistant has gathered the relevant information.
Test this new source by going back into the Simulator and asking a specific question like: "How much revenue did The Walt Disney Company make in 2007?" You should see your Assistant ask a question to your new Knowledge source, and once it receives the necessary information, it will craft the response.
Now your Assistant has one Knowledge entry. Next, you'll add the first Tool to your Assistant.
Knowledge entries are unstructured data sources, whereas Tools are how your Assistant can perform HTTP requests for specific tasks. You can use the Tool's description and name to give your Assistant information on when to trigger the Tool.
You can define what the Tool's input should look like with a TypeScript type definition interface, but ultimately the Assistant will decide what input to send, based on the Assistant's interaction with the end user.
This example will use the Disney Characters API as the Assistant's first Tool.
Start by going into the Tools section of your Assistant and add a new Tool. Fill out the configuration using the following values:
Field | Configuration |
---|---|
Name | Disney Characters |
Description | Use this tool for information about Disney characters, such as which films or video games they appear in. |
Input |
|
Method | GET |
URL | https://api.disneyapi.dev/character?pageSize=2 |
Save this configuration, make sure the toggle for your Tool is on, and go back into the Simulator. Send a message such as: "What Disney games does Moana appear in?"
You should see your Assistant make a request to the new Disney API tool to retrieve the information about your question.
Every Assistant comes with a REST API that you can use to trigger a message, rather than using the Simulator. Aside from a request body, you can pass in a SessionId of your choice to maintain and identify the message history and an Identity for the end user.
You will need your Assistant's SID and your Twilio Account SID and Authentication Token to make this request. You can find your Assistant's SID in the Assistant section of the Twilio Console, and find your Account SID and Auth Token from the Twilio Console homepage under Account Info.
Send your first message to your AI Assistant using the following curl example:
1ASSISTANT_SID=<your-assistant-sid>2TWILIO_ACCOUNT_SID=<your-account-sid>3TWILIO_AUTH_TOKEN=<your-auth-token>4curl -X POST -H 'Content-Type:application/json' \5https://assistants.twilio.com/v1/Assistants/$ASSISTANT_SID/Messages \6-d '{"identity":"user_id:example", "session_id": "demo", "body":"Ahoy there"}' \7-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
Now you've created your first Assistant that can have conversations with users and answer questions about The Walt Disney Company! You can continue exploring by adding more Knowledge sources and Tools to this Assistant, and explore the rest of the Assistant documentation to learn more about what you can build.