Repository navigation
feat(tool): add on-demand tool search with native provider loading - #3680
Merged
Merged
Conversation
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
jujn
approved these changes
Oct 28, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
AgentScope-Java Version
2.1.0-SNAPSHOT
Description
Closes #3622.
Agents with many registered tools currently expose their full tool catalog to the model. This PR adds opt-in tool discovery: the model first searches for the capability it needs, then calls a discovered tool through the existing execution and permission path.
Search and provider-specific loading are separate. The default search runs locally using keywords; OpenAI Responses and Anthropic receive the results through their native client-side loading protocols. Other models use ordinary function calling.
Search API and default strategy
ToolSearchMiddlewareregisters the read-onlytool_searchtool, with a requiredqueryand an optional positivelimit(default 5). Applications enable discovery on an existing toolkit:KeywordToolSearchStrategyprovides dependency-free, case-insensitive matching over tool names and descriptions. Name matches receive a higher score; results are ordered by relevance and limited to the requested count.Applications can supply a
ToolSearchStrategyreturningMono<ToolSearchResult>. Its request contains the current eligible tool schemas, conversation messages, query, and limit. This allows vector search, a remote index, or a JEV-backed implementation without coupling core to those dependencies. This PR implements only the keyword strategy.Visibility, session state, and permissions
Initially, only search and configured always-visible tools are available for model use. Structured-output and explicitly forced tools remain visible. Discovered names accumulate in
ToolContextStateand survive state serialization without changing the serialized form of empty legacy state.Candidates respect the current request's tool groups and overrides. Strategy results are validated against that catalog, deduplicated, and limited before updating session state. Native search history is revalidated against current schemas so removed tools are excluded and overrides take effect without modifying stored messages. Previously discovered tools remain available after history compaction or a change of loading protocol.
Discovery does not bypass permission checks or replace tool execution. Searches retain reactive cancellation, and session discoveries remain in call-scoped state.
Native provider loading
tool_search_calllocally, and returns discovered definitions intool_search_output. Streaming and non-streaming calls use the same representation.defer_loadingand returns matches astool_referenceblocks. The full catalog is still sent in requests; deferred definitions enter model context when loaded.Native loading can be disabled through the middleware constructor. The adapters reuse the existing official Java SDK dependencies; no new dependencies or version changes are required.
OpenAI's existing hosted search remains a separate option and cannot be combined with client-executed search in one request. This contribution does not add provider-hosted search algorithms as local strategies. Anthropic prompt-cache markers are placed on the last non-deferred client tool. Native loading avoids routinely appending each discovery to the top-level tool declarations, but does not guarantee provider cache hits.
Documentation and validation
The PR adds an executable offline discovery-to-execution example and updates the English and Chinese tool, OpenAI, and Anthropic guides.
mvn -B -T1 verify -faepassed. After the final history and strict-schema adjustments,spotless:apply verifypassed again for core and both affected provider modules with-am: 3,283 test cases, 12 conditional skips, zero failures or errors.git diff --checkpassed.An earlier clean verification hit an unrelated Harness session-writer fencing failure; its isolated test passed on rerun, followed by the successful full reactor verification above. Live provider API calls have not been exercised; provider protocol coverage uses SDK objects and local mocks.