Skip to main content
Core

Custom Tools

Give an agent tools that run in your backend, with access to your APIs and secrets.

A custom tool is a function the model can call. It runs in the agent Actor on your worker, next to your server code, so it can use your APIs and secrets. This page adds a tool to the Quickstart agent.

YOUR BACKENDModelAgent Actorruns get_orderOrders APIget_orderresultAPI token

The model reads the tool’s description and calls it with arguments that match parameters. It reads content as the result, while details goes to clients for your UI. A thrown error, like the 404 in fetchOrder, becomes an error result: the model reads the message and can try something else. signal aborts when the run is cancelled, so a Stop from the client also cancels the request.

Secrets

fetchOrder reads ORDERS_API_TOKEN from the worker’s environment, so the token never leaves your backend:

Sees the token
Your tool codeYes, from process.env on the worker.
The modelNo. It sees the tool’s name, description, parameters, and results.
The session and connected clientsNo. They store and receive tool arguments and results.
The sandboxNo. Commands run with the sandbox’s own environment.

Tool results and error messages are stored in the session and sent to every connected client, so keep secrets out of both. Model keys work differently. See API Keys.

The agent keeps its sandbox, so the model can call get_order next to the built-in tools. Custom tools also work without a sandbox.

Next: Design Patterns, how to combine agents with other Actors.