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:

RoleLocationResponsibility
Required-field helperschema.go: ValidateRequiredReturn absent required argument names, in schema order.
Invocation boundarypkg/service/ipc.go: IPCCaller.CallToolDecode model arguments, apply the helper, and return synthetic tool-result errors before sending a call.
Metadata contractpkg/protocol/tool.go: ToolInfoCarry 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 required when 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_call frames in its subprocess tests, bypassing service preflight, so handlers enforce their contextual requirements themselves.

When does it run in a tool call?

  1. Agent admission: the agent offers selected tools and rejects a provider call whose exact name was not offered.
  2. IPC preflight: IPCCaller.CallTool resolves merged ToolInfo, parses the JSON arguments, and calls ValidateRequired.
  3. 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.go and pkg/service/registry.go.
  • Tests: none directly under pkg/tools; helper behavior is exercised indirectly through service flows, including schema and missing-argument cases in tests/suites/test_builtin.py.
  • Wire fields and sibling plugin/macro contracts: pkg/protocol/tool.go and pkg/protocol; frame definitions are cataloged in the JSONL API catalog.