DigitalOcean GenAI Platform lets you build GPU-powered AI agents with fully-managed deployment. Agents can use pre-built or custom foundation models, incorporate function and agent routes, and implement RAG pipelines with knowledge bases.
Large language models often require additional functionalities to complete complex tasks. For example, a travel agent may need to retrieve the latest flight prices, hotel rates, tour packages, and available transportation.
Functions are blocks of code that you can call in your agent to enable the foundation model to access external data sources, APIs, and databases to gather information and perform specific actions on demand. Thus, your agent can get real-time, third-party information that may not be present in a static knowledge base and can go beyond static, pre-programmed responses to engage with users in a dynamic, information-rich dialog.
In addition to the function, we charge for tokens the agent uses to determine:
Whether the user question needs to be routed to a function.
Which functions and in what order they are required.
You need to first create a function using DigitalOcean Functions that meets the following requirements:
The function must be a web function.
All data types in your schema must be either a string
, boolean
, or a number
.
The function’s response must be in a body
key as shown below:
...
return {
body: {<function response>}
}
...
Private functions require a secure web function for authentication. When enabled, we apply the function’s password and restrict access to secure mechanisms. We recommend enabling this setting to protect your function from unauthorized access.
We also recommend using Node.js 18 with a 128 MB memory limit and Python 3.9 with a 256 MB memory limit for optimal cold start performance (when the function’s code is downloaded and the execution environment set up). For more information on function runtimes and memory limits, see Configure Functions.
To get weather data, you can create a function in JavaScript using the following code:
import axios from 'axios';
async function main(args) {
const zipCode = args.zipCode || '';
const measurement = args.measurement || 'F';
try {
const response = await axios.get(`https://your-api.com/weather/${zipCode}`, {
params: { measurement }
});
const { temperature = 0.0, conditions = 'Unknown' } = response.data;
return {
body: {
temperature,
conditions,
measurement
}
};
} catch (error) {
console.error("Error fetching weather data:", error);
return {
body: {
temperature: 0.0,
conditions: "Unknown",
measurement
}
};
}
}
export default main;
Adding a function route using the DigitalOcean API requires the unique identifier of the agent and one or more functions to route to. You also need to provide a name and namespace of the function, instructions on when the agent should call the function, and types of data that the function expects as input and output schema.
To obtain a list of agents with their unique identifiers, use the /v2/gen-ai/agents
endpoint. You can get the namespace for your function in the Namespace Info section in the Settings tab of your function.
To view function routes for an agent, use the /v2/gen-ai/agents/{uuid}/child_agents
endpoint.
To call the function in the agent from the control panel, click GenAI Platform from the left menu and then click on the agent you want to add a function route. In the Resources tab, scroll to the Function Route section, and click Add function route to open the Add a function route page.
In the Define the function section, specify the following:
Namespace: Select the namespace for your function from the Namespace drop-down list.
Function: Select the function name, for example get-weather
, from the Select function drop-down list.
Function instructions: Specify when the agent should call the function in the text box. For example, you can enter something like Call this function when asked about the weather for a zip code
.
Next, define the input and output schema that the agent accepts. The schema provides a detailed description of the inputs, outputs, and the logic required for the agent to call and use these functions:
Input schema: Specifies the types of data that the function expects as inputs.
In the Define input schema section, specify the input schema parameters. For the get-weather
function example, add these parameters in the format as shown:
{
"zipCode": {
"type": "string",
"required": true,
"description": "The ZIP code for which to fetch the weather"
},
"measurement": {
"type": "string",
"required": false,
"description": "The measurement unit for temperature (F or C)"
}
}
Output schema (optional): Specifies the data structure a function returns, helping the agent interpret and use the output. While an input schema and function description work for standalone functions, an output schema helps when functions depend on each other. It shows the agent where data comes from and how it flows through multiple functions. This improves accuracy, especially for complex data structures.
For example, two functions can get the weather for a location: get-zip-code
and get-weather
. If get-weather
needs a zip code, the function routing starts with get-zip-code
, which then routes to get-weather
. get-weather
retrieves the weather data and passes it to the agent to display or use.
In the Define output schema section, specify the output schema parameters. For the get-weather
function example, you should add these parameters in the format as shown:
{
"temperature": {
"description": "The temperature for the specified location",
"type": "number"
},
"measurement": {
"description": "The measurement unit used for the temperature (F or C)",
"type": "string"
},
"conditions": {
"description": "A description of the current weather conditions (Sunny, Cloudy, etc)",
"type": "string"
}
}
In the Function route name field, enter a name for the function route and then click Add Function.
Next, you can test the agent in the Agent Playground and then use your agent in a chat bot or embed it in your application.