OpenProgram Docs

Deferred tools

A deferred tool is registered, but its schema reaches the model only after tool_search loads it. Search is the only way to load. The loaded set is read from the request's own messages, and inside an epoch the tools array only grows at its end.

TopicDesignFollows
Loading on Anthropictool_reference result plus a defer_loading array entryClaude Code
CatalogBeside the user message, full once, then Added / RemovedClaude Code, Codex
A search that loads nothingSays why in words the model receives; a tool already in the array is "already callable"Claude Code, Codex
Guides and applicationsName their tools; the model loads themCodex
Source goneEntry stays; the call returns "unavailable"Codex
Called before loadingRuns if valid; a failed check says how to loadClaude Code
Mode and deny changesArray fixed per epoch; dispatch refusesCodex
RankingBM25 over name, namespace, description and schemaPi, Claude Code
Old search resultsNever agedClaude Code, Codex
Branches and nested runsLoads belong to the run whose messages hold themPi

Loading on Anthropic

A provider declares a native form under tool_search in provider.json. Anthropic declares anthropic-reference for anthropic-messages, with models_off: ["haiku"].

The Grok subscription endpoint declares none: it answers a tool_search_call item with 422 "unknown item type", so a load there appends to the array after every other tool.

PartWith the formWithout it
Search resulttool_reference blocks only, plus a sibling text block: the search's note, or Tool loaded. when no text is there; the result text stays on the node for the UIThe result text
ArrayLoaded tools appended with defer_loading: true, in first-load order, from the definition the load record keptLoaded tools appended as ordinary entries after every other tool, in first-load order (split_tools_for_dispatch); the request records an expected break tool_loaded
Beta headeradvanced-tool-use-2025-11-20; on Vertex tool-search-tool-2025-10-19None
CacheFingerprint skips deferred entries; breakpoint on the last ordinary toolUnchanged
No match, error, summary-carried toolPlain text result; a carried tool is an ordinary entrySame
Why this design
ComparedDoes
Claude CodeReferences in the result, defer_loading entries in the array; excludes haiku
Anthropic tool_additionAnnounces a tool in history; few models and platforms support it
CodexDefinition in a tool_search_output history item
PiAppends to the array; one known reread
HermesBridge tools; deferred tools never enter the array

A defer_loading entry is validated only once a result names it, and appending one is allowed; adding an ordinary tool or rewriting one is rejected. Claude Code runs this in production, and with search the only loading path, references cover every case.

Catalog

The list of loadable tools is the deferred_catalog section of turn_context, beside the user message. The conversation's system prompt holds none, so a server connecting mid-conversation changes no prefix byte.

RuleValue
Built-in deferred toolListed by name
MCP server or applicationOne namespace line, N tools: a, b, …, cut to 250 characters; an open application says so
Full listNo baseline: the first turn, and the first turn after a summary
Later turnsAdded deferred tools / Removed deferred tools; nothing when unchanged
SizeAt most 4 KiB, names first, then a count of what was left out
BaselineThe last catalog the rendered history shows
Own system prompt (Agent method, runtime.exec)Catalog stays inline in that prompt
No tool_search in the turn's toolsNothing is deferred: every tool of the turn goes out with its schema, so there is no catalog. Without the loader a deferred tool could never be called; Claude Code also sends every tool up front when its tool search is off. DEFAULT_TOOLS holds the loader and a selected list with a deferred tool gets it, so this is an Agent that disabled tool_search
Closing sentenceSays only the listed tools need loading, and that every tool already in the tools list is callable as it is and is never searched for. The loader's description says the same
Why this design
ComparedDoes
Claude CodeAppend-only names in a user-side reminder; all names again after compaction
CodexDeveloper-message delta by namespace, 250 characters a line, 4 KiB cap
PiSystem-prompt section by server, same caps
HermesInside the search tool's description, degraded by budget

History is the only place that changes nothing already sent. turn_context already resends only changed sections. A role: system message is not used on Anthropic: Claude Code uses the user side there, and some models reject it.

A search that loads nothing

A tool_search result has two parts: the loads (details["loads"]) and a note (details["note"]), the words for everything it did not load. Both are stored on the tool node, so every later request sends the same bytes.

Asked forNoteLoads
A tool already in the array: resident, or made resident for the turn`send_file` is already callable: it is in your tools list with its full schema. Call it now; it never needs tool_search.None; the array is unchanged
A name the turn does not offerNo tool named x is offered in this conversation. plus which tools need a searchNone
Keywords with no matchNo deferred tools matched query … plus which tools need a searchNone
A deferred tool, loaded before or notNoneIts definition, recorded as a load
A mixThe lines for what was not loadedThe rest
WireWhere the note goes
Codex (tool_search_output)The output carries the loaded definitions, tools: [] when there are none; the note follows as a user item wrapped in <tool-search-result>
Anthropic referencesWith loads: the text block beside the tool_reference blocks. Without: the result text, which is the note
Every other wireThe result text, which starts with the note
Why this design
ComparedDoes
Claude Codeselect: of a tool that is already loaded returns that tool as a match, "a harmless no-op that lets the model proceed without retry churn"; the file-delivery tool is never deferred
CodexSearches deferred tools only and sends an empty tool_search_output for every miss; its loader's description names what a search covers
PiReturns text on its own wire

An empty tool_search_output alone reads as "no such tool". A model that searched for send_file, which the array already held, answered that it could not send the file: the answer was in the result text, which this wire never sends.

Claude Code's answer lets the model go on, so a search for a callable tool says so first and in the positive.

RejectedBecause
The tool again in the output, kept in the arrayTwo entries of one name, a shape no client is known to send
The tool in the output, out of the arrayThe array changes and the prefix is re-read
Recording it as a loadA resident tool becomes a defer_loading entry on Anthropic

A message after a tool output is a shape every wire already uses for tool attachments.

The search is avoided in the first place by saying which tools need one: the catalog and the loader's description name the deferred list as the only tools to search for.

Guides and applications

A guide that teaches deferred tools, and an application when it opens, end with activation_note: Tools for this: `a`, `b`. Load them with `tool_search select:a,b`. Neither loads anything; an open application's tools stay deferred.

Why this design
ComparedDoes
CodexAn explicitly mentioned app's tools stay deferred
Claude Code, PiLoading only through search
HermesOnly searchable tools can be called

One loading path changes the array one way on every provider, and opening an application no longer rereads the prefix. The cost is one cheap, recorded select: call.

Source gone

EventReason given
Application closedits application '<id>' was closed
Owner unloaded'<owner>' was unloaded
MCP server disconnectedMCP server '<name>' is disconnected

The tools leave the registry and the catalog sends a Removed line. A loaded tool keeps its array entry; calling it returns Tool <name> is unavailable: <reason>. as an error. No tool_removal is sent.

Why this design

Codex keeps history and answers unsupported call; Anthropic advises keeping the definition and returning an ordinary error. Claude Code rewrites old references, which is a history edit. An array that never shrinks cannot fail validation or reread the prefix.

Called before loading

CallResult
Valid argumentsRuns
Failed check, not loadedThe error ends with This tool's schema was not sent. Load it with `tool_search select:<name>`, then retry.
Failed check, loadedThe error alone
Why this design

This is Claude Code's buildSchemaNotSentHint. Refusing every unloaded call would waste a round trip on calls that were right.

Mode and deny changes

An epoch is keyed by provider, model and first message (tool_epoch.epoch_key), so a summary or a model switch starts one. Its first request stores the withheld set with the tool snapshot.

ChangeArrayDispatch
Plan mode on or offUnchangedpermission_decision refuses
exit_plan_mode outside plan modeUnchangedRefused, PLAN_MODE_NOT_ACTIVE
Whole-tool deny rule, missing capabilityRemoved from the next epochRefused meanwhile
Structured-output submit tool appearsNew epoch record with it—
Why this design

Codex refuses at dispatch in plan mode; Claude Code refuses plan-mode calls but filters denied tools out; Anthropic advises against swapping tool lists in place. Changing the array mid-conversation fails on models that validate the tool set, and dispatch already enforces permission.

Ranking

RuleValue
Rankertool_rank, Pi's BM25: k1 1.2, b 0.75, name weight 3, namespace weight 0.5
IndexedName, namespace (MCP server or application), description, hint, schema property names and descriptions
TokensSplit on camelCase and __; stop words dropped; stemmed; CJK one character each
OrderExact name, then query terms matched, then score
A tool's nameselect:a,b loads exactly the named tools. A query that is exactly one tool's name does the same and ranks nothing: scheduler loads scheduler, not cron and remind with it. A name is a tool; applications and MCP servers are not selectable
Keptselect:, comma lists, +term filters first, the Agent's allowed set; loaded tools included
Default count5
Why this design

Pi and Codex use BM25; Claude Code uses fixed keyword scores. Pi's ranker spells out every rule and ports without a dependency. Every match is loaded for good, so the default stays at Claude Code's 5 rather than 8.

The argument is itself named select, so a model asking for one tool writes select: scheduler as often as select:scheduler. Claude Code answers a query that is an exact tool name with that tool before any scoring; the same rule here makes both spellings load one tool.

The catalog lists tool names only, so a group has no name to select: a keyword query reaches a server or application through the namespace field.

Old search results

A tool_search result is never shortened to a stub on any provider; tool output is not aged at all (Tool output).

Why this design

Claude Code's microcompact skips ToolSearch, and Codex never ages. The definition lives in the load record, so a stub saves little and is a history edit.

Branches and nested runs

RunTools it is sent
Two branches at onceEach, what its own messages loaded
Nested runtime.execIts own loads; the outer chat never sees them
Stopped or failed searchNothing loaded
Why this design

Pi writes loads into each branch's own state. Branches run in parallel, so loads cannot be conversation-wide state.

Implementation status

Open itemWaiting for
loaded_deferred_tools in journal, safe points, checkpointsRead-only for one release, then removed
Anthropic three-request self-test with cache diagnosisA paid live run
Codex cache after a large load and after a summaryA live Codex run
OpenAI and Azure Responses search formA live check; not declared until then
Copilot, Vercel, opencode with referencesA live check; they keep the array-append path
Empty thinking blocks skipped on AnthropicA request comparison with a paid run
Context breakdown and budgetStill estimate the catalog from the inline text
Epoch recordsKept per conversation; branches sharing a first message share one
Implementation files
  • openprogram/programs/_host/runtime.py, tool_rank.py
  • openprogram/programs/_authoring/guides.py, openprogram/extensions/mcp/registry.py
  • openprogram/models/providers/settings/tool_search_spec.py, adapters/anthropic/anthropic.py, shared/tool_loads.py
  • openprogram/runtime/agent/loop/streaming.py, tool_dispatch.py, tool_epoch.py
  • openprogram/runtime/context/prompt_assembly/turn_context.py, components.py
  • openprogram/runtime/permissions/policy.py, lifecycle.py
Last updated · 2026-11-25