-
Notifications
You must be signed in to change notification settings - Fork 5.1k
CAMEL-22851: Implement native tool-search-tool for langchain4j-tools component #20996
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
base: main
Are you sure you want to change the base?
Conversation
This commit implements a native tool-search-tool feature for the camel-langchain4j-tools component that allows LLMs to discover and access tools dynamically without consuming the entire context window. Key changes: - Added 'exposed' parameter to LangChain4jToolsEndpoint (default: true) - Tools with exposed=false are added to a searchable registry instead of being immediately exposed to the LLM - Created ToolSearchTool class that provides search functionality for discovering non-exposed tools - Modified CamelToolExecutorCache to maintain separate caches for exposed and searchable tools - Updated LangChain4jToolsProducer to automatically expose the toolSearchTool when searchable tools exist - Added comprehensive integration tests demonstrating the feature - Updated component documentation with usage examples and benefits Benefits: - Reduced context usage by only exposing commonly used tools initially - Scalability to support hundreds or thousands of tools without overwhelming the LLM - Dynamic discovery allowing the LLM to find tools as needed based on conversation - Better organization through tag-based tool grouping
This commit addresses all Priority 1, 2, and 3 enhancements from the code review: Priority 1 (Critical): - Fixed tool search logic to search all searchable tools, not just those filtered by producer tags - Added duplicate prevention using LinkedHashSet in search results - Fixed doStop() memory leak by only removing tools registered by the specific endpoint - Added remove() and removeSearchable() methods to CamelToolExecutorCache for proper cleanup Priority 2 (Important): - Added comprehensive unit tests: * ToolSearchToolTest - tests search functionality with various tag combinations * ToolSearchToolFormatTest - tests output formatting for LLMs * CamelToolExecutorCacheTest - tests cache management operations - Completed Javadoc for isExposed() method - Added debug logging for tool registration and removal in LangChain4jToolsEndpoint - Added debug logging and null safety checks in handleToolSearchToolInvocation() - Enhanced parameter descriptions with examples in createToolSearchToolSpecification() Priority 3 (Nice to have): - Enhanced documentation with Best Practices section covering: * Tag strategy and naming conventions * Performance considerations * LLM guidance recommendations * Tool description best practices * Testing recommendations - Added Limitations section to documentation - Improved error messages and null handling Technical improvements: - Added static LOG field to LangChain4jToolsEndpoint following Camel conventions - Improved Javadoc comments with detailed explanations - Enhanced search algorithm to be more intuitive and user-friendly - Better separation of concerns between exposed and searchable tools All tests pass (24/24) and the build succeeds.
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🤖 CI automation will test this PR automatically. 🐫 Apache Camel Committers, please review the following items:
|
|
@gnodet For the integration test could you use https://github.com/apache/camel/blob/main/components/camel-ai/camel-langchain4j-tools/src/test/java/org/apache/camel/component/langchain4j/tools/integration/LangChain4jToolIT.java#L30 ? And the disable the test on the ci. with the ollama test-infra extension you can run the test following https://github.com/apache/camel/blob/main/components/camel-ai/camel-langchain4j-tools/test-execution.md in your case From time to time I do execute the langchain4j tests locally using |
orpiske
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Looking forward to having this one on the code
Implements CAMEL-22851.
Overview
This PR implements a native tool-search-tool feature for the
camel-langchain4j-toolscomponent that allows LLMs to discover and access tools dynamically without consuming the entire context window with tool definitions.Problem Statement
When working with LLMs that support function calling, exposing all available tools in every request can:
Solution
This PR introduces an
exposedparameter (default:true) that allows tools to be marked as "searchable" rather than immediately exposed to the LLM. A nativetoolSearchToolis automatically provided when searchable tools exist, enabling the LLM to discover tools on-demand based on tags.Key Features
1. Exposed Parameter
exposedboolean parameter onLangChain4jToolsEndpoint(default:true)exposed=falseare added to a searchable registry2. Native Tool Search Tool
3. Proper Resource Management
Usage Example
Benefits