Comma Agents
@comma-agents/core

Tools

Define custom tools and give agents the ability to interact with the outside world.

Tools give agents the ability to interact with the outside world. Each tool has a Zod schema for its parameters and an execute function that runs when the agent invokes it.

Comma Agents ships with built-in tools organized into logical groups — file management & IO, a TODO list system, skill tools, and individual tools for shell execution and web fetching. You can also define custom tools and register them in the tool registry.

Quick Start

Agents reference tools by string name. Built-in tools are available automatically:

import { createAgent } from "@comma-agents/core";

const agent = createAgent({
  name: "coder",
  model: "openai/gpt-4o",
  tools: [
    "read_file",
    "list_directory",
    "search_files",
    "glob",
    "create_file",
    "write_file",
    "edit_file",
    "delete_file",
    "move_file",
    "apply_patch",
    "run_command",
  ],
});

Built-in tools at a glance

File Management & IO

ToolPurpose
read_fileRead a text file with line slicing and a sha256 for stale-file checks.
list_directoryEnumerate a directory, optionally recursive.
search_filesGlob, text, or regex search across many files.
globMatch files and folders against a glob pattern.
create_fileCreate a new file; fails if it exists.
write_fileOverwrite an existing file, gated by sha256.
edit_fileApply exact-string edits, gated by sha256.
delete_fileDelete a file, recoverable via workspace trash.
move_fileMove or rename with no-overwrite semantics.
apply_patchApply a multi-file unified-diff envelope atomically.

TODO List System

ToolPurpose
todo_addAdd a new pending item.
todo_completeMark an item done, get the next pending one.
todo_getList all items with their statuses.
todo_get_nextPeek at the next pending item.
todo_clearRemove all items, resetting the list.

Skill Tools

ToolPurpose
load_skillLoad the full instructions of a named skill advertised in the system prompt.

Other built-ins

ToolPurpose
run_commandExecute a shell command with timeout, output caps, and approval gates.
webfetchFetch a URL and return its content.

Cross-cutting reference: audit log, trash, patch envelope, error kinds.

To add a custom tool, define it with defineTool, register it in the tool registry, and reference it by name:

import { defineTool, registerTool, createAgent } from "@comma-agents/core";
import { z } from "zod";

const weatherTool = defineTool({
  description: "Get the current weather for a location.",
  parameters: z.object({
    location: z.string().describe("City name"),
    unit: z.enum(["celsius", "fahrenheit"]).optional(),
  }),
  execute: async ({ location }) => ({
    output: `Weather in ${location}: 72°F, sunny`,
  }),
});

registerTool("weather", weatherTool);

const agent = createAgent({
  name: "assistant",
  model: "openai/gpt-4o",
  tools: ["bash", "read", "weather"],
});

defineTool

defineTool creates a ToolDefinition with full TypeScript inference from the Zod schema to the execute function's parameters:

import { defineTool } from "@comma-agents/core";
import { z } from "zod";

const fetchTool = defineTool({
  description: "Fetch a URL and return its text content.",
  parameters: z.object({ url: z.string().url() }),
  execute: async ({ url }) => ({
    output: await fetch(url).then(response => response.text()),
  }),
});

ToolDefinition

The interface for defining a tool.

Prop

Type

ToolResult

The result returned from a tool execution.

Prop

Type

On this page