Skip to content

refactor(tools): define built-in tools through embedded manifests - #1369

Merged
edenreich merged 9 commits into
mainfrom
refactor/tool-manifests
Sep 27, 2026
Merged

edenreich merged 9 commits into
mainfrom
refactor/tool-manifests

Conversation

@edenreich

@edenreich edenreich commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

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 modes a tool runs in and an "inherit" state for require_approval. Execution stays in Go.

  • Each bounded context owns its tools' manifests, embedded next to the implementation: internal/agent/tools/*.yaml (39), internal/browser/tools/*.yaml (6), internal/computer/tools/*.yaml (4). Changing a computer tool touches only internal/computer.
  • agentdomain.ToolManifest parses 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.
  • The registry answers tool policy. ReadOnlyTools, planModeAllowedTools, planOnlyTools and the Config.IsApprovalRequired switch are deleted. The approval policy, per-mode tool lists, call ordering and subagent mode derivation read the manifests through ToolManifestLookup. Each tool folds its own require_approval setting into Manifest(), so config no longer knows tool names.
  • Computer-use approval and session-only recording move into internal/computer via the new CallApprover and SessionTool contracts; IsComputerUseTool / IsSessionOnlyTool are gone.
  • Manifests are the only source of tool descriptions. The tools section of prompts.yaml, its 49 seeded descriptions and the INFER_PROMPTS_TOOLS_*_DESCRIPTION env overrides are removed; infer init writes a prompts.yaml without them.
  • A manifest lists the agent modes it runs in (modes: [standard, auto, auto-with-judge, plan, readonly], omitted = the unrestricted modes), replacing read_only + plan_mode. Every mode still advertises the same tools, so a mode switch keeps the prompt cache; ExecuteTool rejects 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.
  • Tool names are referenced through per-context constants (tools.ToolRead, browser.ToolClick, computer.ToolComputer, ...).

The A2A tools keep their manifests in internal/agent/tools until #1368 extracts A2A into its own context.

Commits

  1. test(agent): golden test pinning every tool definition, the per-mode tool lists and the approval outcomes, generated on the unchanged code.
  2. refactor(tools): manifest type and loader, file tools.
  3. refactor(tools): remaining agent tools, plus a drift test between manifest enums/bounds and the Go validation constants.
  4. refactor(browser,computer): their own embedded manifests.
  5. refactor(tools): resolve tool policy through the registry.
  6. refactor(config): take tool descriptions only from the manifests.
  7. docs: CONTRIBUTING "Adding New Tools", AGENTS.md, and removal of the tool-description override docs.

Testing

  • internal/agent/testdata/tool_definitions.golden.json is unchanged since commit 1: definitions stay byte-identical (provider prompt cache stays stable), and mode lists and approval outcomes are unchanged.
  • go test -race ./... and task precommit:run pass.
  • Editing internal/computer/tools/Computer.yaml changes exactly one golden line and nothing outside internal/computer.
  • Built binary: infer tools execute Read, infer tools validate (allowed and blocked) and infer init (no tools: in prompts.yaml) behave as before.

Docs impact

In-repo docs are updated in this PR. inference-gateway/docs may still document prompts.yaml tool description overrides; draft ticket, not filed:

[DOCS] CLI: tool descriptions are no longer configurable in prompts.yaml
The CLI no longer reads prompts.tools.<Tool>.description or INFER_PROMPTS_TOOLS_*_DESCRIPTION; each built-in tool's description ships in its manifest. Remove those sections from the CLI configuration pages (e.g. cli.md). Source: #1367.

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
@edenreich
edenreich requested a review from a team as a code owner September 27, 2026 23:07
@edenreich edenreich added the refactor Refactoring task label Sep 27, 2026
@edenreich

Copy link
Copy Markdown
Contributor Author

@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

@inference-gateway-maintainer

inference-gateway-maintainer Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Model: ollama_cloud/glm-5.3-flash · View Job

Todos

  • Read invoked skills (clean-code, clean-architecture)
  • Survey PR diff and commit history
  • Review core manifest domain type and registry policy resolution
  • Review computer/browser context boundaries and approval contracts
  • Review config/prompts removal and wiring
  • Run tests/vet to verify green state
  • Write review verdict with findings JSON

Pull Request

#1369

✅ Infer Result: Success

Review 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 manifests

