-
-
Notifications
You must be signed in to change notification settings - Fork 97
Auto Mode Tool Classification
Auto mode now uses an intelligent classifier to select only the relevant tool categories based on the user's prompt, instead of loading all 84 tools upfront. This dramatically improves performance for simple conversations while maintaining full tool access when needed.
When a user selects "Auto" mode in the chat dropdown:
-
User enters a prompt → The prompt is sent with
tool_categories=None(Auto mode indicator) -
Classifier analyzes the prompt →
_classify_prompt_for_tools()uses keyword matching to detect intent - Relevant tools are loaded → Only tools from selected categories are bound to the model
- Request proceeds → The LLM generates a response with access to only the necessary tools
The classifier uses fast keyword-based pattern matching (no LLM call) to detect:
Web/Scraping Tools (search category) - Triggered by:
-
scrape,fetch,download,crawl,extract from -
get content,webpage,website,url,http -
Note: Web scraping and search tools are both in the
ToolCategory.SEARCHcategory
Math/Calculation Tools (math category) - Triggered by:
-
calculate,compute,solve,what is,how much -
equation,math,addition,subtract,multiply,divide - Math operators (
+,*,/,=,-) when no URL is present
File Operations Tools (file category) - Triggered by:
-
read file,write file,save to,open file -
create file,delete file,list files,directory
Time/Date Tools (time category) - Triggered by:
-
time,date,today,tomorrow,yesterday -
schedule,calendar,when is,what day
Search/Research Tools (search category) - Triggered by:
-
search,find,look up,research,information about -
tell me about,what do you know,explain
Conversation Management Tools (conversation category) - Triggered by:
-
clear history,clear conversation,conversation history -
new conversation,switch conversation,list conversations
-
Simple chat (e.g., "hello", "how are you?") → Returns
[](no tools needed) -
Multiple categories (e.g., "scrape site.com and calculate the sum") → Returns
["search", "math"] - URLs containing operators (e.g., "fetch https://example.com") → Excludes math tools (operators are ignored when URLs detected)
-
Web scraping → Uses
"search"category (both web search and scraping tools are inToolCategory.SEARCH)
- "hello" → 2048 input tokens (all 84 tools loaded)
- Response time: Slow (all tools in context)
- Token count: Excessive for simple chat
- "hello" → ~150 input tokens (0 tools loaded)
- "scrape joecurlee.com" → ~300 input tokens (only search tools loaded - includes web scraping)
- "what is 2+2" → ~200 input tokens (only math tools loaded)
- Response time: Fast (minimal tool overhead)
- Token count: Optimized for task complexity
| Mode | Tool Loading | Use Case |
|---|---|---|
| Chat (default) |
tool_categories=[] - No tools |
Simple conversations, Q&A without actions |
| Auto |
tool_categories=None - Intelligent selection |
General use, tasks requiring unknown tools |
| RAG | Specific RAG tools | Knowledge base queries |
llm_model_manager.py (Lines 260-290, 420-555)
- Added
_classify_prompt_for_tools()method for intelligent category selection - Modified
handle_request()to detect Auto mode and call classifier - Updated tool filtering logic to handle classifier output
llm_request.py (Line 333)
- Changed
APPLICATION_COMMANDto usetool_categories=None(Auto mode)
chat_prompt_widget.py (Lines 73-85)
- Changed dropdown default from "Auto" to "Chat" for better UX
message_formatting_mixin.py (Lines 103-117)
- Fixed to only pass tools to chat template when appropriate
Unit Tests: All 106 LLM component tests pass
Integration Test: test_tool_classifier.py - 17/17 test cases pass
Simple conversations (recommended):
- Keep dropdown on "Chat" (default)
- Type "hello", "how are you?", etc.
- Fast responses with no tool overhead
Commands requiring tools:
- Switch dropdown to "Auto"
- Type "scrape joecurlee.com" or "what is 2+2"
- Classifier selects relevant tools automatically (e.g.,
["search"]for scraping,["math"]for calculations) - Fast responses with only necessary tools loaded
Specific tool use:
- Use programmatic LLMRequest with explicit
tool_categories - Example:
LLMRequest(tool_categories=["search", "math"]) - Valid categories:
author,code,research,qa,chat,image,system,file,math,conversation,mood,analysis,workflow,search,rag,user
Adding new tool categories:
- Register tools with the appropriate category in
ToolManager - Add keyword patterns to
_classify_prompt_for_tools()inllm_model_manager.py - Update this documentation
Debugging classification:
from airunner.components.llm.managers.llm_model_manager import LLMModelManager
manager = LLMModelManager()
categories = manager._classify_prompt_for_tools("your prompt here")
print(f"Selected categories: {categories}")Potential improvements to the classifier:
- Machine Learning Classifier: Replace keyword matching with a lightweight ML model
- User Feedback Loop: Learn from user corrections (e.g., "I didn't need those tools")
- Context-Aware: Consider conversation history when selecting tools
- Performance Metrics: Track tool usage patterns and optimize keyword lists
- Custom Categories: Allow users to define their own tool categories
Solution: Check keyword patterns in _classify_prompt_for_tools() - may have false positive matches
Solution: Add more keyword patterns for that category or use explicit tool_categories in request
Solution: Verify you're using "Chat" mode (default), not "Auto" mode
- Mode-Based-Architecture - Overall architecture design
- Tool-System - How tools are registered and managed
- Chat-Prompt-Widget - UI for selecting chat modes
- LLM-Request-System - Request structure and parameters