Skip to content

toolbox ​

ts
import { designTool, runTool } from "std::toolbox"

node main() {
  const saved = designTool(
    name: "addTax",
    purpose: "Add a tax rate to an amount.",
    request: "{ amount: number; rate: number }",
  )
  if (saved is failure) {
    return saved
  }
  return runTool("addTax", { amount: 100, rate: 0.08 })
}

Run interactively or supply handlers for the review and save requests. designTool drafts and checks a tool, then lets the user accept it or ask for changes. Use writeTool when the source is already written, and listTools to inspect saved tools.

Each tool has an impl.agency exporting Request and run. A generated tool.agency wraps it with cost and time limits. You can also import its tool export directly from the saved directory.

Types ​

Unresolved ​

A review point the drafting agent could not fix, in the reviewer's words, and the agent's reason.

ts
/** A review point the drafting agent could not fix, in the reviewer's
  words, and the agent's reason. */
export type Unresolved = {
  point: string;
  reason: string
}

(source)

ModuleFacts ​

What describe says about a tool's run function.

ts
/** What `describe` says about a tool's `run` function. */
export type ModuleFacts = {
  signature: string;
  docstring?: string;
  effects: string[]
}

(source)

ToolMeta ​

What meta.json holds: how the tool was made, and how often it ran. requestSchema is the JSON Schema of the Request type, as the tool's own requestSchema node reported it at save time; null for a tool saved before schemas were recorded.

ts
/** What meta.json holds: how the tool was made, and how often it ran.
  `requestSchema` is the JSON Schema of the Request type, as the tool's
  own `requestSchema` node reported it at save time; null for a tool
  saved before schemas were recorded. */
export type ToolMeta = {
  purpose: string;
  request: string;
  requestSchema?: Json;
  createdAt: string;
  maxTime: number;
  version: number;
  uses: number;
  lastUsedAt?: string
}

(source)

ToolEntry ​

One tool in a toolbox. This is what listTools returns. If the tool could not be read correctly, broken holds the reason.

ts
/** One tool in a toolbox. This is what `listTools` returns. If the tool
  could not be read correctly, `broken` holds the reason. */
export type ToolEntry = {
  name: string;
  dir: string;
  module: ModuleFacts;
  meta: ToolMeta;
  broken?: string
}

(source)

Effects ​

std::toolbox::scan ​

ts
@alwaysUnder(dir)
effect std::toolbox::scan {
  dir: string
}

(source)

std::toolbox::recordUse ​

ts
@alwaysUnder(dir)
effect std::toolbox::recordUse {
  dir: string;
  name: string
}

(source)

std::toolbox::writeFile ​

ts
@alwaysUnder(root)
effect std::toolbox::writeFile {
  root: string;
  dir: string;
  filename: string;
  content: string
}

(source)

std::toolbox::createStaging ​

ts
@alwaysUnder(root)
effect std::toolbox::createStaging {
  root: string;
  dir: string;
  name: string
}

(source)

std::toolbox::removeStaging ​

ts
@alwaysUnder(root)
effect std::toolbox::removeStaging {
  root: string;
  dir: string;
  name: string
}

(source)

std::toolbox::removeStagedFile ​

ts
@alwaysUnder(root)
effect std::toolbox::removeStagedFile {
  root: string;
  dir: string;
  name: string;
  filename: string
}

(source)

std::toolbox::review ​

ts
effect std::toolbox::review {
  name: string;
  stagingDir: string;
  source: string;
  /** The draft the previous round showed, or "" on the first round. The
    approval prompt diffs `source` against it, so a redraft shows what
    changed rather than the whole tool again. */
  previous: string;
  effects: string[];
  tested: boolean;
  /** Reviewer findings that do not block the draft: advice to the user
    who asked for the tool. */
  notes: string[];
  /** Reviewer findings the author was asked to fix and the reviewer
    raised again. Empty unless the draft is here because of them. */
  blocking: string[];
  /** Review points the author reported it could not fix, with its reason. */
  unresolved: Unresolved[];
  /** True when this is a draft from earlier in the session that nobody
    accepted, shown again instead of writing a new one. */
  resumed: boolean
}

(source)

std::toolbox::save ​

ts
@alwaysUnder(dir)
effect std::toolbox::save {
  dir: string;
  name: string;
  source: string;
  effects: string[]
}

(source)

Functions ​

listTools ​

ts
listTools(
  dir: string = "~/.agency-agent/tools",
): Result<ToolEntry[]> raises <std::toolbox::scan, std::ls>

List saved tools and their metadata, marking unreadable or invalid entries as broken.

