Skip to main content

Add a tool

The full step-scoped pattern and the rules that keep handlers, permissions, and approvals aligned.
5 min read

Adding a tool is four domain files plus canonical catalog, presentation policy, and voice-dispatch metadata. Agata enforces a stricter pattern than Eve's minimum: every dynamic tool is resolved in step.started, so permissions and progressive activation are refreshed before each model call.

Read the rules section before writing anything.

The four rules#

Eve rewrites every execute, approval, and toModelOutput callback of a defineDynamic file into a durable named callback. Agata binds the transformed callback to its catalog tool name before Eve registers it for replay.

Literal defineTool calls go in agent/tools/

The transform plugin only processes files whose path contains /tools/. A helper in agent/lib/ that builds a defineTool(...) is never transformed.

That is why sectionToolset takes a build callback instead of a map of already-built tools: the factory has to run inside the tools file.

The handler uses a block body, never a concise arrow

The handler collector discards any handler without a BlockStatement. The repo guardian requires that the shape stay transformable.

Zero local declarations in the handler, and the parameter is named resolve

Closure capture is a regular-expression name comparison over the handler's parameters and variables. If a name appears in an execute body, it is captured and left declared: const { x } = __vars; followed by the original const x = …, which is a SyntaxError at build.

Hence the shape: the handler has a single statement, return sectionToolset(...), with no const or let. And the context parameter is named resolve, never ctx, because ctx appears in every execute.

Never close over the session token

A durable scope could serialize captured variables with JSON.stringify. A captured sessionToken would be persisted.

That is why each handler re-reads it inside execute with requireEveProfileAuth(ctx), instead of receiving it via closure.

The guardian#

It rejects any resolver in session.started / turn.started, runs Eve's real transform over every file in agent/tools/, and fails if one that declares tools was not transformed or captures closures. Always run it before treating a new tool as done.

The pattern#

Find the real API contract

OpenAPI is not authoritative for write payloads. Look at:

  1. apps/api/internal/<domain>/ports/in/*.go — the input shape.
  2. apps/api/internal/delivery/http/*.go — sometimes defines its own body, different from ports. Finance is the example: creating a transaction takes occurredAtMs, updating it takes occurredAt.
  3. Migrations, for valid enum values: CHECK constraints are the source of truth.

Also check which query params the handler actually parses. Several list endpoints only understand cursor and limit even though the domain has obvious filters. Never expose a filter input that does nothing.

Write lib/domains/<domain>/schemas.ts

One *Input per tool and shared *Outputs. Reuse _shared/pagination.ts for the list envelope and _shared/time.ts for dateKeySchema. Never redeclare a date key.

Write shape.ts

A loose GoXLike type and a trimXForModel(raw) that returns null for rows without identity. Trim to what is actionable: drop audit timestamps, internal ids, blobs, and sort fields.

One shaper per Go entity, not per tool.

Write handlers.ts

Exported async functions (input, ctx). Each one opens with requireEveProfileAuth(ctx) and is the only thing that touches HTTP. Convert dates here: the tool speaks date keys, the API speaks whatever it speaks.

Write agent/tools/<domain>.ts

Register capability metadata and voice dispatch

Add the name to AGENT_TOOL_NAMES and its file metadata in agent/lib/capabilities/catalog.ts, then add the executable schema/handler entry to agent/lib/voice/tool-registry.ts. The catalog owns group, section, mode, risk, intents, entity types, anchor/bulk classification, and optional skill. check:eve-tools rejects source/catalog/voice drift and group-budget violations.

Choose stable instructions or an on-demand skill

Keep the section briefing to capability facts. Put a multi-step procedure or large dispatcher contract in a permission-aware agent/skills/ definition; do not add long payload instructions to every turn.

Verify

Provider-backed evals and live Go writes are a separate authorized lane. Add at least one routing/contract eval now; run the approved matrix before enabling a new progressive default.

Narrow vs dispatcher#

QuestionChoose
Does the user ask for it in natural language several times a week?Narrow tool (create_task, plan_meal, …)
Is it configuration, structure, or maintenance?Operation on manage_<domain>

Do not invent an endpoint: look at ports/in and the HTTP handler. If the domain capability does not exist in Go, do not expose it (e.g. nutrition household). Next helpers Eve can call directly are fine when persistence still goes to Go (e.g. library oEmbed → thumbnailUrl on create).

Choose the result presentation#

Every canonical name must resolve in agent/lib/presentation/policies.ts. Choose the semantic kind from the authorized result shape, then choose its turn role:

  • terminal when the result normally answers the request;
  • supporting for resolver/search data that a later action can supersede;
  • text when prose is the actual answer, such as product documentation, capability discovery, or identity context.

Reuse a renderer family and extend its safe adapter only with fields confirmed by accepted input or output. Add English copy first and the matching Spanish keys in the same change. A new tool must not depend silently on the generic receipt: bun --filter app check:eve-tools fails catalog/presentation drift. Historic or invalid outputs may still fail closed to receipt/prose fallback.

When to ask for approval#

Set approval if the tool moves money, deletes data, or rewrites many rows at once.

  • always() for irreversible or financial work.
  • approveDeleteInSection('work') for deletes: denies immediately if the caller lacks delete permission in that section, instead of letting the API respond 403.
  • In a dispatcher, use ({ session, toolInput }) => … and return 'not-applicable' for a safe operation or the result of approveDeleteInSection — never invent an approval status.

Every write must declare an output schema. The shared tool gate adds the common receipt schema to legacy handlers and normalizes durable replay output, but domain handlers should still return exact entity ids, deep links, changed fields, reversibility, and bounded per-item receipts when they know them.

Gating a side effect is also how it stays safe against replays: a non-idempotent write behind an approval cannot fire on its own from a re-executed step.

When a naturally idempotent endpoint exists, prefer it: PUT .../checkins/upsert is indexed by date, PUT .../entity-tags replaces the entire set.