- Add support for new database tools: GBIF, OBIS, WikiPathways, RNAcentral, ENCODE, GTEx, MGnify, GDC - Add optimizer tools and smolagents tool wrapper configs - Improve tool loading validation to filter out schema files and ensure tool names are strings - Update tool count from 713 to 734 tools - Fix tool validation to safely check supports_caching method using getattr - Add save_dir parameter to ToolDiscover tool - Update PyPIPackageInspector to inherit from BaseTool - Add smolagents as optional dependency in pyproject.toml - Simplify UniProt_search documentation - Minor log message improvements in smcp_server
6.0 KiB
Tool Generation Guide
Overview
The build_tools.py script automatically detects changes in tool configurations and only regenerates modified tools, avoiding unnecessary regeneration. This document explains how to ensure all changes are properly detected.
Change Detection Mechanism
How It Works
-
Hash Calculation: The system calculates an MD5 hash for each tool configuration
- Excludes timestamp fields (
timestamp,last_updated,created_at) - Recursively normalizes nested structures (dictionaries, lists, etc.)
- Uses sorted JSON serialization to ensure consistency
- Excludes timestamp fields (
-
Metadata Storage: Hash values are stored in
src/tooluniverse/tools/.tool_metadata.json- On first run, all tools are marked as "new tools"
- Subsequent runs compare old and new hash values
-
Change Identification:
- New Tools: Exist in configuration files but not in metadata
- Changed Tools: Hash values have changed
- Unchanged Tools: Hash values are identical
Detection Scope
The system detects changes in the following configuration fields:
name- Tool namedescription- Tool descriptionparameter- Parameter definitions (including added/removed/modified parameters)return_schema- Return type definitiontype- Tool type- All other configuration fields (except timestamps)
Usage
Basic Usage
# Normal build (only generate changed tools)
python scripts/build_tools.py
Force Regenerate All Tools
If you suspect there's an issue with change detection, you can force regeneration of all tools:
# Using command line argument
python scripts/build_tools.py --force
# Or using environment variable
TOOLUNIVERSE_FORCE_REGENERATE=1 python scripts/build_tools.py
Verbose Output Mode
View detailed change information:
# Show detailed information for each changed tool
python scripts/build_tools.py --verbose
# Or combine with force
python scripts/build_tools.py --force --verbose
Skip Formatting
If you only want to generate code without formatting:
python scripts/build_tools.py --no-format
Validation Features
After generating code, the system automatically validates:
- ✅ Whether function names match tool names
- ✅ Whether all required parameters appear in function signatures
- ✅ Whether all parameters in configuration appear in generated code
If issues are found, warning messages will be displayed in the output.
Common Questions
Q: Modified tool configuration but not detected?
A: Try the following steps:
-
Check if configuration actually changed:
# Use verbose mode to view python scripts/build_tools.py --verbose -
Force regeneration:
python scripts/build_tools.py --force -
Check metadata file: View
src/tooluniverse/tools/.tool_metadata.jsonto confirm hash values are updated -
Manually delete metadata file: Deleting
.tool_metadata.jsonwill force re-detection of all tools
Q: How to ensure old tools are properly deleted?
A: The system automatically cleans up orphaned files:
- If a tool is removed from configuration, the corresponding
.pyfile will be automatically deleted - Cleanup information is displayed in output:
🧹 Removed X orphaned tool files
Q: How to ensure parameter changes are detected?
A: Hash calculation detects the following parameter-related changes:
- Added parameters
- Removed parameters
- Modified parameter types
- Modified parameter descriptions
- Modified parameter default values
- Modified required/optional status
Q: Performance Optimization
A: The system is already optimized:
- Only regenerates changed tools
- Uses hash values instead of full configuration comparison
- Supports parallel processing (if configured)
Environment Variables
| Variable Name | Description | Default Value |
|---|---|---|
TOOLUNIVERSE_FORCE_REGENERATE |
Force regenerate all tools | 0 (don't force) |
TOOLUNIVERSE_VERBOSE |
Show detailed change information | 0 (don't show) |
TOOLUNIVERSE_SKIP_FORMAT |
Skip code formatting | 0 (format) |
Best Practices
-
Regular Force Rebuild: Use
--forceafter important updates to ensure consistencypython scripts/build_tools.py --force -
Use Version Control: Include
.tool_metadata.jsonin version control to track changes -
Verify Generation Results: Use
--verboseto view detailed output and ensure all tools are processed correctly -
Cleanup Testing: Run build after modifying tool configurations to confirm orphaned files are properly cleaned up
Troubleshooting Steps
If you encounter problems, troubleshoot in the following order:
- ✅ Check if configuration file format is correct (valid JSON)
- ✅ Use
--verboseto view detailed output - ✅ Use
--forceto force regeneration - ✅ Check if
.tool_metadata.jsonfile is corrupted - ✅ Delete
.tool_metadata.jsonto start fresh - ✅ Check generated code validation error messages
Technical Details
Hash Calculation Algorithm
# Pseudocode
def calculate_hash(tool_config):
# 1. Exclude timestamp fields
normalized = {k: v for k, v in config.items()
if k not in excluded_fields}
# 2. Recursively normalize nested structures
normalized = normalize_recursive(normalized)
# 3. Serialize to JSON with sorted keys
json_str = json.dumps(normalized, sort_keys=True)
# 4. Calculate MD5 hash
return md5(json_str)
Change Detection Flow
Load tool configurations
↓
Calculate hash for each tool
↓
Load old metadata (.tool_metadata.json)
↓
Compare old and new hash values
↓
Categorize: new tools / changed / unchanged
↓
Only generate new tools and changed tools
↓
Update metadata file
Tip: If you encounter any issues during use, you can use the --force --verbose options to get more diagnostic information.