Tools

Give the agent small, typed functions it can call.

A tool lets the agent ask your app to do one specific task. Define its input with Zod and put the work in run.

import { defineTool } from "@agentdock-ai/agentdock";
import { z } from "zod";

const lookupOrder = defineTool({
  name: "lookup_order",
  description: "Find an order by its ID.",
  input: z.object({ orderId: z.string() }),
  run: async ({ orderId }, ctx, signal) => {
    return findOrder(orderId, ctx.userId, signal);
  },
});

run receives the validated input, the JSON context passed to the run, and an abort signal. It can also receive a progress callback and tool-call ID as its fourth and fifth arguments.

Add tools to the agent

Register the typed tool on the single AgentDock instance:

const agent = new AgentDock({ model });
agent.registerTool(lookupOrder);

Register additional tools with registerTool() or registerTools().

Validate input

defineTool() turns the Zod object into a schema for the model and checks tool input before run executes. Keep each tool focused and return JSON data.

Protect side effects

Set requiresApproval: true for actions such as publishing, sending, or deleting. The agent will pause for a decision. See approvals.

For an advanced tool, new AgentDock() also accepts a raw JSON Schema. It must have an object root. Zod with defineTool() is the recommended path.

On this page