Skip to content

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

Closed

Description

Summary

Groundwork for #1366 (custom tools in any language): move the definitions of the built-in tools out of Go code into manifests that use the same schema as the #1366 custom tool manifest. Execution stays in Go, in-process. Once this lands, a built-in tool and a custom tool differ only in how they run: a built-in manifest binds to its Go implementation by name, a custom one runs command. #1366 then only adds loading from ~/.infer/tools/ and the process runner.

What is hardcoded today

A tool's definition and policy are spread over five places, all keyed by tool name:

  • JSON Schema: a hand-written Definition() per tool, 49 tools in total (39 in internal/agent/tools/, 6 in internal/browser/, 4 in internal/computer/).
  • Description: one field per tool in PromptsToolsConfig (config/prompts.go), overridable in prompts.yaml.
  • Approval default: the switch toolName in Config.IsApprovalRequired (config/config.go). Some tools have their own default (TodoWrite, Wait, Memory false; ApproveSubagent, CreateAvatar true), the rest fall back to tools.safety.require_approval.
  • Read-only: agentdomain.ReadOnlyTools (internal/agent/domain/tools.go), used for the read-only subagent toolset, the readonly mode and concurrent execution within a batch.
  • Plan mode: planModeAllowedTools and planOnlyTools (internal/agent/llm_tool_service.go).

Proposed shape

One embedded manifest per built-in tool, owned by the bounded context that implements it and embedded next to the Go code (internal/agent/tools/Read.yaml, internal/browser/tools/BrowserClick.yaml, internal/computer/tools/Computer.yaml), with the #1366 fields:

name: Read
description: Reads a file from the local filesystem. ...
parameters:
  type: object
  additionalProperties: false
  properties:
    file_path:
      type: string
      description: The path to the file to read (can be absolute or relative)
    limit:
      type: integer
      minimum: 1
      description: The number of lines to read. Only provide if the file is too large to read at once.
    offset:
      type: integer
      minimum: 1
      description: The line number to start reading from. Only provide if the file is too large to read at once
  required:
    - file_path
require_approval: false
modes: [standard, auto, auto-with-judge, plan, readonly]
  • A manifest without command binds to the Go implementation registered under the same name. Manifests loaded from disk ([FEATURE] Allow registering custom tools in any language #1366) still require command.
  • Definition() is built from the manifest. The Go types keep Execute, Validate and the formatting methods.
  • The tool registry answers tool policy (read-only, plan mode, approval) from the manifests; the container feeds it the browser and computer tools the same way as MCP tools, so changing a computer tool touches only internal/computer.
  • User config keeps winning for tools.<name>.require_approval / enabled in config.yaml. The manifest is the only source of a tool's description: the tools section of prompts.yaml and the INFER_PROMPTS_TOOLS_*_DESCRIPTION env overrides are removed.
  • Tools whose approval depends on their arguments (computer use) decide per call through a CallApprover contract in their own context; tool names are referenced through per-context constants.
  • The Agent tool appends the Markdown subagent catalog to its description at runtime. That decoration stays in Go on top of the manifest description.
  • No import cycle to manage: config no longer holds default tool descriptions, so infer init writes a prompts.yaml without a tools section.
  • The three A2A tools keep their manifests in internal/agent/tools until A2A moves into its own context ([TASK] Refactor extract A2A into its own bounded context #1368).

Schema gaps found (feed back into #1366)

The #1366 schema cannot express today's built-in behavior without two changes:

  1. Plan mode is not the same as read-only. WebFetch, WebSearch, ListSubagents, GetSubagentResult and ReadSubagentScreen are read-only but hidden in plan mode. TodoWrite, Wait, AskUserQuestion and A2A_QueryAgent are offered in plan mode but are not read-only. RequestPlanApproval is plan-only. Mapping everything onto one read_only flag would change what the model sees. Both are really the same question - which agent modes a tool runs in - so a manifest lists them: modes: [standard, auto, auto-with-judge, plan, readonly] (mode keys as in ParseAgentMode); omitted means the unrestricted modes (standard, auto, auto-with-judge). A tool listing readonly must change nothing: read-only subagents get it and its calls run concurrently. Every mode still advertises the same tool list so a mode switch keeps the prompt cache; a call outside the tool's modes is rejected at execution with a message to the model.
  2. require_approval needs an "inherit" state. Most built-ins have no default of their own and follow tools.safety.require_approval, so an omitted field must mean "use the global setting". Custom tools in [FEATURE] Allow registering custom tools in any language #1366 can keep defaulting to true.

Why execution stays in-process (not moved to cmd/tools)

Also considered: moving each tool's execution behind cmd/tools so a built-in manifest could be command: [infer, tools, execute, Read], exactly like a custom tool. Not recommended:

  • infer tools execute <Tool> '<json>' already runs every built-in through the agent's code path. What [FEATURE] Allow registering custom tools in any language #1366 is missing is the definition side, not a CLI entry point.
  • Every call would spawn a process and build the full service container (container.NewServiceContainer), on the hottest tools (Read, Grep, Edit).
  • Many tools depend on per-session in-memory state: the Edit/MultiEdit read-before-edit guard and file snapshots (Registry.readToolUsed / readFiles), background shells (Bash, BashOutput, KillShell, ListShells), the subagent tracker (Agent and its six sibling tools), and the chat UI (AskUserQuestion, RequestApproval, RequestPlanApproval).
  • Read, Edit, Grep and TodoWrite return structured Data (image content, diffs, matches, the todo list) that the TUI renders. The [FEATURE] Allow registering custom tools in any language #1366 contract is plain stdout text.
  • cmd/ is the Cobra and composition layer. Tool logic belongs in internal/agent/tools per the bounded-context layout.

If a stateless subset (Tree, Grep, WebFetch, WebSearch) should ever run out of process, that is a separate issue.

Suggested split

  1. Manifest type and loader, plus the file tools: Read, Write, Edit, MultiEdit, Delete, Grep, Tree, Bash.
  2. The remaining tools in internal/agent/tools/, then browser and computer.

Acceptance Criteria

  • A manifest type and loader that [FEATURE] Allow registering custom tools in any language #1366 reuses: it parses the fields a built-in tool needs plus modes and validates the name and the parameters schema. The custom-tool fields (command, timeout, enabled) and rejecting a manifest from disk without command land with [FEATURE] Allow registering custom tools in any language #1366, alongside their first caller.
  • Every built-in tool in internal/agent/tools/ has an embedded manifest and builds its Definition() from it. The hand-written schema maps are deleted.
  • Browser and computer tools get embedded manifests in their own packages through the same loader.
  • ReadOnlyTools, planModeAllowedTools, planOnlyTools and the hardcoded per-tool defaults in Config.IsApprovalRequired are derived from the manifests. Per-tool config overrides (tools.<name>.require_approval, enabled) keep working; prompts.yaml tool description overrides are removed, the manifest is the only source.
  • No behavior change: a golden test, generated from main before the refactor, pins the JSON of GetToolDefinitions() and the tool lists per agent mode (standard, plan, readonly), and passes unchanged after it. Byte-identical definitions also keep the provider prompt cache stable.
  • Existing tool tests pass; only tests of the removed prompts.yaml tool overrides and of the moved approval rules changed.

Activity

  1. moved this from In progress to QA in 2026on Sep 27, 2026
  2. added a commit that references this issue on Sep 27, 2026
    191f389
  3. inference-gateway-releaser commented on Sep 28, 2026

    @inference-gateway-releaser
    Contributor

    🎉 This issue has been resolved in version 0.216.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorreleased

    Type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions