feat: add meta tools for dynamic tool discovery and execution
Merged
RY
1y ago+1048+1048+0123456789012345678901234567890123456789-0-0-0123456789
Summary
This PR introduces meta tools functionality to enable dynamic tool discovery and execution in the StackOne AI SDK. Meta tools allow AI agents to search for relevant tools using natural language queries and execute them without hardcoding tool names.
Note: This implementation is based on the learnings from #77 and addresses the issues encountered in that PR.
Features Added
🔍 Meta Tools (Beta)
meta_filter_relevant_tools: Discovers relevant tools using natural language queries with BM25 relevance rankingmeta_execute_tool: Executes discovered tools dynamically with provided parameters
Key Improvements
- Uses Orama's BM25 algorithm for high-quality relevance ranking
- Supports filtering by minimum relevance score
- Provides both OpenAI and AI SDK format compatibility
- Includes comprehensive test coverage
Implementation Details
Tool Discovery
- Indexes all available tools using Orama search engine
- Extracts categories and action types from tool names for better search
- Returns tools with relevance scores for transparency
Developer Experience
- Simple API:
await tools.metaTools()to get meta tools - Works seamlessly with existing OpenAI and AI SDK integrations
- No authentication complexity - uses existing toolset authentication
Testing
- ✅ Unit tests for both meta tools
- ✅ Integration tests for the complete workflow
- ✅ Format conversion tests (OpenAI and AI SDK)
- ✅ Example implementations provided
Documentation
- Added comprehensive documentation to README with beta warning
- Created detailed examples in
examples/meta-tools.ts - Included usage patterns for both AI-assisted and direct usage
Beta Status
These features are marked as beta as the API may evolve based on user feedback. The core functionality is stable and well-tested.
Example Usage
// Get meta tools
const metaTools = await tools.metaTools();
// Use with AI SDK
const aiSdkTools = metaTools.toAISDK();
const { text } = await generateText({
model: openai("gpt-4o-mini"),
tools: aiSdkTools,
prompt: "Find tools for managing employees",
});
Test Plan
- Run all unit tests:
bun run test:unit - Test examples work correctly
- Verify OpenAI format compatibility
- Verify AI SDK format compatibility
- Check relevance scoring accuracy
Summary by cubic
Added meta tools for dynamic tool discovery and execution, allowing agents to search for relevant tools using natural language and run them without hardcoding tool names.
- New Features
- Added
meta_filter_relevant_toolsfor searching tools with BM25 relevance ranking. - Added
meta_execute_toolfor running discovered tools dynamically. - Included full parameter schemas in search results for compatibility with OpenAI and SDK formats.
- Added documentation, examples, and comprehensive tests for meta tools.
- Added