gnodet opened a new pull request, #20996:
URL: https://github.com/apache/camel/pull/20996

   ### Overview
   This PR 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 with tool 
definitions.
   
   ### Problem Statement
   When working with LLMs that support function calling, exposing all available 
tools in every request can:
   * Consume significant context window space, reducing space for actual 
conversation
   * Overwhelm the LLM with too many options, potentially degrading performance
   * Limit scalability when dealing with hundreds or thousands of tools
   
   ### Solution
   This PR introduces an `exposed` parameter (default: `true`) that allows 
tools to be marked as "searchable" rather than immediately exposed to the LLM. 
A native `toolSearchTool` is automatically provided when searchable tools 
exist, enabling the LLM to discover tools on-demand based on tags.
   
   ### Key Features
   
   **1. Exposed Parameter**
   
   - New` exposed` boolean parameter on `LangChain4jToolsEndpoint` (default: 
`true`)
   - Tools with `exposed=false` are added to a searchable registry
   - Maintains backward compatibility - existing code works unchanged
   
   **2. Native Tool Search Tool**
   
   - Automatically exposed when searchable tools exist
   - Searches by tags with support for comma-separated lists
   - Returns formatted tool descriptions for LLM consumption
   - Prevents duplicate results when tools have multiple matching tags
   
   **3. Proper Resource Management**
   
   - Endpoints only remove their own tools on shutdown (fixes potential memory 
leak)
   - Separate caches for exposed and searchable tools
   - Clean separation of concerns
   
   ### Usage Example
   
   ```java
   // Exposed tool - immediately available to LLM
   from("langchain4j-tools:queryById?tags=users&description=Query user by 
ID&parameter.userId=integer")
       .to("sql:SELECT name FROM users WHERE id = :#userId");
   
   // Searchable tool - discoverable via toolSearchTool
   from("langchain4j-tools:queryBySSN?tags=users&description=Query user by 
SSN&parameter.ssn=string&exposed=false")
       .to("sql:SELECT name FROM users WHERE ssn = :#ssn");
   
   // Another searchable tool with different tags
   from("langchain4j-tools:sendEmail?tags=users,email&description=Send 
email&parameter.email=string&parameter.message=string&exposed=false")
       .to("smtp://mailserver");
   ```
   
   ### Benefits
   
   - **Reduced Context Usage**: Only expose commonly used tools initially
   - **Scalability**: Support hundreds or thousands of tools without 
overwhelming the LLM
   - **Dynamic Discovery**: LLM discovers tools as needed based on conversation 
context
   - **Better Organization**: Tag-based tool grouping for easier discovery


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to