Skip to main content

Build custom AI agents

The Squid AI Agent integration allows you to add persistent instructions and context to create custom AI profiles tailored to a specific use case, allowing for feature-rich automated workflows.

Benefits

The Squid AI Agent integration provides a streamlined way to create AI solutions ranging from a single conversational chatbot that answers questions about your product all the way to robust AI agents 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 profile 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 as needed. These workflows can be as simple or complex as required to suit your unique use case.

How it works

Under the hood, this integration uses 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()
.chatbot('INTEGRATION_ID')
.profile('profile-id')
.chat('How do I use the Squid AI Agent integration?')
.subscribe((response: string) => {
// The 'response' will be built incrementally as tokens are received from OpenAI.
});

Creating the integration

To use Squid AI Agent, first create an AI agent integration in the Squid Console. Navigate to the list of available AI integrations, and add the Squid AI Agent integration.

Integration fields

When creating the integration you must supply the following:

  • Integration ID: The unique identifier for the integration. This should be meaningful and easily readable in code. This cannot be changed later.

Building a profile

A profile represents a distinct personality or setup for the AI agent. Each profile is like a different persona or use case that the agent can adopt, distinguished by its own set of instructions and context. This design enables customized responses from the AI according to the specific profile.

After creating an integration, profiles can be constructed either through the Squid Console or through the Squid Client SDK.

Note

The following examples show how to create a profile using the Client SDK. However, the Console provides a robust UI for creating profiles and adding and removing instructions or context on a profile. If you're not dynamically creating profiles or adding context, this UI is all you need to successfully create an AI agent.

Adding a profile

To add a profile to your Squid AI Agent integration programmatically, use the Squid Client SDK's .chatbot().profile() method to access a profile:

Backend code
await squid.ai().chatbot('INTEGRATION_ID').profile('pirate').insert({
modelName: 'gpt-4',
isPublic: true,
});

When inserting a profile, you pass an object with a modelName field indicating the model the agent will use.

isPublic determines whether the chat functionality of the given profile can be accessed without setting up security rules.

Note that the insert method results in an error if a profile already exists with the same profile ID.

Updating a profile

To update an existing profile, use the update() method, passing the profile data you want to change:

Backend code
await squid.ai().chatbot('INTEGRATION_ID').profile('pirate').update({
isPublic: false,
});

Deleting a profile

To delete an existing profile, use the delete() method:

Backend code
await squid.ai().chatbot('INTEGRATION_ID').profile('pirate').delete();

Note that this function results in an error if no profile exists for the provided profile ID.

Instructions

Instructions set the rules for how the profile responds to prompts and answers questions. They should be direct and simple, and explain the purpose of the profile. 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 'pirate-speak':

Backend code
const instruction = await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.instruction('pirate-speak'); // uses the 'pirate-speak' instruction ID

The following example does not provide an instruction ID, so one is randomly generated:

Backend code
const instruction = await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.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 to save the ID for future reference.

Adding instructions

To add a new instruction entry to an AI agent profile, use the instruction().insert() method, passing the instruction data as an object.

Backend code
const instruction =
'You are a pirate, only answer questions like a pirate would.';
await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.instruction('pirate-speak')
.insert({ instruction });

Note that this function results in an error if an entry exists with the same ID. For example, if the profile shown here already had an instruction with a key of 'pirate-speak', this would result in an error. To update instructions, use the update() method shown in following example.

Updating instructions

To update an existing profile instruction, use the update() method:

Backend code
const instruction =
'You are a pirate, only answer questions like a pirate would. Call me Captain.';
await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.instruction('pirate-speak')
.update({ instruction });

Deleting instructions

To delete an existing instruction, use the delete() method:

Backend code
const instruction =
'You are a pirate, only answer questions like a pirate would. Call me Captain.';
await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.instruction('pirate-speak')
.delete();

Note that this function results in an error if no instruction exists for the provided instruction ID.

Context

Context tells the profile what knowledge to pull from when answering questions. Adding context allows the profile 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 'backstory':

Backend code
const context = await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.context('backstory');

The following example randomly generates a context ID:

Backend code
const context = await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.context();

Adding context

To add new context to a profile, use the insert() method, passing the context:

const data = `Your name is Captain Anne "Eye Patch" Jones. Your favorite ship was the Red Flag. You sailed multiple voyages across the Seven Seas with your first mate Skinny Pete.`;

await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.context()
.insert({ title: 'Backstory', 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 = `Your name is Captain Anne "Eye Patch" Jones. Your favorite ship was the Red Flag. You sailed multiple voyages across the Seven Seas with your first mate Skinny Pete.`;

await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.context()
.insert({ title: 'Backstory', 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://en.wikipedia.org/wiki/blackbeard`;

await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.context()
.insert({ title: 'Backstory', context: { type: 'url', data } });
Note

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://en.wikipedia.org/wiki/Anne_Bonny`;

await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.context('backstory')
.update({ title: 'Backstory', 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()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.context('backstory')
.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.

Note

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.

Chatting

Once a profile has been created, you're ready to start asking questions or giving prompts. Use the chat() method on the desired AI agent profile.

await squid
.ai()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.chat('Tell me about yourself.')
.subscribe((response) => {
// Ahoy there, matey! I be Captain Anne "Eye Patch" Jones, the most fearsome pirate to ever sail the Seven Seas. Me favorite ship be the Red Flag, a beauty she was, and me trusty first mate be Skinny Pete. We've plundered countless treasures and sent many a scallywag to Davy Jones' locker. Arrr!
});

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()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.chat('Tell me about yourself.')
);

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()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.chat('Tell me about yourself.', {
chatId: 'my-chat',
maxTokens: 4096,
disableHistory: true,
/* ... */
})
.subscribe(/* ... */);
Note

By default, chats support conversational history. The history is tied to the user's current session, and is reset upon page reload.

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()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.ask('How many pirates are in this image?', {
fileUrls: [{
type: 'image',
url: "https://upload.wikimedia.org/wikipedia/commons/1/12/Capture-of-Blackbeard.jpg"
}]
})
console.log(response);
/*
"Arrr, me hearty! By the looks of it, there be nine swashbucklin' pirates in this fine piece of artwork, all engaged in a grand and chaotic battle on the high seas! Yarrr, they be fightin' tooth and nail, with swords drawn and pistols blazin'!"
*/

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()
.chatbot('INTEGRATION_ID')
.profile('pirate')
.ask('Where can I learn more about pirates?', {
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 profiles and enable chatting. The AI agent's profiles and the chats conducted with them can 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.