Repository navigation
refactor(tools): define built-in tools through embedded manifests - #1369
Conversation
Snapshot every built-in tool's definition JSON, the tools offered in standard, plan and read-only mode, and the approval outcome per tool in standard and plan mode (with and without per-tool require_approval overrides), so moving the definitions into manifests cannot change what the model sees or what needs approval.
Introduce ToolManifest in the agent shared kernel: the #1366 manifest fields (name, description, command, parameters, require_approval, read_only, timeout, enabled) plus plan_mode, with strict decoding and validation of the name, the plan mode and the parameters schema. ParseCustomToolManifest additionally requires a command, for manifests loaded from disk. The file tools (Read, Write, Edit, MultiEdit, Delete, Grep, Tree, Bash) now build their definitions from embedded manifests that sit next to their implementations (internal/agent/tools/<Name>.yaml); the hand-written schema maps are gone. Refs #1367
Every tool in internal/agent/tools now builds its definition from the <Name>.yaml manifest next to its implementation. Values only known at runtime stay in Go on top of the manifest: the Agent tool's subagent catalog, the WebSearch engines and result limit from config, and the Memory entry size limit. A table test keeps the enums and bounds the manifests show the model in step with the constants the tools validate their arguments with. Refs #1367
…anifests The browser and computer bounded contexts own their tool definitions: each embeds its tools/<Name>.yaml manifests and builds the definitions from them, so changing a browser or computer tool touches only that context. GetLatestFrame still lists the registered frame sources at runtime on top of its manifest. Refs #1367
The registry now answers tool policy from each tool's manifest, replacing the static ReadOnlyTools, planModeAllowedTools and planOnlyTools maps and the Config.IsApprovalRequired switch. - Tools fold their own require_approval setting into Manifest(), so the config package no longer knows tool names. - ToolManifestLookup feeds the approval policy, the mode tool lists, the call-order barrier and subagent mode derivation. - Computer-use approval and session-only recording move into the computer context via the CallApprover and SessionTool contracts; IsComputerUseTool and IsSessionOnlyTool are gone. - Tool names are referenced through per-context constants. Refs #1367
Each tool's manifest is now the one place its description lives, so prompts.yaml drops its tools section: PromptsToolsConfig, the 49 seeded descriptions and the INFER_PROMPTS_TOOLS_*_DESCRIPTION env overrides are removed, and ToolManifest.Definition no longer takes an override. Refs #1367
|
@infer Can you review this PR? is it ready for merge? use /ponytail:ponytail-review /go /go-concurrency /domain-driven-design /clean-code /clean-architecture |
|
Model: Todos
Pull Request✅ Infer Result: SuccessReview complete. All checks passed and findings are finalized - below is the full review for the PR. Review: refactor(tools) - built-in tools defined through embedded manifestsVerdict: ready to merge. I found no correctness, boundary, or concurrency defect; the two findings below are minor and neither blocks merge. The two pending CI checks (test, e2e) should confirm what I verified locally. What I verified on the runner:
DDD / domain-driven-design: This is a textbook bounded-context extraction, not a ceremony pass. Each context owns its manifests next to its implementation (changing a computer tool touches only Clean architecture / clean-code: The Dependency Rule tightened measurably. go / go-concurrency: Over-engineering (ponytail-review): The diff's best outcome is that it gets shorter - it deletes ~3,100 lines while adding the manifests. The only cuttable piece is Non-blocking nits:
Follow-up: at merge time, file the already-drafted Model: Tokens: 2,545,641 in · 17,327 out · 2,562,968 total (26 requests) Tool calls: 50 total · 100% success rate TracesStatsTriggered by edenreich · Infer Action · OSS |
…caller ParseCustomToolManifest and the command, timeout and enabled fields only served custom tools, which nothing loads yet; they come back with the custom-tool loader. Refs #1367
read_only and plan_mode were two encodings of the same question - which agent modes a tool runs in - translated by a switch on the manifest. A manifest now lists its modes by mode key (standard, auto, auto-with-judge, plan, readonly); omitted means the unrestricted modes, as for MCP tools. Every mode still advertises the same tool list, so the prompt cache stays stable; ExecuteTool rejects a call outside the tool's modes with a message to the model. That guard now also covers readonly subagents, which offered only read-only tools but did not refuse a hallucinated call to another. Refs #1367
## Summary Closes #1366. Users add tools written in any language with one YAML manifest per tool. A custom tool works like a built-in: the model sees it, it runs through `!!Name(arg="v")` and `infer tools execute`, and it follows the same agent modes and approval flow. - **Where tools load from**: - **User tools** come from `~/.infer/tools/`, or `tools.custom_dir` / `INFER_TOOLS_CUSTOM_DIR`. - **Project tools** come from the working directory's `.infer/tools/` and `.agents/tools/`. - They merge. On a name clash the project tool wins, and `.infer/tools/` wins over `.agents/tools/`. - Running infer from home, where `.infer/tools` is the user directory, keeps those tools trusted as user tools. - **Manifest**: the built-in tool manifest from #1369 plus `command`, `timeout` (default 30s) and `enabled`. - It is strictly decoded, so `read_only:` or a typo fails loudly. The file name must match `name`. - An omitted `require_approval` inherits `tools.safety.require_approval`. - An omitted `modes` hides the tool in plan and readonly, like an MCP tool. - **Project tools always need approval**: a repository supplies them, so `require_approval: false` in a project manifest is ignored. Every call asks, even in `readonly` mode (which otherwise runs its tools unapproved), except in `auto` mode. - This is implemented as a `CallApprover` that only asks in the tool's own modes, so plan mode still refuses an out-of-mode call with "tool not allowed" rather than an approval request. - **The file tools never edit tool directories**: Write, Edit, MultiEdit and Delete refuse any path inside `~/.infer/tools`, `tools.custom_dir`, `.infer/tools` or `.agents/tools`, so the model cannot write itself a tool that skips approval. - The check resolves symlinks and ignores case, so a link or another spelling on a case-insensitive filesystem doesn't get around it. - It sits in `Config.ValidatePathInSandboxWrite`, so it applies regardless of `tools.sandbox.protected_paths`, including existing configs. - **A call**: - No shell. - The arguments are validated against `parameters` before the process starts, then written to stdin as one JSON object. - Exit 0 returns stdout as the result. A non-zero exit returns stderr (or stdout) as the error. - On timeout or turn cancel the whole process group is killed on Unix, so children of a script die too. Windows kills the direct child. - Capture is bounded, and `tools.max_result_bytes` caps what the model sees. - **Names**: a manifest is skipped with a logged warning when it takes the name of a built-in tool of any context (agent, a2a, browser, computer) or starts with `MCP_`. - Built-in names are checked even for tools config switches off, and compared case-insensitively. - Each context exposes `ToolNames()` for this. - **Policy for free**: the custom `Tool` implements `ManifestTool`, so per-mode tool lists, the `ExecuteTool` mode guard, `!!` autocomplete and `StandardApprovalPolicy` need no changes or name lists. - **Registration**: the container registers custom tools before Markdown subagents load, so `.infer/agents/*.md` may list them. `tools.enabled: false` turns them off with the other local tools. - **Shared validation**: the MCP argument checks move to `agentdomain.ValidateArguments`, used by MCP and custom tools. It also accepts `required` as `[]string`, which a parsed manifest produces and the old MCP copy silently skipped. - **Example**: `examples/tools` runs offline against a tokenless mock model scripted in `scenarios.yaml`. - It has one tool of each kind: `WordCount` (Python user tool, read-only, no approval) and `SaveNote` (shell project tool in `.agents/tools/`). - A Taskfile runs each scenario: `task word-count`, `task save-note` (blocked in headless), `task save-note:auto`, `task save-note:plan`, `task execute`, `task chat`. - **Package**: custom tools live in `internal/tools/custom` (imported as `customtools`), the start of a `tools` bounded context that the agent consumes. Moving the built-in tools and the registry from `internal/agent/tools` into it is the follow-up #1373. - **Language stats**: `.gitattributes` marks `examples/**` as vendored. The existing `tests/mocks` rule named a directory, which gitattributes never applies to the files inside it, so it becomes `tests/mocks/**`. ## Commits 1. `refactor(tools)`: `DecodeToolManifest` (strict decode for a type embedding `ToolManifest` inline) and `ValidateArguments` in the shared kernel. MCP uses the latter. 2. `feat(tools)`: the custom tools package (loader, runner, process-group kill), `tools.custom_dir`, `ToolNames()` per context, `mcpdomain.ToolNamePrefix`, container wiring. 3. `docs`: `docs/custom-tools.md`, plus links from the README, the tools and configuration references, the directory structure and AGENTS.md. 4. `style(tools)`: YAML arrays as block lists in docs and test manifests. 5. Review suggestion: drop the trailing comment on `ToolsConfig.CustomDir`. 6. `docs(examples)`: the tokenless-driven example and an e2e test that runs its scenarios. 7. `chore`: `.gitattributes` for examples and mocks. 8. `docs(examples)`: rename to `examples/tools` and add the Taskfile. 9. `feat(tools)`: refuse file-tool writes into custom tool directories. 10. `feat(tools)`: load project tools from `.infer/tools` and `.agents/tools`, which always need approval. 11. `docs(examples)`: ship `SaveNote` as a project tool. 12. `refactor(tools)`: move custom tools from `internal/customtools` to `internal/tools/custom`. ## Testing - `internal/tools/custom`: - loading and every skip case: unknown field, invalid YAML, file name mismatch, built-in name in any case, a disabled built-in, `MCP_`, missing command, negative timeout, `enabled: false`, missing directory; - project/user merge and precedence, and the home directory staying trusted; - success via stdin/stdout, non-zero exit with stderr, the stdout fallback, invalid arguments never starting the process; - a timeout that also kills a child process the script started (the test fails with the group kill disabled); - cancel; - mode listing and plan-mode refusal, and approval inheriting or overriding the global setting, through the real registry, `LLMToolService` and `StandardApprovalPolicy`; - project tools needing approval in standard, readonly and plan mode despite `require_approval: false`, and not in auto. - `config`: the write block for `.infer/tools`, `.agents/tools`, `tools.custom_dir`, the directory itself, another spelling and a symlink, while sibling and project files stay writable. The symlink and case cases each fail with their guard removed. - `agentdomain`: `ValidateArguments` table, including `required` as `[]string` and `[]any`, and `DecodeToolManifest` with an inline extension. Built-in manifests still reject `command`. The existing MCP tests pass unchanged. - e2e: `TestCustomToolsExample` runs the example's scenarios against the built binary: `WordCount` runs, the project tool `SaveNote` is blocked headless, runs in auto and is refused in plan. The full e2e suite passes. - `go test -race ./...` and `task precommit:run` pass. The tool-definitions golden file is unchanged. - Smoke with the built binary: - every example task behaves as its README says; - `infer tools execute Write` into `.agents/tools/` is refused even with `--approved`; - a custom `Read.yaml` and a manifest with `read_only:` are skipped with warnings while the built-in `Read` keeps working. ## Not included - The rest of the tools bounded context: moving `internal/agent/tools` into `internal/tools` and cutting its dependency on the agent context is #1373. - `infer export` builds its own tool registry without custom tools, so their results in exports use the default formatting. - The Bash tool is not covered by the write block. In `auto` mode it can run any command, as it already can for `.env` files. - A project's `.infer/config.yaml` is trusted like the user's own and can set `tools.custom_dir`, the Bash allow-list and the approval settings. The docs say to review it in repositories you don't trust. - From the issue's out-of-scope list: distribution via `infer plugins`, structured or streaming results, and a stdio MCP transport. - Docs follow-up: inference-gateway/docs#850 (a new `cli-custom-tools.md`, plus `cli.md` and `mcp.md`). --------- Co-authored-by: inference-gateway-maintainer[bot] <246577062+inference-gateway-maintainer[bot]@users.noreply.github.com>
|
🎉 This PR is included in version 0.216.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
Closes #1367. Built-in tool definitions and policy move out of Go code into embedded YAML manifests that use the #1366 custom-tool schema plus the agent
modesa tool runs in and an "inherit" state forrequire_approval. Execution stays in Go.internal/agent/tools/*.yaml(39),internal/browser/tools/*.yaml(6),internal/computer/tools/*.yaml(4). Changing a computer tool touches onlyinternal/computer.agentdomain.ToolManifestparses and validates a manifest (strict decode, name, parameters schema, plan mode). The custom-tool parts (command,timeout,enabled) are left to [FEATURE] Allow registering custom tools in any language #1366, which adds the first caller.Definition()returns a deep copy, so runtime patches (WebSearch engines, Memory limits, the Agent catalog) never share maps.ReadOnlyTools,planModeAllowedTools,planOnlyToolsand theConfig.IsApprovalRequiredswitch are deleted. The approval policy, per-mode tool lists, call ordering and subagent mode derivation read the manifests throughToolManifestLookup. Each tool folds its ownrequire_approvalsetting intoManifest(), soconfigno longer knows tool names.internal/computervia the newCallApproverandSessionToolcontracts;IsComputerUseTool/IsSessionOnlyToolare gone.toolssection ofprompts.yaml, its 49 seeded descriptions and theINFER_PROMPTS_TOOLS_*_DESCRIPTIONenv overrides are removed;infer initwrites aprompts.yamlwithout them.modes: [standard, auto, auto-with-judge, plan, readonly], omitted = the unrestricted modes), replacingread_only+plan_mode. Every mode still advertises the same tools, so a mode switch keeps the prompt cache;ExecuteToolrejects a call outside the tool's modes with a message to the model. That guard now also covers readonly subagents, which previously did not refuse a hallucinated call to a tool they weren't offered.tools.ToolRead,browser.ToolClick,computer.ToolComputer, ...).The A2A tools keep their manifests in
internal/agent/toolsuntil #1368 extracts A2A into its own context.Commits
test(agent): golden test pinning every tool definition, the per-mode tool lists and the approval outcomes, generated on the unchanged code.refactor(tools): manifest type and loader, file tools.refactor(tools): remaining agent tools, plus a drift test between manifest enums/bounds and the Go validation constants.refactor(browser,computer): their own embedded manifests.refactor(tools): resolve tool policy through the registry.refactor(config): take tool descriptions only from the manifests.docs: CONTRIBUTING "Adding New Tools", AGENTS.md, and removal of the tool-description override docs.Testing
internal/agent/testdata/tool_definitions.golden.jsonis unchanged since commit 1: definitions stay byte-identical (provider prompt cache stays stable), and mode lists and approval outcomes are unchanged.go test -race ./...andtask precommit:runpass.internal/computer/tools/Computer.yamlchanges exactly one golden line and nothing outsideinternal/computer.infer tools execute Read,infer tools validate(allowed and blocked) andinfer init(notools:inprompts.yaml) behave as before.Docs impact
In-repo docs are updated in this PR.
inference-gateway/docsmay still documentprompts.yamltool description overrides; draft ticket, not filed: