Agent tool framework
The agent tool framework gives an agent a controlled way to discover operational capabilities, understand their input and output contracts, and call them during a turn. It joins registry discovery, surface and availability rules, model-facing schemas, execution policy, lifecycle hooks, and workflow guidance so tools remain useful without exposing private connection data or unrestricted access.
Tool lifecycle
The framework moves a capability from a declared contract to a bounded runtime call. The registry creates the available view for a surface, the per-turn catalog controls which schemas are visible, the model selects from those schemas, and the executor validates and runs the call before returning a structured observation to the agent.
The main path is:
flowchart LR
A[Tool contract] --> B[Registry discovery]
B --> C[Surface and availability filter]
C --> D[Per-turn catalog]
D --> E[Visible public schemas]
E --> F[Model tool call]
F --> G{Specialist capability needed?}
G -- yes --> H[Activate schemas]
H --> E
G -- no --> I[Input validation]
I --> J[Approval and lifecycle hooks]
J --> K[Tool execution]
K --> L[Structured result and runtime events]
L --> E
The result returns to the agent as an observation. The agent can then make another call or produce an answer while the surrounding harness records events and applies host policy. See Agent execution architecture for the parent runtime, Agent harness and turn execution for host orchestration, LLM invocation and provider abstraction for the model boundary, Agent memory for memory tools, and Skill lifecycle and releases for workflow guidance changes.
Tool contracts
Registered tool model
The RegisteredTool model is the shared runtime description for a capability exposed by the registry. It names the operation and source, describes its use, declares its input and output shape, identifies supported surfaces, and carries policy such as side effects and call ordering.
Tools can begin as a BaseTool class or as a function marked with the tool decorator. Both forms become the same runtime model, so discovery and execution use one contract. An optional evidence mapper stays attached to the contract so downstream systems can connect a result to supporting evidence.
References: core/…/contracts.py• L210-264 core/…/contracts.py• L282-318 core/…/contracts.py• L391-432 core/…/contracts.py• L549-710 core/…/tool_decorator.py• L130-270
Runtime tool forms
The execution layer accepts registered tools and direct agent tools. A registered tool runs a discovered function or class method and can receive values from resolved integrations. A direct AgentTool receives the model payload plus an AgentToolContext that carries integrations, host resources, and optional update reporting.
This shared runtime union lets the agent loop apply one lifecycle to both forms. It also keeps session and console services outside the model-visible argument contract.
References: core/…/contracts.py• L702-796 core/…/execution.py• L428-462
Tool surfaces
Tool surfaces define where a capability may be offered: investigation, chat, or action. A tool defaults to investigation unless it declares another surface. Surface resolution removes tools that do not belong to the current user or agent path.
This lets one vendor capability support several flows while keeping sensitive or disruptive operations in the host that can handle them. For example, a delivery tool should not be offered to chat when the chat transport owns delivery.
References: core/…/tools.py• L8-13 tools/registry.py• L120-160 core/…/action_tools.py• L48-71 tests/…/test_tool_selection_contracts.py• L81-89
System capability contracts
System tools expose bounded local operations through the same registered-tool contract. Their descriptions and schemas set a narrow task boundary so an agent can select a safe operation without turning a broad request into unrestricted access.
The system set includes focused memory, trusted guidance, file structure, workspace, durable work-item, and scheduler inspection capabilities. The scheduled-loop tool lists recurring tasks known to the current process, including schedule state and the newest run outcome. It is read-only, exposes disabled loops only when requested, and limits organization-scoped turns to that organization's tasks. A missing task store means that nothing has been scheduled; an unreadable store returns an unavailable result rather than pretending that the schedule is empty.
References: tools/…/__init__.py• L14-25 tools/…/tool.py• L19-36 tools/…/tool.py• L39-75 tools/…/tool.py• L95-143 tools/…/tool.py• L44-166 tools/…/tool.py• L387-474 tools/…/tool.py• L56-110 tools/…/tool.py• L57-127
Registration and discovery
Registry sources
The canonical registry walks the built-in tools package, listed vendor integration packages, and explicitly registered external packages. It collects tools declared by decorators, BaseTool instances, or registered objects, then returns a name-sorted snapshot and lookup map.
External packages must be registered before lookup. Registration is idempotent and clears cached snapshots so the new package appears on the next lookup. The first definition wins when sources use the same name. Import failures are logged and skipped, which keeps unrelated capabilities usable while exposing the missing tool through registry diagnostics and execution results. Vendor tool packages are walked from the shared package list, while package manifests can add nested tool modules without requiring broad imports.
References: tools/registry.py• L33-117 tools/registry_discovery.py• L23-45 tools/registry_discovery.py• L98-113 tools/registry_discovery.py• L125-192 tools/registry_discovery.py• L195-246
System package manifests
System tools use a package manifest to tell discovery which sibling packages contain agent-callable modules. The manifest keeps system capability families discoverable without requiring a broad eager import of every support package.
The scheduled-loop package is part of that manifest. Its package exports the tool name and callable while the tool module supplies the registered contract. This makes scheduler inspection available through the normal registry and surface filtering path.
References: tools/…/__init__.py• L1-25 tools/…/__init__.py• L1-5 tools/…/tool.py• L95-124
Descriptor index
The descriptor index gives callers cheap tool metadata without importing every executor or vendor SDK. Surface-specific consumers use it to identify which modules can supply a tool and load an executor only when the capability must run.
The index is a discovery aid rather than a second tool contract. Its entries must agree with the imported registry. Frozen builds use a descriptor file shipped at build time because source scanning is not available there.
References: tools/registry_index.py• L1-12 tools/registry_index.py• L30-42 tools/registry_index.py• L44-218 tools/registry_index.py• L286-329 tools/registry.py• L120-160 tools/registry.py• L230-259
Availability filtering
Availability filtering turns resolved integration state and local runtime checks into the capabilities usable in the current session. A missing backend is different from an unknown tool, so integration tools return a typed unavailable envelope with a source, available: false, and a non-empty error.
This distinction lets the agent and evidence systems explain connection or configuration loss without treating it as a malformed request. Surface filtering still applies before a tool becomes available to the turn.
References: core/…/execution.py• L319-335 core/…/tool_availability.py• L1-41 tools/…/tool.py• L126-143 tools/…/__init__.py• L132-175
Progressive catalog visibility
Large interactive action catalogs use progressive visibility to keep the model's first tool set focused. Core controls stay visible, while specialist tools become visible only after tool_search activates them.
The per-turn provider first builds the available action set for the session. It can remove skill discovery or memory tools when the session disables those capabilities, and it applies a fail-closed read-only filter for unattended runs. Interactive runs then use a session-local catalog that adds any active skill helpers and exposes tool_search as the discovery control.
A catalog snapshot is limited by both the initial tool count and the schema token budget. A literal shell request can prioritize shell_run, while session-goal controls can join the initial set when a session goal is active. Search matches tool names and descriptive metadata, supports exact names, and returns full descriptions and workflow guidance for matched tools on the next reasoning step. A successful search can also expand a tool that was already visible but only had a compact description.
The catalog keeps a stable snapshot until the available tools or activation state changes. It reserves tool_search as its own discovery control, which prevents a registered capability from replacing the mechanism used to find hidden capabilities. Progressive visibility is disabled for unattended runs and for precomputed tool sets, so those hosts use their explicitly supplied safe set.
References: core/…/progressive_tool_catalog.py• L11-35 core/…/progressive_tool_catalog.py• L87-190 core/…/progressive_tool_catalog.py• L192-224 core/…/progressive_tool_catalog.py• L226-291 core/…/tool_provider.py• L148-177 core/…/skill_tool_catalog.py• L12-38
Per-turn tool provider
The default tool provider assembles the action capabilities for one session and turn. It binds the session, console, approval function, host ports, resolved integrations, and turn history boundary to the tool context so tools can act within the host's current limits.
The provider passes the resulting catalog to the agent and exposes the same live catalog through tool resources. It also creates observers for progress and bounded action logs. This keeps host state outside public schemas while allowing the execution path to report tool events.
References: core/…/tool_provider.py• L58-100 core/…/tool_provider.py• L100-186 core/…/tool_provider.py• L188-229
Model-facing schemas
Public input contract
Each tool exposes a JSON Schema that tells the model which arguments it may provide. The framework can build this schema from explicit metadata, a Pydantic model, or annotated function parameters while keeping the public form separate from the full runtime form.
Private connection and credential fields belong in injected_params. The framework removes them from the model-facing properties and required list, then obtains their values from resolved integration state at execution time. This stops the model from inventing secrets or account identity while preserving user-controlled values such as issue IDs, paths, and query limits.
The slash_invoke action uses the same boundary for interactive commands. Its public contract keeps the command name separate from positional arguments, restricts command names to the catalog, and tells the model to use it for explicit slash-command operations rather than as a general natural-language router. The catalog supplies use cases and anti-examples so the model can distinguish a request to run a command from an ordinary question.
References: core/…/contracts.py• L41-70 core/…/contracts.py• L73-115 core/…/contracts.py• L485-509 core/…/execution.py• L447-462 tools/…/tool.py• L26-36 tools/…/tool.py• L82-132 tools/…/slash_catalog.py• L542-589 tools/…/slash_catalog.py• L618-673
Call validation
Before a tool runs, the executor checks the model payload against the public schema. It requires an object, checks required fields, rejects undeclared fields when the schema forbids them, and checks declared value types and enum values.
Validation errors become structured tool errors and do not reach the backend. This gives the next agent iteration a clear reason to correct its call without exposing the backend to malformed input.
References: core/…/contracts.py• L511-541 core/…/execution.py• L348-364
Output contract
Tools may describe output fields or provide an output schema for the agent and other consumers. Runtime results are normalized into a ToolExecutionResult with provider content, optional details, an error flag, a terminate flag, and metadata.
The provider receives the content form while compatibility consumers can still read the historical raw payload. A truthy error marks a failed result; an empty or null error value does not make ordinary data fail.
References: core/…/contracts.py• L210-231 core/…/execution.py• L87-105 core/…/execution.py• L482-505
Tool execution
Agent call loop
The model receives the currently visible tool schemas in the provider request. When it returns ToolCall objects, the agent records the request, executes the calls in the listed order, appends their results to the conversation, and continues until the model gives an accepted answer or a tool asks the loop to stop.
When the model needs a hidden specialist capability, it calls tool_search first. The catalog activates matching schemas and the agent can call the selected tool on the next reasoning step. A turn-ending action such as ask_user_choice must stand alone. A batch that mixes it with another action does not run. Queued menus, approvals, or cancellations end the turn and skip later calls. Workflow plans give the host the completion state needed to accept a multi-step skill. A flagged report step makes the text reply reach the user before the next menu. The loop emits start and end events with public inputs and redacted results. These events support progress displays, tracing, and evidence capture without exposing private arguments in the user-facing path.
The slash-command action follows the same ordered execution path. It rebuilds positional arguments into a dispatchable command while preserving quoted values such as paths or cron expressions. A command that opens an interactive picker is queued for a turn with exclusive terminal input instead of racing the active prompt. The action returns bounded command output or a failure observation so the agent can use command results in a later call.
References: core/…/types.py• L69-83 core/…/react_loop.py• L259-314 core/…/react_loop.py• L333-428 core/…/progressive_tool_catalog.py• L226-291 tools/…/slash.py• L175-281 tools/…/slash.py• L335-353 core/…/test_onboarding_workflow.py• L120-180 core/…/test_workflow.py• L231-327
Execution policy
The executor preserves the model's call order and does not use a tool batch to create concurrent work. Bookkeeping may share a response with an action, but a turn-ending action must be the only action in that response. This keeps user input, approval, and other turn boundaries ahead of later work.
Side-effect and approval metadata then guide the host decision. Interactive shell modes can allow, ask, or block work based on autonomy, trust, plan-only state, and whether the host can collect approval. Risk labels help explain shell actions but do not decide permission.
Unattended action catalogs fail closed. The default provider keeps only tools with no side effect or read-only behavior and blocks named operations that can change delivery, invoke shell commands, or execute code. slash_invoke is a mutating action because a slash command can change local or external state, so its command-specific policy is checked before dispatch. Non-mutating control commands can bypass that action gate to preserve basic shell control.
References: core/…/execution.py• L226-288 core/…/execution.py• L465-479 tools/…/slash.py• L283-332 tools/…/execution_policy.py• L1-35 tools/…/execution_policy.py• L104-229 tools/…/policy.py• L24-57 core/…/tool_provider.py• L28-49 core/…/tool_provider.py• L157-168 core/…/test_merge_conflicts_workflow.py• L140-193 core/…/test_workflow.py• L231-264
Execution context
The executor supplies resolved integration state to a registered tool and merges extracted values with model arguments. Declared injected fields take precedence when a configured value exists, so the model cannot replace a connection or credential with a guessed value.
Direct agent tools receive the same resolved integrations through AgentToolContext, along with host resources and a callback for partial updates. Operational context stays available to the capability without entering the model's schema.
References: core/…/execution.py• L338-462 core/…/contracts.py• L713-729
Headless subprocess presentation
Non-TTY hosts need a subprocess presenter before an agent can use shell tools. The harness adapter installs the shared tool sources and a headless presenter during process setup, so gateway, scheduled, and embedded turns use the same tool contract without depending on interactive terminal output.
The headless presenter sends command and result messages to logs, supplies the subprocess environment, and accepts the execution decision already made by the host policy. It does not provide background CLI tasks or live output streams, so those operations remain unavailable in headless mode rather than competing for terminal control.
References: tools/harness_adapters.py• L6-17 tools/…/subprocess_presenter.py• L23-105
Execution hooks
Execution hooks provide the host boundary around a validated call. A pre-call hook can approve or block it, an after-call hook can adjust the normalized result, an update hook can receive partial progress, and a batch hook can inspect the provider request before calls start.
Hook composition preserves all supplied lifecycle stages. Pre-call failures block the operation while observer failures do not corrupt the tool result or transcript.
References: core/…/execution.py• L108-156 core/…/execution.py• L159-223 core/…/execution.py• L517-578
Skill guidance
Declarative workflow guidance
A SKILL.md file is optional workflow guidance for a named group of registered tools. Its front matter declares a lowercase kebab-case skill name, a description, and a non-empty list of tool names. The Markdown body explains when and how to use that group.
The loader validates the file and reports read or metadata warnings. Missing files are allowed, so a tool family can add guidance without making the registry depend on one file. Incomplete front matter is rejected instead of being passed to the model as raw metadata.
References: core/…/skill_guidance.py• L55-108 core/…/skill_guidance.py• L144-178 core/…/skill_guidance.py• L181-272
Guidance attachment
At registry load, valid guidance is formatted as a bounded model-facing block and attached to each named registered tool. The tool description then carries both the capability summary and the workflow rules that help the model choose a safe sequence. A workflow skill can also be loaded as a turn-specific recipe. After a user chooses an onboarding entry, the host pauses at the entry menu and starts the child workflow only in the answer turn. Scheduled runs can carry the selected recipe in their task while disabling general skill discovery.
The registry checks explicit and discovered skill files and validates their names against the full known tool set. Guidance attaches only to tools in the current surface snapshot. In a progressive action catalog, skill-local helpers remain immediately usable while general specialist tools stay searchable. Guidance improves selection and ordering but does not grant permission; surface membership, availability, schema checks, and approval hooks remain enforcement points. Combined guidance is limited to 2,400 characters, and guidance that disables model invocation is not attached.
References: core/…/skill_guidance.py• L111-134 tools/registry_skill_guidance.py• L20-115 core/…/progressive_tool_catalog.py• L112-141 integrations/…/SKILL.md• L1-32 integrations/…/SKILL.md• L1-51 core/…/test_onboarding_workflow.py• L120-180 core/…/test_merge_conflicts_workflow.py• L129-155
Change checklist
When these files or sections are changed, remember to consider these:
- A new tool contract must agree across its public schema, injected parameters, extracted parameters, source, and declared surfaces. A credential left in the public required list can stop the model from calling the tool.
- A new system tool must be added to the correct package manifest and keep its package export, decorator metadata, surface, side-effect level, and public output promise aligned.
- A new or moved tool module must remain discoverable through the package manifest, dynamic registry, and descriptor index. Runtime-only metadata needs the matching fallback descriptor or lazy-load path.
- A surface or availability change must be checked against the host that owns that surface. A typed unavailable result must remain distinct from an unknown tool.
- A side-effect change must be carried through approval hooks and action policy. Risk labels are advisory and do not enforce shell safety.
- A workflow action batch must preserve listed call order and keep turn-ending actions separate from work calls. A plan must be present before a later work call when the host's workflow gate requires it.
- A large action catalog must preserve the always-visible controls, the reserved
tool_searchname, next-step activation, schema size limits, and immediate access to skill-local helpers. - Changes to initial tool ordering or request prioritization must preserve the schema token budget and the literal shell-command path.
- Changes to the per-turn provider must keep session capability flags, unattended filtering, host resource binding, and live catalog updates aligned.
- Changes to unattended tool eligibility must keep the fail-closed side-effect filter and its blocked operation names aligned with the host's safety boundary.
- Skill front matter must name registered tools and keep combined model guidance within the 2,400-character bound. A renamed tool needs matching changes in the skill file and registry-facing metadata.
- Changes to error or output payloads must preserve the fields used by evidence classification and provider observation handling.
- Organization-scoped scheduler visibility must keep the deployment fallback owner rule intact. An unreadable task store must remain unavailable rather than empty.
- Changes to slash command names or guidance must update the command enum, command descriptions, use cases, anti-examples, and the dispatch path together. Keep command words in
commandand positional words inargs. - Changes to interactive slash commands must preserve the queue boundary for raw-stdin pickers and the distinction between a command typed by the user and one selected by the agent.
- Changes to slash output handling must preserve bounded success and error observations so the agent can chain data-dependent calls without receiving unbounded terminal output.
- Changes to harness startup wiring must keep both the registry and skill-tool sources installed with the headless subprocess presenter. Without that presenter, shell execution is blocked even when the tool is discoverable.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A new tool module is omitted from its package manifest or descriptor path | The tool is absent from a surface snapshot even though its code imports correctly | Update discovery metadata and the descriptor index together |
| A credential or connection identity remains model-visible and required | The model must supply a value it cannot know, so the call may fail or be skipped | Declare the field as injected and verify the public schema |
| A required argument has the wrong type or an undeclared field | The backend is not called and the agent receives a validation error | Keep the JSON Schema and call construction rules aligned |
| A specialist tool is needed but the model does not search the progressive catalog | Its schema is not available for the current reasoning step | Use tool_search with a capability query or exact tool name |
| A mutating or external tool lacks approval in a gated host | The pre-call hook blocks the operation or ends the turn | Set side-effect metadata and use the host approval policy |
| An unattended catalog includes a non-read-only or explicitly blocked tool | A scheduled tick can change local or external state | Apply the provider's fail-closed eligibility filter |
| A turn-ending action is batched with another action | The batch does not run, so the user menu or approval is not reached | Send the turn-ending action alone and continue after the next user turn |
| A workflow performs a later work call before its plan is established | The host rejects the work or cannot prove the step is complete | Write the plan before the gated work call and keep step status current |
| A scheduler task store cannot be read completely | The tool must not claim that no loops exist | Return the typed unavailable result with a non-empty error |
| A scheduled-loop query runs in an organization scope with the wrong owner rule | One organization can see another organization's scheduled tasks | Filter by the current organization and the deployment fallback owner |
| A skill has incomplete front matter or names a missing tool | Guidance is omitted or does not apply as intended | Close the metadata block and validate names against the registry |
| Combined skill guidance exceeds the model-facing limit | Later workflow rules can be cut off | Keep guidance concise and check the 2,400-character bound |
| The initial catalog exceeds its schema token budget or loses its discovery control | The model starts with an unusable or incomplete action surface | Preserve the count and budget checks and reserve tool_search |
| A session disables a capability but the provider still exposes its tools | The agent can request a capability that the host intended to remove | Apply session capability flags before building the live catalog |
slash_invoke receives command words in args or positional words in command | Schema validation or dispatch can reject the call or run the wrong command | Keep the command enum and argument array split as defined |
| An agent invokes an interactive picker while the REPL owns stdin | The picker races the prompt and terminal control bytes can enter user input | Queue the command for an exclusive-stdin turn |
| Slash output is not recorded or is returned without bounds | The agent cannot react to a failed command or a large result can bloat its context | Read the current turn's slash row and cap success and error text |
| Harness startup installs tool sources but no subprocess presenter | Shell tools refuse every call in a non-TTY host | Install the headless presenter adapter with the registry and skill sources |
| A headless host requests a background CLI task | The operation cannot provide the interactive stream or terminal control it needs | Return the unsupported-mode failure instead of starting a partial task |
Key files
| File | Why to read it |
|---|---|
| core/…/contracts.py | Defines shared tool metadata, public schema views, validation, evidence mapping, and direct agent-tool context. |
| core/…/execution.py | Shows the common call path, result shape, call ordering, injected values, and execution hooks. |
| tools/registry.py | Owns registry snapshots, surface lookups, external package registration, descriptor use, and lazy loading. |
| tools/registry_discovery.py | Explains how canonical and vendor tool packages, package manifests, module origins, and registered objects are found. |
| tools/registry_index.py | Defines the source-scanned metadata index, pinned descriptors, frozen-build index, and lazy executor loading. |
| core/…/tool_decorator.py | Shows how function tools enter the shared registered-tool contract. |
| core/…/skill_guidance.py | Defines the SKILL.md format, validation, diagnostics, parsing, and model-facing formatting. |
| tools/registry_skill_guidance.py | Attaches declarative guidance to registered tools and applies the size bound. |
| core/…/progressive_tool_catalog.py | Defines first-pass tool visibility, specialist search and activation, schema budgets, and catalog stability. |
| core/…/tool_provider.py | Builds per-turn action capabilities, applies session and unattended filters, and binds host resources to the live catalog. |
| core/…/skill_tool_catalog.py | Adds active-skill helper tools without changing global registration. |
| tools/…/__init__.py | Lists system tool packages that the registry must discover. |
| tools/…/tool.py | Illustrates a read-only system capability with organization filtering, schedule status, latest-run data, and unavailable-store handling. |
| tools/…/execution_policy.py | Defines action execution modes, approval gates, trust behavior, and plan-only behavior. |
| tools/…/slash_catalog.py | Defines slash-command intent guidance and the model-facing command and argument schema. |
| tools/…/slash.py | Shows slash-command execution, interactive-picker queuing, bounded observations, and mutating action gating. |
| tools/harness_adapters.py | Installs registry, skill-tool, and headless subprocess adapters during harness setup. |
| tools/…/subprocess_presenter.py | Shows the non-TTY host boundary for shell output, environment setup, and unsupported background tasks. |