AI functions
AI functions define how a Squid AI agents should handle certain queries.
When configuring your AI agents or AI assistant, you might find that certain questions require specific responses that are difficult to configure through instructions. For example, you might have industry-specific formulas that the model isn't familiar with. Or you may have customer questions that require a very specific wording in response. In these cases, you can incorporate this functionality through a Squid Service function with the @aiFunction
decorator. You can add these functions upon creation of the assistant, allowing you to customize each assistant with the functionality it requires.
AI functions take a description
parameter, which is a string describing the function. This description is how the AI agent determines when to use the function, so ensure the description is clear and informative.
The following example uses the @aiFunction
decorator to define a function that an AI agent can use:
import { SquidService, aiFunction } from '@squidcloud/backend';
class AiService extends SquidService {
@aiFunction<{ shipName: string }>(
'This function returns the list of pirates in a ship',
[
{
name: 'shipName',
description: 'The name of the ship',
type: 'string',
required: true,
}
]
)
async listPiratesInAShip(params: { shipName: string }): Promise<string> {
const { shipName } = params;
if (shipName === 'Black Pearl' {
return 'Jack Sparrow';
})
if (shipName === "Queen Anne's Revenge") {
return 'Black Beard';
}
return 'No ship found';
}
}
To add the function to an AI agent, pass the function name with a call to chat
or ask
:
const response = await squid.ai().chatbot('INTEGRAITON_ID').profile('PROFILE_ID').ask('Which pirate was captain of the Black Pearl?', { functions: ['listPiratesInAShip']});
const assistantId = await createAssistant(
'YOUR_ASSISTANT_NAME',
"YOUR ASSISTANT'S INSTRUCTIONS",
['listPiratesInAShip']
);
You can find out more about configuring AI assitants in the Squid AI assistant documentaiton