Build custom AI agents
Squid allows you to add persistent instructions and context to create custom AI agents tailored to a specific use case, allowing for feature-rich automated workflows.
Benefits
AI Agents provide a streamlined way to create AI solutions ranging from a single conversational chatbot that answers questions about your product all the way to robust workflows and systems with multiple layers and actions.
Use cases
Create embedded workflows that are kicked off from a single client query. A customer message like "I need to transfer my service" can be classified and then passed to the appropriate agent in the workflow. From there, another Squid AI agent can consult with internal private resources like those pertaining to transfer procedures, and then pass its responses to another AI agent or back to the customer as needed. These workflows can be as simple or complex as required to suit your unique use case.
How it works
Under the hood, agents use a Large Language Model (LLM) to generate answers to users' questions. When a user asks a question, the persistent instructions and most relevant context are passed to the LLM as part of the prompt, providing the user with a contextualized answer.
Squid lets you choose the LLM for your AI agent, allowing you to find the best fit for your use case.
The following LLMs are currently available:
- OpenAI GPT-3.5, GPT-4, GPT-4 Turbo, GPT-4o
- Gemini Pro
- Anthropic Claude 3 Opus, Claude 3 Sonnet, Claude 3.5 Sonnet, Claude 3 Haiku
Do you need a specific model that is not currently supported? Please reach out to us to discuss your needs!
Squid provides two straightforward methods to create AI agents, add or update chat instructions, and add or update context: through the Squid Console or programmatically using the Squid Client SDK. And with Squid's powerful Backend SDK, you can secure your AI agents however you need to for your use case so you can be sure only the right information goes to the right place.
squid
.ai()
.agent('AGENT_ID')
.chat('How do I use Squid AI agents?')
.subscribe((response: string) => {
// The 'response' will be built incrementally as tokens are received from OpenAI.
});
Accessing agents
To use Squid AI agent, select the AI Agents tab in the Squid Console.
Building an agent
An agent represents a distinct personality or setup for your AI workflow. Each agent is like a different persona or use case, distinguished by its own set of instructions and context. This design enables customized responses from the AI according to the specific agent.
Agents can be constructed either through the Squid Console or through the Squid Client SDK.
The following examples show how to create an agent using the Client SDK. However, the Console provides a robust UI for creating agents and adding and removing instructions or context on an agent. If you're not dynamically creating agents or adding context, this UI is all you need to successfully create an AI agent.
Adding an agent
To add a Squid AI agent programmatically, use the Squid Client SDK's .agent()
method to access an agent:
await squid.ai().agent('banking-copilot').insert({
modelName: 'gpt-4',
isPublic: true,
});
When inserting an agent, you pass an object with a modelName
field indicating the model the agent will use.
isPublic
determines whether the chat functionality of the given agent can be accessed without setting up security rules.
Note that the insert
method results in an error if an agent already exists with the same agent ID.
Updating an agent
To update an existing agent, use the update()
method, passing the agent data you want to change:
await squid.ai().agent('banking-copilot').update({
isPublic: false,
});
Deleting an agent
To delete an existing agent, use the delete()
method:
await squid.ai().agent('banking-copilot').delete();
Note that this function results in an error if no agent exists for the provided agent ID.
Instructions
Instructions set the rules for how the agent responds to prompts and answers questions. They should be direct and simple, and explain the purpose of the agent. Instructions are supplied as a block of text.
When generating a reference to an instruction, you can provide an instruction ID, or one can be automatically generated.
The following example provides an instruction ID of 'knowledge-base'
:
const instruction = await squid
.ai()
.agent('banking-copilot')
.instruction('knowledge-base'); // uses the 'knowledge-base' instruction ID
The following example does not provide an instruction ID, so one is randomly generated:
const instruction = await squid.ai().agent('banking-copilot').instruction(); // uses a new randomly-generated instruction ID
Providing an instruction ID allows you to more easily access instructions later for when you want to make changes. For randomly generated IDs, it is recommended that you save the ID for future reference.
Adding instructions
To add a new instruction entry to an AI agent, use the instruction().insert()
method, passing the instruction data as an object.
const instruction =
'You are a helpful copilot that assists customer support staff by providing answers to their questions about banking and finance products.';
await squid
.ai()
.agent('banking-copilot')
.instruction('knowledge-base')
.insert({ instruction });
Note that this function results in an error if an entry exists with the same ID. For example, if the agent shown here already had an instruction with a key of 'knowledge-base'
, this would result in an error. To update instructions, use the update()
method shown in following example.
Updating instructions
To update an existing agent instruction, use the update()
method:
const instruction =
'You are a helpful copilot that assists customer support staff by providing answers to their questions about banking and finance products. If asked about something other than banking or finance products, respond letting the user know that you can't answer that.';
await squid
.ai()
.agent('banking-copilot')
.instruction('knowledge-base')
.update({ instruction });
Deleting instructions
To delete an existing instruction, use the delete()
method:
const instruction =
'You are a helpful copilot that assists customer support staff by providing answers to their questions about banking and finance products.';
await squid.ai().agent('banking-copilot').instruction('knowledge-base').delete();
Note that this function results in an error if no instruction exists for the provided instruction ID.
Context
Context tells the agent what knowledge to pull from when answering questions. Adding context allows the agent to provide relevant answers on specific topics that may not be part of the underlying AI model.
When generating a reference to context, you can provide a context ID, or one can be automatically generated.
The following example provides a context ID of 'credit-cards'
:
const context = await squid.ai().agent('banking-copilot').context('credit-cards');
The following example randomly generates a context ID:
const context = await squid.ai().agent('banking-copilot').context();
Adding context
To add new context to an agent, use the insert()
method, passing the context:
const data = `Platinum Mastercard® Fair Credit, No annual fee. Flexible due dates...`;
await squid
.ai()
.agent('banking-copilot')
.insert({ title: 'credit-cards', context: { type: 'text', data } });
Two types of contexts are supported:
The text
context type
Text context is created with a string that contains the context:
const data = `Platinum Mastercard® Fair Credit, No annual fee. Flexible due dates...`;
await squid
.ai()
.agent('banking-copilot')
.context()
.insert({ title: 'credit-cards', context: { type: 'text', data } });
The url
context type
URL context is created by providing a URL to be scraped for context. Currently only content on that specified page will be scraped. If you want to create context for multiple pages on a site, they will each need their own context entry.
const data = `https://www.capitalone.com/credit-cards/compare`;
await squid
.ai()
.agent('banking-copilot')
.context()
.insert({ title: 'credit-cards', context: { type: 'url', data } });
URL context is static, meaning it is not automatically refreshed with website updates. To ensure your AI agent's context is up to date, you need to re-add the URL context when the content of the website changes. Automatic context refreshes are coming to Squid in the future.
Updating context
To update context, use the update()
method:
const data = `https://www.bankofamerica.com/credit-cards/`;
await squid
.ai()
.agent('banking-copilot')
.context('credit-cards')
.update({ title: 'credit-cards', context: { type: 'url', data } });
Note that this method results in an error if an entry has not yet been created for the current context ID.
Deleting context
To delete a context entry, use the delete()
method:
await squid.ai().agent('banking-copilot').context('credit-cards').delete();
Note that this method results in an error if an entry has not yet been created for the current context ID.
While these are simple examples, the context you add can be much more complex. Some good examples of context include resources like code documentation, product manuals, business operations (e.g., store hours) and user-specific data. You can mix and match url
and text
contexts to create a robust knowledge base for your AI agent, ensuring they can provide any information your users will need.
Your context can be as long as you like, however since there are character limits to LLM prompts, only a portion of your context may actually be included alongside the user's inquiry. When constructing a prompt, Squid decides which portions of the supplied context are most relevant to the user's question.
Context metadata
When adding or updating the context of an AI agent, you can optionally provide context metadata. Metadata is an object where keys can have a type of string, number, or boolean. Adding metadata provides additional information about the context that can then be used when chatting. The following example shows adding a PDF as context and providing two key/value pairs as metadata:
const data = {
blob: contextBlob,
fileName: 'CreditCardList.pdf',
};
await squid
.ai()
.agent('banking-copilot')
.context()
.insert({
title: 'BofA Credit Cards',
context: { type: 'file', data },
metadata: {
company: 'Bank of America',
},
});
You can then use metadata when chatting with your AI agent, as shown in the Filtering context with metadata section.
Chatting
Once an agent has been created, you're ready to start asking questions or giving prompts. Use the chat()
method on the desired AI agent.
await squid
.ai()
.agent('banking-copilot')
.chat('Which credit card is best for students?')
.subscribe((response) => {
// The best credit card for students is ...
});
Because tokens are streamed incrementally, the chat()
method returns an RxJs Observable which allows you to subscribe to the current response as tokens arrive on the client.
To receive the final response as a Promise, use the lastValueFrom
function in RxJs:
import { lastValueFrom } from 'rxjs';
const response = await lastValueFrom(
squid.ai().agent('banking-copilot').chat('Which credit card is best for students?')
);
Chat options
In addition to a prompt, the chat
function can accept an optional options
parameter. This parameter provides various properties for configuring the AI agent. To view a full list of available options and their default values, refer to the API reference documentation.
await squid
.ai()
.agent('banking-copilot')
.chat('Which credit card is best for students?', {
chatId: 'my-chat',
maxTokens: 4096,
disableHistory: true,
/* ... */
})
.subscribe(/* ... */);
By default, chats support conversational history. The history is tied to the user's current session, and is reset upon page reload.
Filtering context with metadata
When you have added metadata to your context, you can use the contextMetadataFilter
chat option to instruct the AI agent to only consult specific contexts. Only contexts that meet the filter requirement will be used to respond to the client prompt.
The following example filters contexts to only include those with a metadata value of "company"
that is equal to "Bank of America"
:
await squid
.ai()
.agent('banking-copilot')
.chat('Which credit card is best for students?', {
contextMetadataFilter: { company: { $eq: 'Bank of America' } }, // filter context using metadata
/* ... */
})
.subscribe(/* ... */);
The following metadata filters are supported:
Filter | Description | Supported types |
---|---|---|
$eq | Matches vectors with metadata values that are equal to a specified value | number, string, boolean |
$ne | Matches vectors with metadata values that are not equal to a specified value | number, string, boolean |
$gt | Matches vectors with metadata values that are greater than a specified value | number |
$gte | Matches vectors with metadata values that are greater than or equal to a specified value | number |
$lt | Matches vectors with metadata values that are less than a specified value | number |
$lte | Matches vectors with metadata values that are less than or equal to a specified value | number |
$in | Matches vectors with metadata values that are in a specified array | string, number |
$nin | Matches vectors with metadata values that are not in a specified array | string, number |
$exists | Matches vectors with the specified metadata field | boolean |
Adding images as context
When chatting, you can optionally provide an array of files as context. This feature is only available when using GPT-4 Turbo.
The following example includes the fileUrls
property in the options parameter to ask a question about an image:
const response = await squid
.ai()
.agent('banking-copilot')
.ask('Which credit card is this?', {
fileUrls: [
{
type: 'image',
url: 'https://ecm.capitalone.com/WCM/card/background-images/cchp/cchp-verge-desktop.jpg',
},
],
});
console.log(response);
/*
"That's a Venture X card from Capital One."
*/
Currently, 'image'
is the only supported AiFileUrlType
that can be passed to the AI agent.
AI functions
The Squid AI Agent can handle specific use cases or create more consistent responses using AI functions. Here are some common scenarios that use this functionality:
- Add specific messaging for user questions. For example, when a change is made to the company or product that users will likely ask about, you can provide a consistent suitable response.
- Run industry-specific formulas that LLMs won't know or consistently apply.
- Run data queries or API calls that provide information the AI agent uses in its response.
To use AI functions during chat, pass the AI function names as an array to the functions
attribute of the options
parameter:
const response = await squid
.ai()
.agent('banking-copilot')
.ask('What is my current credit limit?', {
functions: ['AI_FUNCTION_NAME_1', 'AI_FUNCTION_NAME_2'],
});
To learn more about AI functions, view the documentation. To see an example application that uses AI functions, check out this AI agent tutorial.
Securing your data
Securing your data is vital when using the Squid Client SDK to create agents and enable chatting. The AI agent and the chats conducted with them may contain sensitive information, so it's crucial to restrict access and updates to prevent unauthorized usage or modification.
To learn about securing your AI agent, check out the Securing the Squid AI Agent documentation.