ExAgent. Tool. Search
(ExAgent v2.3.0)
View Source
Capability that hides a large tool catalogue behind a search_tools tool.
Every advertised tool schema is sent with every model request. With dozens of
MCP tools that costs many tokens per step and makes the model pick worse. With
this capability the model first sees your regular tools plus search_tools;
a search returns the best matching deferred tools by name and description, and
those tools are offered from the next request on, for the rest of the
conversation.
search = ExAgent.Tool.Search.new(deferred: mcp_tools, max_results: 5)
ExAgent.new(
model: model,
tools: [lookup_order | ExAgent.Tool.Search.tools(search)],
capabilities: [search]
)tools/1 returns the search_tools tool followed by the deferred tools: they
stay in the agent's inventory, so validation, permissions, approvals and
persisted continuations treat them like any other tool. Which tools are loaded
is derived from the search_tools results in the history, so it survives
restore without extra state. Loaded tools follow the regular tools in load
order, in this and later runs, so the tool list only changes when a search
finds a new tool; provider prompt caches are invalidated then, not on every
step or turn. Providers that reject any change of
tools within a reasoning conversation are not a good fit.
Searching ranks by keyword overlap with tool names (weighted) and
descriptions, folding simple plurals; a query naming tools exactly returns just
those tools. Hiding a tool is not a security boundary;
use ExAgent.Permissions for authority. A loaded tool is offered even if an
earlier capability, such as a skill gate, removed it; do not filter deferred
tools with other capabilities. Capabilities that rewrite tool results, such as
ExAgent.Tool.OutputLimit, are fine: a rewritten search result is recomputed
from the query.
Options for new/1: :deferred (required, tools to hide), :max_results
(default 5) and :name of the search tool (default "search_tools").
Summary
Functions
Callback implementation for ExAgent.Capability.after_model_request/2.
Callback implementation for ExAgent.Capability.after_tool_execute/4.
Callback implementation for ExAgent.Capability.before_tool_execute/3.
Build a search capability. Raises ArgumentError for invalid options.
The search tool followed by the deferred tools, for the agent's :tools.
Types
@type t() :: %ExAgent.Tool.Search{ deferred: [ExAgent.Tool.t()], index: list(), max_results: pos_integer(), names: MapSet.t(String.t()), tool: ExAgent.Tool.t() }
Functions
Callback implementation for ExAgent.Capability.after_model_request/2.
Callback implementation for ExAgent.Capability.after_tool_execute/4.
Callback implementation for ExAgent.Capability.before_tool_execute/3.
Build a search capability. Raises ArgumentError for invalid options.
@spec tools(t()) :: [ExAgent.Tool.t()]
The search tool followed by the deferred tools, for the agent's :tools.