Declaring one
const agent = api.agents.create({
runtime: "local", machine: pc, model: "gemini-3.5-flash",
customTools: {
open_ticket: {
description: "Open a ticket in our tracker. Returns its number and URL.",
category: "write",
parameters: {
title: { type: "string", required: true },
body: { type: "string" },
labels: { type: "array", items: { type: "string" } },
},
async run({ title, body, labels }, { signal }) {
const ticket = await tracker.create({ title, body, labels }, { signal });
return { output: `Opened #${ticket.number}: ${ticket.url}`, summary: `#${ticket.number}`, meta: { url: ticket.url } };
},
},
},
});def open_ticket(args):
ticket = tracker.create(title=args["title"], body=args.get("body"), labels=args.get("labels") or [])
return {"output": f"Opened #{ticket.number}: {ticket.url}"}
agent = api.agents.create(
runtime="local", machine=pc, model="gemini-3.5-flash",
tools={
"open_ticket": {
"description": "Open a ticket in our tracker. Returns its number and URL.",
"category": "write",
"parameters": {
"type": "object",
"properties": {
"title": {"type": "string"},
"body": {"type": "string"},
"labels": {"type": "array", "items": {"type": "string"}},
},
"required": ["title"],
},
"run": open_ticket,
},
},
)descriptionstringrequiredAll the model knows about the tool. An empty one is refused.
runfunctionrequired(args, { signal }) => string | { output, summary?, meta? }.
categorystringwriteread · write · storage · exec.
parametersobject{}What the model may send, in the same shape the built-in tools use.
The category is a real decision
| Choose | When | Consequence |
|---|---|---|
| read | It only looks | Never asked, and runs in parallel with other reads |
write | It changes something recoverable | Asked in ask, free in auto |
storage | It changes something with no undo | Asked even in auto, « always » per target |
| exec | It runs something arbitrary | Asked in everything but full |
It is never asked and runs in parallel. A tool that sends, publishes or spends must not be declared read — and the three always-asked categories are not available to custom tools, so anything of that kind belongs in your own code, before the run.
Names
Lowercase letters, digits and underscores, starting with a letter. A name belonging to a built-in tool — including skill and task — is refused with invalid_custom_tool rather than shadowing it.
What run may return
| Returned | Becomes |
|---|---|
| A string | The output. No summary. |
{ output } | The output. Anything that is not a string is serialised as JSON. |
{ output, summary } | Plus the line shown on tool_end. |
{ output, summary, meta } | Plus whatever you want your interface to have. |
Throwing is fine: it becomes a failed tool result with your message, and the model adapts. The signal fires when the run is stopped — honour it on anything slow.
They cost tokens, every turn
A declaration is sent with every turn, so each custom tool adds to every step's bill. Declare what this run may actually call, not everything your application can do.