Use the catalog to select a tool before calling runTool. Each entry includes its signature, tool description, effects, and saved metadata. A broken entry explains why the tool cannot be used.

Parameters:

NameTypeDefaultDescription
dirstring"~/.agency-agent/tools"Nonempty toolbox directory to scan.

Returns: Result<ToolEntry[]>

Throws: std::toolbox::scan, std::ls

Needs: fileRead

(source)

designTool ​

ts
designTool(
  name: string,
  purpose: string,
  request: string,
  dir: string = "~/.agency-agent/tools",
  maxRounds: number = 3,
  maxTime: number = 3m,
  maxCost: number = $1.00,
  model: string = "",
  provider: string = "",
  review: boolean = false,
): Result<ToolEntry>

Draft a reusable tool, revise it with the user, and save it after acceptance.

Use this when a tool still needs to be written or refined. The coding agent writes against your fixed request type. Each draft gets sandbox compilation and typechecking; pure, predictable tools also get generated tests. Set review: true to add a review agent before those checks.

The user can accept the draft or give text feedback for another round. Acceptance still requires the save approval shared with writeTool. An unfinished draft stays available during the session for the same name, request type, and purpose.

The saved tool runs under maxTime and maxCost. These limits apply to future calls of the tool, rather than the drafting process.

Parameters:

NameTypeDefaultDescription
namestringUnused camelCase name of at most 64 letters or digits, starting with a lowercase letter and excluding "staging".
purposestringWhat the tool should do, in plain language.
requeststringInput type as Agency text, such as { amount: number; rate: number }.
dirstring"~/.agency-agent/tools"Nonempty toolbox directory to write into.
maxRoundsnumber3Maximum draft and revision rounds before returning a failure.
maxTimenumber3mSaved tool's time limit in milliseconds, at most 59m30s.
maxCostnumber$1.00Saved tool's cost limit in dollars.
modelstring""Model override for drafting and review, or "" for the configured model.
providerstring""Provider for the model override.
reviewbooleanfalseHave a review agent inspect drafts before their checks when true.

Returns: Result<ToolEntry>

Throws: std::toolbox::removeStaging, std::toolbox::createStaging, std::toolbox::review, std::toolbox::save, std::toolbox::scan, std::toolbox::writeFile, std::run, std::guard, std::toolbox::removeStagedFile

Needs: fileRead, fileWrite, subprocess, terminal

(source)

writeTool ​

ts
writeTool(
  name: string,
  purpose: string,
  request: string,
  source: string,
  dir: string = "~/.agency-agent/tools",
  maxTime: number = 3m,
  maxCost: number = $1.00,
): Result<ToolEntry>

Save an already-written tool after checking its source and obtaining approval.

Use this for source you have already written and tested. It compiles and typechecks the source with a generated wrapper, shows the source and effects for save approval, and publishes the tool. It makes no model calls and generates no tests. Use designTool to draft or revise with the user.

The source must export a Request type matching request and a run(request: Request): Json function. Import Json from std::validation. The wrapper enforces maxTime and maxCost on later tool calls.

Parameters:

NameTypeDefaultDescription
namestringUnused camelCase name of at most 64 letters or digits, starting with a lowercase letter and excluding "staging".
purposestring
requeststringInput type as Agency text, matching the source's Request type.
sourcestringAgency-only module exporting Request and run(request: Request): Json.
dirstring"~/.agency-agent/tools"Nonempty toolbox directory to write into.
maxTimenumber3mSaved tool's time limit in milliseconds, at most 59m30s.
maxCostnumber$1.00Saved tool's cost limit in dollars.

Returns: Result<ToolEntry>

Throws: std::toolbox::removeStaging, std::toolbox::createStaging, std::toolbox::save, std::toolbox::scan, std::toolbox::writeFile, std::run, std::guard

Needs: fileRead, fileWrite, subprocess

(source)

runTool ​

ts
runTool(
  name: string,
  request: Json,
  dir: string = "~/.agency-agent/tools",
): Result<Json>

Run a saved tool with its input and return its result.

Runs the saved main node in a subprocess under the tool's stored time limit. Metadata must be readable before the tool starts. After the run, recording its use count is best-effort: a rejected or failed metadata write does not change the tool's result. The result itself is not recorded there.

Parameters:

NameTypeDefaultDescription
namestringThe saved tool's name under dir.
requestJsonA value matching the tool's Request type.
dirstring"~/.agency-agent/tools"Nonempty toolbox directory holding the tool.

Returns: Result<Json>

Throws: std::toolbox::scan, std::run, std::guard, std::toolbox::recordUse

Needs: fileRead, fileWrite, subprocess

(source)