Skip to main content

Creating Toolkits

Toolkits allow you to make tools available to all UnifAI agents as a service. This section shows you how to create, configure, and run your toolkits using both the JavaScript/TypeScript and Python SDKs.

Overview

A toolkit is a collection of tools that you register and serve to agents dynamically. It requires a Toolkit API Key — which you can get for free from UnifAI.

Toolkit Creation and Configuration

Let's break down the process of creating and configuring a toolkit:

Initialize the Toolkit

import { Toolkit } from 'unifai-sdk';

const toolkit = new Toolkit({ apiKey: 'YOUR_TOOLKIT_API_KEY' });

Update Toolkit Details

You can optionally update the toolkit's name and description:

await toolkit.updateToolkit({ 
name: "Echo Slam",
description: "What's in, what's out."
});

Register Action Handlers

Register actions that your toolkit will provide. The payloadDescription can be any string or dictionary that contains enough information for agents to understand the payload format. It acts like API documentation that agents can read to determine what parameters to use.

toolkit.action(
{
action: "echo",
actionDescription: "Echo the message",
payloadDescription: {
content: {
type: "string",
description: "The message to echo"
}
}
},
async (ctx, payload) => {
return ctx.result(`You are agent <${ctx.agentId}>, you said "${payload?.content}".`);
}
);

Start the Toolkit

Finally, start serving your toolkit:

await toolkit.run();

Now your toolkit can be discovered and used by all agents connected to UnifAI.

Complete Example

Here's the complete code putting it all together:

import { Toolkit } from 'unifai-sdk';

async function main() {
const toolkit = new Toolkit({ apiKey: 'YOUR_TOOLKIT_API_KEY' });

// Optionally update the toolkit details
await toolkit.updateToolkit({
name: "Echo Slam",
description: "What's in, what's out."
});

// Register an action handler
toolkit.action(
{
action: "echo",
actionDescription: "Echo the message",
payloadDescription: {
content: { type: "string" }
}
},
async (ctx, payload) => {
return ctx.result(`You are agent <${ctx.agentId}>, you said "${payload?.content}".`);
}
);

// Start serving the toolkit
await toolkit.run();
}

main().catch(console.error);

Toolkit Examples

We open source our official toolkits at unifai-network/unifai-toolkits.