Verdict: 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:

  • go test ./... green (exit 0, ~1m43s), includes the new golden test and the manifest drift test.
  • go vet ./... clean.
  • internal/agent/testdata/tool_definitions.golden.json untouched since commit 1 (c5c1294), so definitions, per-mode tool lists and approval outcomes really are byte-stable as claimed - the provider prompt cache stays warm.
  • The pinned 49 built-in tools = 39 agent + 6 browser + 4 computer YAML manifests; all three contexts embed their own.

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 internal/computer, and the golden test proves exactly one line changes). The shared kernel stays small and behavior-rich: ToolManifest carries policy (AllowedInPlanMode, RequiresApproval with the inherit-nil), and the one-method ToolManifestLookup port lets the agent core ask for policy without knowing which context defines the tool. The context map is honest - A2A manifests stay in internal/agent/tools until #1368 rather than being extracted prematurely (a bounded context is a model boundary, not a deployment unit). The computer context now owns its own approval semantics via the CallApprover port (observation vs destructive actions live in internal/computer/approval.go, unknown values fail closed) and its session-scoped recording via SessionTool - the anti-corruption layer sits exactly where the foreign concept (config knobs) meets the domain.

Clean architecture / clean-code: The Dependency Rule tightened measurably. config.IsApprovalRequired - a ~150-line tool-name switch - is deleted; config no longer knows tool names. The 49 seeded descriptions in config/prompts.go and the 26 INFER_PROMPTS_TOOLS_*_DESCRIPTION env overrides are gone; cmd/tools/tools.go now asks the tool itself (SessionTool) instead of hardcoding names. Adding a tool becomes: one YAML + the Go struct + one register line, with the golden test guarding the seam - OCP in action. Fail-fast helpers (MustLoadToolManifests, MustGet, PropertySchema panics) are consistent with the repo's style, and the drift test (TestToolManifestsMatchValidation) plus the golden test would catch a manifest/constants mismatch. Doc comments explain why (policy inheritance, prompt-cache stability), not how.

go / go-concurrency: CallOrder mutates barrier/since without a lock, but the contract - "Next must be called in batch order from one goroutine at a time" - holds at both call sites (agent.go issues Next sequentially before spawning; the approval loop is one goroutine), the wait closures capture their deps snapshot, and each done channel has exactly one owner that closes it once. Registry.Manifest takes the RLock only to read the map, then releases before calling ManifestTool.Manifest(), and Definition() deep-copies the schema, so concurrently-built definitions never share maps. Nothing here leaks goroutines; -race in CI covers it. Idiomatic-Go notes: modern stdlib is used well (slices, maps, cmp, min/max, errors.Join patterns), interfaces are consumer-discovered, and accept interfaces, return structs holds throughout.

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 ParseCustomToolManifest plus the Command/Timeout/Enabled manifest fields: grep shows no production caller in this PR (tests only); they pre-wire the #1366 custom-tools schema. If #1366 lands on top of this, keep them; otherwise they are ~25 lines of speculative surface. Everything else is lean - builtinTool is a constraint encoding a real invariant, the ToolManifest{Name: name} fallback gives MCP tools default policy without a special case, and the three-layer approval precedence (per-tool setting, manifest default, global) is behavior, not flexibility theater. Net: -25 lines possible (and only if #1366 is not imminent).

Non-blocking nits:

  • approval_policy.go: the arguments JSON is decoded twice on the two lazy paths (callArguments and isBashCommandAllowed); each decodes only when reached, so it is fine, but a single decode passed through would read slightly cleaner.
  • tool_definitions_golden_test.go: approvalOutcomes builds a full registry for each of the 8 (config x mode x global) approval snapshots; it is all in-memory and cheap, so this is only worth simplifying if the golden test ever slows the suite.

Follow-up: at merge time, file the already-drafted [DOCS] CLI: tool descriptions are no longer configurable in prompts.yaml ticket in inference-gateway/docs (the PR body drafts it; in-repo docs are already updated here).

Model: ollama_cloud/glm-5.3-flash · Exit Code: 0 · Duration: 6m 47s

Tokens: 2,545,641 in · 17,327 out · 2,562,968 total (26 requests)

Tool calls: 50 total · 100% success rate

Traces
Session: 1790550841-a3444cfa

