-
Notifications
You must be signed in to change notification settings - Fork 513
feat: opt-in client-side tool search (load_tools) to cut tool-schema tokens #2108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yakir-shriker
wants to merge
1
commit into
HolmesGPT:master
Choose a base branch
from
yakir-shriker:feat/tool-search-load-tools
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| """Client-side tool search (progressive tool disclosure). | ||
|
|
||
| When ``HOLMES_TOOL_SEARCH_ENABLED`` is set, heavy tool schemas (MCP toolsets) are | ||
| NOT loaded into the model's context up front. Instead the model is given a single | ||
| ``load_tools`` function tool; it calls that with a query to discover and load the | ||
| tools it needs, and they become available on the next step. | ||
|
|
||
| This is a deliberate alternative to Anthropic's server-side tool-search / | ||
| ``defer_loading`` beta: that path is mis-handled by LiteLLM (server_tool_use is | ||
| converted to a client tool_use and result blocks are dropped — BerriAI/litellm | ||
| issues #17737 and #28083), which breaks multi-step tool use through Bedrock-backed | ||
| gateways. ``load_tools`` is a plain function tool that HolmesGPT executes itself, so | ||
| it works identically across the Anthropic API, Bedrock, OpenAI and any | ||
| LiteLLM-fronted gateway — no beta header, no server tools. | ||
|
|
||
| On large MCP deployments this keeps 10-60k tokens of tool schemas out of every turn | ||
| until they're actually needed. | ||
| """ | ||
|
|
||
| # Name of the meta-tool the model calls to discover/load held-back tools. | ||
| LOAD_TOOLS_NAME = "load_tools" | ||
|
|
||
| # OpenAI function-tool definition for load_tools. It is a normal function tool — | ||
| # HolmesGPT intercepts and executes it (see ToolCallingLLM._handle_load_tools). | ||
| LOAD_TOOLS_TOOL: dict = { | ||
| "type": "function", | ||
| "function": { | ||
| "name": LOAD_TOOLS_NAME, | ||
| "description": ( | ||
| "Search for and load additional tools that are not loaded by default. " | ||
| "To keep the context small, heavy integrations are hidden until needed — " | ||
| "for example: AWS, GitHub, PagerDuty, Kafka/MSK, Tempo tracing, " | ||
| "OpenSearch/Elasticsearch metrics, and Grafana. Call this with keywords " | ||
| "describing the capability you need (e.g. 'aws s3', 'github pull request', " | ||
| "'kafka consumer lag', 'pagerduty incidents', 'tempo trace', " | ||
| "'opensearch metrics'). The matching tools become available to call on your " | ||
| "next step. If nothing matches, retry with broader keywords or an " | ||
| "integration name. Tools already loaded in this conversation stay available." | ||
| ), | ||
| "parameters": { | ||
| "type": "object", | ||
| "properties": { | ||
| "query": { | ||
| "type": "string", | ||
| "description": ( | ||
| "Keywords (or a regular expression) describing the capability or " | ||
| "integration you need, e.g. 'aws ec2', 'github', 'kafka lag'." | ||
| ), | ||
| } | ||
| }, | ||
| "required": ["query"], | ||
| }, | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| from holmes.core.tool_search import LOAD_TOOLS_NAME, LOAD_TOOLS_TOOL | ||
|
|
||
|
|
||
| def test_load_tools_tool_is_a_function_tool(): | ||
| # Must be a normal OpenAI function tool so HolmesGPT can execute it and so it | ||
| # works across every provider (no Anthropic server-tool / beta dependency). | ||
| assert LOAD_TOOLS_TOOL["type"] == "function" | ||
| assert LOAD_TOOLS_TOOL["function"]["name"] == LOAD_TOOLS_NAME | ||
| assert "query" in LOAD_TOOLS_TOOL["function"]["parameters"]["properties"] | ||
| assert LOAD_TOOLS_TOOL["function"]["parameters"]["required"] == ["query"] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.