tooluniverse.tool_finder_llm module¶
LLM-based Tool Finder - A tool that uses LLM to find relevant tools based on descriptions.
This tool leverages AgenticTool’s LLM functionality to create an intelligent tool finder that puts only essential tool information (name and description) in the prompt to minimize context window cost while letting the LLM decide which tools to return based on the query.
Key optimizations: - Only sends tool name and description to LLM (no parameters, configs, etc.) - Uses compact formatting to reduce token count - Caches tool descriptions to avoid repeated processing - Excludes irrelevant tools from prompt
- class tooluniverse.tool_finder_llm.ToolFinderLLM[source]¶
Bases:
BaseTool
LLM-based tool finder that uses natural language processing to select relevant tools.
This class leverages AgenticTool’s LLM capabilities to analyze tool descriptions and match them with user queries. It’s optimized for minimal context window cost by only sending essential information (tool name and description) to the LLM, providing an intelligent alternative to embedding-based similarity search.
Cost optimizations: - Only includes tool name and description in LLM prompt - Uses compact formatting to minimize token usage - Excludes unnecessary tool metadata and parameters - Implements caching to avoid repeated tool processing
- __init__(tool_config, tooluniverse=None)[source]¶
Initialize the LLM-based Tool Finder.
- Parameters:
tool_config (
dict
) – Configuration dictionary containing LLM settings and promptstooluniverse – Reference to the ToolUniverse instance containing all tools
- find_tools_llm(query, limit=5, include_reasoning=False, categories=None)[source]¶
Find relevant tools using LLM-based selection.
- Parameters:
- Returns:
Dictionary containing selected tools and metadata
- Return type:
- find_tools(message=None, picked_tool_names=None, rag_num=5, return_call_result=False, categories=None, return_list_only=None)[source]¶
Find relevant tools based on a message or pre-selected tool names.
This method matches the interface of the original ToolFinderEmbedding to ensure seamless replacement. It uses LLM-based selection instead of embedding similarity.
- Parameters:
message (
str, optional
) – Query message to find tools for. Required if picked_tool_names is None.picked_tool_names (
list, optional
) – Pre-selected tool names to process. Required if message is None.rag_num (
int, optional
) – Number of tools to return after filtering. Defaults to 5.return_call_result (
bool, optional
) – If True, returns both prompts and tool names. Defaults to False.categories (
list, optional
) – List of tool categories to filter by. Applied before LLM selection.return_list_only (
bool, optional
) – If True, returns only a list of tool specifications. Overrides other return options.
- Returns:
If return_list_only is True: List of tool specifications
If return_call_result is False: Tool prompts as a formatted string
If return_call_result is True: Tuple of (tool_prompts, tool_names)
- Return type:
- Raises:
AssertionError – If both message and picked_tool_names are None
- run(arguments)[source]¶
Run the tool finder with given arguments following the standard tool interface.
This method now returns JSON format by default to ensure consistency with other search tools and simplify integration with SMCP.
- Parameters:
arguments (
dict
) – Dictionary containing: - description (str, optional): Query message to find tools for (maps to ‘message’) - limit (int, optional): Number of tools to return (maps to ‘rag_num’). Defaults to 5. - picked_tool_names (list, optional): Pre-selected tool names to process - return_call_result (bool, optional): Whether to return both prompts and names. Defaults to False. - return_format (str, optional): ‘json’ (default) or ‘legacy’ for old format - return_list_only (bool, optional): Whether to return only tool specifications as a list - categories (list, optional): List of tool categories to filter by