Download docs/TOOL_PRIORITY_SYSTEM.md from 5xuekun/SHAPE: direct link, hf CLI and curl.
- Browser
- Download file 5.37 kB
-
https://huggingface.co/spaces/5xuekun/SHAPE/resolve/main/docs/TOOL_PRIORITY_SYSTEM.md
- Command line
-
hf download hf://spaces/5xuekun/SHAPE/docs/TOOL_PRIORITY_SYSTEM.md
-
curl -L -o TOOL_PRIORITY_SYSTEM.md https://huggingface.co/spaces/5xuekun/SHAPE/resolve/main/docs/TOOL_PRIORITY_SYSTEM.md
A newer version of the Gradio SDK is available: 6.31.0
Tool Priority System for LLM-Orchestrated Single-Cell Bioimage Analysis
Overview
This document describes the tool priority system implemented to ensure that the LLM-Orchestrated Single-Cell Bioimage Analysis System selects the most appropriate tools for each task, avoiding irrelevant tool calls and errors.
Architecture
1. Tool Priority Configuration (octotools/models/tool_priority.py)
A comprehensive priority system that categorizes tools based on their relevance to bioimage analysis tasks.
Priority Levels
HIGH (1): High priority tools for bioimage analysis
- Core image processing and segmentation:
Image_Preprocessor_Tool,Nuclei_Segmenter_Tool,Single_Cell_Cropper_Tool - Specialized analysis tools:
Cell_State_Analyzer_Tool,Fibroblast_Activation_Scorer_Tool,Analysis_Visualizer_Tool
- Core image processing and segmentation:
MEDIUM (2): Medium priority tools
- General-purpose image analysis tools:
Object_Detector_Tool,Advanced_Object_Detector_Tool,Image_Captioner_Tool
- General-purpose image analysis tools:
LOW (3): Low priority tools (use sparingly)
- Utility tools:
Text_Detector_Tool - Code generation tools:
Python_Code_Generator_Tool,Generalist_Solution_Generator_Tool
- Utility tools:
EXCLUDED (99): Tools not relevant for bioimage analysis
- All search tools (Google_Search_Tool, Pubmed_Search_Tool, etc.)
- Text extraction tools (URL_Text_Extractor_Tool)
Relevant_Patch_Zoomer_Tool(not suitable for bioimages)
Key Features
- Domain Detection: Automatically detects task domain (bioimage, search, text_extraction, general)
- Tool Filtering: Filters out irrelevant tools based on detected domain
- Dependency Management: Tracks tool dependencies (e.g., Single_Cell_Cropper_Tool requires Nuclei_Segmenter_Tool)
- Priority-Based Recommendations: Suggests next tools based on priorities and dependencies
2. Planner Integration (octotools/models/planner.py)
The Planner class has been enhanced to use the priority system:
Changes Made
Tool Priority Manager Integration:
- Initializes
ToolPriorityManagerin__init__ - Tracks detected task domain
- Initializes
Enhanced Query Analysis (
analyze_query):- Detects task domain automatically
- Filters tools based on domain
- Excludes irrelevant tools from consideration
Improved Next Step Generation (
generate_next_step):- Filters available tools based on domain
- Groups tools by priority in prompt
- Provides recommended next tools considering dependencies
- Enhanced prompt with explicit priority guidance
Tool Selection Validation (
_validate_tool_selection):- Validates that selected tool is in available tools list
- Checks if tool is excluded for the domain
- Verifies tool dependencies are satisfied
- Warns if LOW priority code generation tools are selected when higher-priority alternatives exist
Usage
The system works automatically. When the Planner analyzes a query:
Domain Detection: The system detects if the query is related to:
- Bioimage analysis (default for this system)
- Search tasks
- Text extraction
- General tasks
Tool Filtering: Based on the detected domain:
- Bioimage tasks: Excludes search/text tools, includes all bioimage-relevant tools
- Other domains: Applies appropriate filtering
Priority-Based Selection: The LLM receives:
- Tools organized by priority level
- Recommended next tools based on dependencies
- Clear guidance on which tools to prefer
Validation: After tool selection:
- Validates the tool is appropriate
- Checks dependencies are satisfied
- Provides warnings for suboptimal selections
Benefits
- Reduced Errors: Prevents calling irrelevant tools (e.g., search tools for image analysis)
- Better Tool Selection: Prioritizes tools most relevant to the task
- Dependency Management: Ensures tools are called in the correct order
- Extensibility: Easy to add new tools and adjust priorities
- Maintainability: Centralized priority configuration
Configuration
To modify tool priorities or add new tools, edit octotools/models/tool_priority.py:
- Update
BIOIMAGE_TOOL_PRIORITIESdictionary to set priorities - Add tool dependencies to
TOOL_DEPENDENCIESdictionary - Update keywords in domain detection sets if needed
Example
For a bioimage analysis query like "segment the cells in this image":
- Domain detected:
bioimage - Tools filtered: Search/text tools excluded
- Available tools prioritized:
- HIGH: Image_Preprocessor_Tool, Nuclei_Segmenter_Tool, Cell_Segmenter_Tool, Organoid_Segmenter_Tool, Single_Cell_Cropper_Tool, Cell_State_Analyzer_Tool, Analysis_Visualizer_Tool
- MEDIUM: Object_Detector_Tool, Image_Captioner_Tool, etc.
- LOW: Text_Detector_Tool, Python_Code_Generator_Tool, Generalist_Solution_Generator_Tool
- LLM guided to select from HIGH priority tools first
- Tool selection validated before execution
Files Modified
octotools/models/tool_priority.py(NEW): Priority system implementationoctotools/models/planner.py(MODIFIED): Integrated priority system
Future Enhancements
- Dynamic priority adjustment based on query complexity
- Learning from successful tool sequences
- More sophisticated dependency resolution
- Integration with tool performance metrics