session (headless, success)                                                                        6m39s
├── chat ollama_cloud/glm-5.3-flash                                                                14.2s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       5.4s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     5.4s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             5.4s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 5.4s
├── execute_tool Read call_wgomferk                                                                242µs
├── execute_tool Read call_vk9g6bvk                                                                153µs
├── chat ollama_cloud/glm-5.3-flash                                                                 1.7s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.7s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.7s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             1.7s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.7s
├── execute_tool Read call_hstxgdbf                                                                171µs
├── execute_tool Read call_0epbnsko                                                                171µs
├── chat ollama_cloud/glm-5.3-flash                                                                 5.3s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       5.2s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     5.2s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             5.2s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 5.2s
├── execute_tool TodoWrite call_7lacpl46                                                            62µs
├── execute_tool Read call_13u8i28x                                                                398µs
├── execute_tool Read call_l1ctfw0t                                                                475µs
├── chat ollama_cloud/glm-5.3-flash                                                                 5.5s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       5.5s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     5.4s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             5.4s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 5.4s
├── execute_tool TodoWrite call_j61ifv9x                                                            66µs
├── execute_tool Bash call_ydd1wmpt                                                                  3ms
├── chat ollama_cloud/glm-5.3-flash                                                                 2.3s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       2.2s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     2.2s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             2.2s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 2.2s
├── execute_tool Read call_g9jma0pr                                                                179µs
├── execute_tool Read call_futmir4f                                                                253µs
├── chat ollama_cloud/glm-5.3-flash                                                                 2.5s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       2.4s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     2.4s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             2.4s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 2.4s
├── execute_tool Read call_vzjqn3vp                                                                240µs
├── execute_tool Read call_08v83igo                                                                344µs
├── execute_tool Read call_knmzp934                                                                186µs
├── chat ollama_cloud/glm-5.3-flash                                                                 3.8s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       3.7s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     3.7s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             3.7s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 3.7s
├── execute_tool Read call_soxm5m1q                                                                189µs
├── execute_tool Read call_4c1ue4ce                                                                149µs
├── execute_tool Read call_xocspvr5                                                                193µs
├── chat ollama_cloud/glm-5.3-flash                                                                 3.7s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       3.7s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     3.7s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             3.7s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 3.7s
├── execute_tool Read call_ighd747c                                                                197µs
├── execute_tool Read call_wlli4bz3                                                                277µs
├── chat ollama_cloud/glm-5.3-flash                                                                 2.6s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       2.6s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     2.5s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             2.5s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 2.5s
├── execute_tool Read call_1tf50ear                                                                211µs
├── execute_tool Read call_27rd4khd                                                                190µs
├── chat ollama_cloud/glm-5.3-flash                                                                 3.8s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       3.8s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     3.8s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             3.8s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 3.8s
├── execute_tool Read call_yp347wzr                                                                119µs
├── execute_tool Read call_yiy4u66i                                                                139µs
├── execute_tool Read call_dcp9xw2f                                                                 76µs
├── chat ollama_cloud/glm-5.3-flash                                                                 3.3s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       3.2s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     3.2s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             3.2s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 3.2s
├── execute_tool Read call_i1qikqih                                                                143µs
├── execute_tool Read call_rqhi0gi2                                                                143µs
├── chat ollama_cloud/glm-5.3-flash                                                                10.3s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                      10.3s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]    10.2s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                            10.2s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                10.2s
├── execute_tool Read call_d0vlblpj                                                                348µs
├── execute_tool Read call_c2ttuo6n                                                                238µs
├── chat ollama_cloud/glm-5.3-flash                                                                 4.0s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       4.0s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     3.9s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             3.9s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 3.9s
├── execute_tool TodoWrite call_z4clgysk                                                            77µs
├── execute_tool Bash call_ncr4zyxt                                                                  6ms
├── chat ollama_cloud/glm-5.3-flash                                                                 6.0s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       6.0s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     6.0s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             6.0s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 6.0s
├── execute_tool Read call_zfabesqt                                                                131µs
├── execute_tool Grep call_wafo6ysc                                                                161ms
├── chat ollama_cloud/glm-5.3-flash                                                                 3.1s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       3.1s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     3.0s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             3.0s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 3.0s
├── execute_tool Read call_1pg9ftyf                                                                291µs
├── execute_tool Bash call_fharvu27                                                                  5ms
├── chat ollama_cloud/glm-5.3-flash                                                                 4.3s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       4.2s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     4.2s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             4.2s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 4.2s
├── execute_tool Read call_ohsn7lok                                                                351µs
├── execute_tool Read call_v2rg7j89                                                                245µs
├── chat ollama_cloud/glm-5.3-flash                                                                 6.1s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       6.0s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     6.0s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             6.0s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 6.0s
├── execute_tool Read call_mjb0far0                                                                248µs
├── execute_tool Grep call_6rabcvu3                                                                121ms
├── chat ollama_cloud/glm-5.3-flash                                                                30.4s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                      30.3s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]    30.3s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                            30.3s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                30.3s
├── execute_tool Grep call_dgx0dab7                                                                 77ms
├── execute_tool Bash call_q88i0od1                                                                  3ms
├── chat ollama_cloud/glm-5.3-flash                                                                 9.6s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       9.6s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     9.5s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             9.5s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 9.5s
├── execute_tool Grep call_lhz670by                                                                350ms
├── execute_tool Bash call_b6qsxud4                                                                  3ms
├── chat ollama_cloud/glm-5.3-flash                                                                19.3s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                      19.2s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]    19.2s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                            19.2s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                19.2s
├── execute_tool TodoWrite call_xhhkegb0                                                            68µs
├── execute_tool Bash call_ld59szof                                                                1m18s
├── chat ollama_cloud/glm-5.3-flash                                                                 2.8s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       2.7s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     2.7s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             2.7s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 2.7s
├── execute_tool Bash call_5zjssdl6                                                                977µs
├── chat ollama_cloud/glm-5.3-flash                                                                 2.0s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       1.8s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     1.8s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             1.8s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 1.8s
├── chat ollama_cloud/glm-5.3-flash                                                                 3.5s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                       3.3s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]     3.2s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                             3.2s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                 3.2s
├── execute_tool Wait call_n1o1qsrr                                                                1m38s
├── chat ollama_cloud/glm-5.3-flash                                                                36.7s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                      36.6s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]    36.6s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                            36.6s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                36.6s
├── execute_tool Bash call_gc6p2tyv                                                                  4ms
├── execute_tool Grep call_7xaspcpf                                                                545µs
├── chat ollama_cloud/glm-5.3-flash                                                                15.6s
│   ╰── POST /v1/chat/completions [inference-gateway, server]                                      15.5s
│       ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]    15.5s
│           ╰── POST /proxy/:provider/*path [inference-gateway, server]                            15.5s
│               ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                15.5s
├── execute_tool TodoWrite call_byjq1r96                                                            57µs
╰── chat ollama_cloud/glm-5.3-flash                                                                15.1s
    ╰── POST /v1/chat/completions [inference-gateway, server]                                      15.0s
        ╰── POST 127.0.0.1:8080/proxy/ollama_cloud/chat/completions [inference-gateway, client]    15.0s
            ╰── POST /proxy/:provider/*path [inference-gateway, server]                            15.0s
                ╰── POST ollama.com/v1/chat/completions [inference-gateway, client]                15.0s
Stats
Tool Calls

╭───────────┬───────┬───────┬─────────╮
│ Tool      │ Calls │ Fail% │ Avg     │
├───────────┼───────┼───────┼─────────┤
│ Read      │ 30    │ 0%    │ 213µs   │
│ Bash      │ 8     │ 0%    │ 9788ms  │
│ Grep      │ 5     │ 0%    │ 142ms   │
│ TodoWrite │ 5     │ 0%    │ 64µs    │
│ Wait      │ 1     │ 0%    │ 97501ms │
╰───────────┴───────┴───────┴─────────╯

Token Usage

╭────────────────────────────┬─────────┬─────────┬────────────┬─────────┬──────╮
│ Model                      │ Prompt  │ Cached  │ Completion │ Total   │ Cost │
├────────────────────────────┼─────────┼─────────┼────────────┼─────────┼──────┤
│ ollama_cloud/glm-5.3-flash │ 2545641 │ 2096640 │ 17327      │ 2562968 │ -    │
╰────────────────────────────┴─────────┴─────────┴────────────┴─────────┴──────╯

Sessions

╭───────────┬──────────┬──────────╮
│ Execution │ Mode     │ Sessions │
├───────────┼──────────┼──────────┤
│ headless  │ headless │ 1        │
╰───────────┴──────────┴──────────╯

Triggered by edenreich · Infer Action · OSS

@inference-gateway-maintainer inference-gateway-maintainer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full review: #1369 (comment)

Comment thread internal/agent/domain/tool_manifest.go Resolved
…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
@edenreich
edenreich merged commit 191f389 into main Sep 27, 2026
1 check passed
@edenreich
edenreich deleted the refactor/tool-manifests branch September 27, 2026 23:43
edenreich added a commit that referenced this pull request Sep 28, 2026
## 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>
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.216.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Refactoring task released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TASK] Refactor built-in tool definitions into manifests (groundwork for #1366)

1 participant