Home
Build tools
Create a toolkit

Creating a Toolkit

In this guide, we'll walk through the process of creating a custom toolkit for Arcade AI.

You'll create a simple arithmetic toolkit with operations like addition, subtraction, multiplication, and more.

Prerequisites

pip install arcade-ai

Create a new toolkit

Use arcade new to create a new toolkit:

arcade new

Define your tools

Create a Python file for your tools, e.g., arithmetic.py, in the arcade_<toolkit_name>/tools directory of your new toolkit and import the necessary modules:

from typing import Annotated
from arcade.sdk import tool

Now, define your tools using the @tool decorator:

@tool
def add(
    a: Annotated[int, "The first number"],
    b: Annotated[int, "The second number"]
) -> Annotated[int, "The sum of the two numbers"]:
    """
    Add two numbers together
    """
    return a + b
 
@tool
def subtract(
    a: Annotated[int, "The first number"],
    b: Annotated[int, "The second number"]
) -> Annotated[int, "The difference of the two numbers"]:
    """
    Subtract two numbers
    """
    return a - b
 
@tool
def multiply(
    a: Annotated[int, "The first number"],
    b: Annotated[int, "The second number"]
) -> Annotated[int, "The product of the two numbers"]:
    """
    Multiply two numbers together
    """
    return a * b
 
@tool
def divide(
    a: Annotated[int, "The numerator"],
    b: Annotated[int, "The denominator"]
) -> Annotated[float, "The quotient of the two numbers"]:
    """
    Divide two numbers
    """
    return a / b

Register your tools

To register your tools locally, you can run pip install them and test them in arcade dev

Navigate to the directory created by arcade new (with the pyproject.toml file) and run:

pip install .

This will load the tool into the local actor environment.

You can run the Engine and Actor to test your new tool with:

arcade dev

See the Local Installation Guide for setting up arcade dev if you have not done so already.

Use your tools with Arcade

Now you can use your custom tools with Arcade AI in your application.

Here's an example of how to use your tools:

from arcadepy import Arcade
 
client = Arcade(base_url="http://localhost:9099")
 
# Use the tools in a chat completion
response = client.chat.completions.create(
    messages=[{"role": "user", "content": "What is 6 times 7?"}],
    model="gpt-4o",
    tool_choice="generate",
)
 
print(response.choices[0].message.content)

How it works

By decorating your functions with @tool, you expose them to the Arcade AI platform.

The Annotated types and docstrings provide metadata that helps the AI understand how to use your tools.

Next steps

Try adding more tools to your toolkit, such as sqrt, sum_list, or sum_range.

Explore advanced features like tool authorization and evaluation to enhance your tools.