docs/pkg/tools.md
pkg/tools — required-field preflight helper
pkg/tools contains one service-side helper: ValidateRequired, which finds
missing top-level argument names from a tool metadata schema. It does not define,
discover, route, or execute tools. For bundled capabilities, see
cmd/ez-agent-builtin; for frames and external
capability peers, see pkg/protocol and the
JSONL API catalog. For activation, routing,
offered-tool selection, and metadata merging, see pkg/service,
pkg/service/agent, and
pkg/service/config.
What validates a tool call, and where?
Most of a tool call's validation lives outside this package:
| Role | Location | Responsibility |
|---|---|---|
| Required-field helper | schema.go: ValidateRequired | Return absent required argument names, in schema order. |
| Invocation boundary | pkg/service/ipc.go: IPCCaller.CallTool | Decode model arguments, apply the helper, and return synthetic tool-result errors before sending a call. |
| Metadata contract | pkg/protocol/tool.go: ToolInfo | Carry an untyped Parameters map; providers own its schema details. |
What are the limits of required-field checking?
- It checks whether a top-level key is present—not its value, type, enum,
nested shape, unknown fields, or conditional requirements. A present
nil, empty, or wrong-typed value satisfies this helper. - The helper only honors
requiredwhen it is[]interface{}. Builtin schemas declare[]string, while metadata crosses JSONL into generic maps; this representation boundary has no direct package test. - This is only a preflight. The bundled peer accepts direct
tool_callframes in its subprocess tests, bypassing service preflight, so handlers enforce their contextual requirements themselves.
When does it run in a tool call?
- Agent admission: the agent offers selected tools and rejects a provider call whose exact name was not offered.
- IPC preflight:
IPCCaller.CallToolresolves mergedToolInfo, parses the JSON arguments, and callsValidateRequired. ToolCallIPC: only a passing call becomes a frame for the capability peer.
Tool metadata is collected and merged by the service registry and configuration; the service pages linked above own that behavior.
Where do I change a bundled tool?
Edit the provider, not this helper: change the matching builtin capability
subpackage and register the tool in the builtin catalog composition
(buildProductionCatalog in main.go
over the generic
registry.Catalog).
Update pkg/service/config/builtin.yaml when the tool should be routed by
default. The builtin’s focused coverage is in
tests/suites/test_builtin.py; external-peer metadata flow is illustrated by
tests/suites/test_hello_tool.py.
Where is the authoritative detail?
- Helper behavior:
pkg/tools/schema.go. - Service preflight and metadata merging:
pkg/service/ipc.goandpkg/service/registry.go. - Tests: none directly under
pkg/tools; helper behavior is exercised indirectly through service flows, including schema and missing-argument cases intests/suites/test_builtin.py. - Wire fields and sibling plugin/macro contracts:
pkg/protocol/tool.goandpkg/protocol; frame definitions are cataloged in the JSONL API catalog.