Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/meta_tools_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def example_meta_tools_basic():
meta_tools = all_tools.meta_tools()

# Get the filter tool to search for relevant tools
filter_tool = meta_tools.get_tool("meta_filter_relevant_tools")
filter_tool = meta_tools.get_tool("meta_search_tools")
if filter_tool:
# Search for employee management tools
result = filter_tool.call(query="manage employees create update list", limit=5, minScore=0.0)
Expand All @@ -55,7 +55,7 @@ def example_meta_tools_with_execution():
meta_tools = all_tools.meta_tools()

# Step 1: Search for relevant tools
filter_tool = meta_tools.get_tool("meta_filter_relevant_tools")
filter_tool = meta_tools.get_tool("meta_search_tools")
execute_tool = meta_tools.get_tool("meta_execute_tool")

if filter_tool and execute_tool:
Expand Down Expand Up @@ -138,7 +138,7 @@ def example_with_openai():
messages=[
{
"role": "system",
"content": "You are an HR assistant. Use meta_filter_relevant_tools to find appropriate tools, then meta_execute_tool to execute them.",
"content": "You are an HR assistant. Use meta_search_tools to find appropriate tools, then meta_execute_tool to execute them.",
},
{"role": "user", "content": "Can you help me find tools for managing employee records?"},
],
Expand Down
18 changes: 9 additions & 9 deletions stackone_ai/meta_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


class MetaToolSearchResult(BaseModel):
"""Result from meta_filter_relevant_tools"""
"""Result from meta_search_tools"""

name: str
description: str
Expand Down Expand Up @@ -106,16 +106,16 @@ def search(self, query: str, limit: int = 5, min_score: float = 0.0) -> list[Met
return search_results


def create_meta_filter_tool(index: ToolIndex) -> StackOneTool:
"""Create the meta_filter_relevant_tools tool
def create_meta_search_tools(index: ToolIndex) -> StackOneTool:
"""Create the meta_search_tools tool

Args:
index: Tool search index

Returns:
Meta tool for filtering relevant tools
Meta tool for searching relevant tools
"""
name = "meta_filter_relevant_tools"
name = "meta_search_tools"
description = (
"Searches for relevant tools based on a natural language query. "
"This tool should be called first to discover available tools before executing them."
Expand Down Expand Up @@ -180,8 +180,8 @@ def execute_filter(arguments: str | JsonDict | None = None) -> JsonDict:
)

# Create a wrapper class that delegates execute to our custom function
class MetaFilterTool(StackOneTool):
"""Meta tool for filtering relevant tools"""
class MetaSearchTool(StackOneTool):
"""Meta tool for searching relevant tools"""

def __init__(self) -> None:
super().__init__(
Expand All @@ -195,7 +195,7 @@ def __init__(self) -> None:
def execute(self, arguments: str | JsonDict | None = None) -> JsonDict:
return execute_filter(arguments)

return MetaFilterTool()
return MetaSearchTool()


def create_meta_execute_tool(tools_collection: Tools) -> StackOneTool:
Expand All @@ -210,7 +210,7 @@ def create_meta_execute_tool(tools_collection: Tools) -> StackOneTool:
name = "meta_execute_tool"
description = (
"Executes a tool by name with the provided parameters. "
"Use this after discovering tools with meta_filter_relevant_tools."
"Use this after discovering tools with meta_search_tools."
)

parameters = ToolParameters(
Expand Down
6 changes: 3 additions & 3 deletions stackone_ai/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,22 +486,22 @@ def meta_tools(self) -> "Tools":
Meta tools enable dynamic tool discovery and execution based on natural language queries.

Returns:
Tools collection containing meta_filter_relevant_tools and meta_execute_tool
Tools collection containing meta_search_tools and meta_execute_tool

Note:
This feature is in beta and may change in future versions
"""
from stackone_ai.meta_tools import (
ToolIndex,
create_meta_execute_tool,
create_meta_filter_tool,
create_meta_search_tools,
)

# Create search index
index = ToolIndex(self.tools)

# Create meta tools
filter_tool = create_meta_filter_tool(index)
filter_tool = create_meta_search_tools(index)
execute_tool = create_meta_execute_tool(self)

return Tools([filter_tool, execute_tool])
22 changes: 13 additions & 9 deletions tests/test_meta_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import responses

from stackone_ai import StackOneTool, Tools
from stackone_ai.meta_tools import ToolIndex, create_meta_execute_tool, create_meta_filter_tool
from stackone_ai.meta_tools import (
ToolIndex,
create_meta_execute_tool,
create_meta_search_tools,
)
from stackone_ai.models import ExecuteConfig, ToolParameters


Expand Down Expand Up @@ -128,21 +132,21 @@ def test_search_limit(self, sample_tools):
assert len(results) <= 3


class TestMetaFilterTool:
"""Test the meta_filter_relevant_tools functionality"""
class TestMetaSearchTool:
"""Test the meta_search_tools functionality"""

def test_filter_tool_creation(self, sample_tools):
"""Test creating the filter tool"""
index = ToolIndex(sample_tools)
filter_tool = create_meta_filter_tool(index)
filter_tool = create_meta_search_tools(index)

assert filter_tool.name == "meta_filter_relevant_tools"
assert filter_tool.name == "meta_search_tools"
assert "natural language query" in filter_tool.description.lower()

def test_filter_tool_execute(self, sample_tools):
"""Test executing the filter tool"""
index = ToolIndex(sample_tools)
filter_tool = create_meta_filter_tool(index)
filter_tool = create_meta_search_tools(index)

# Execute with a query
result = filter_tool.execute(
Expand All @@ -167,7 +171,7 @@ def test_filter_tool_execute(self, sample_tools):
def test_filter_tool_call(self, sample_tools):
"""Test calling the filter tool with call method"""
index = ToolIndex(sample_tools)
filter_tool = create_meta_filter_tool(index)
filter_tool = create_meta_search_tools(index)

# Call with kwargs
result = filter_tool.call(query="candidate", limit=2)
Expand Down Expand Up @@ -237,15 +241,15 @@ def test_meta_tools_creation(self, tools_collection):

# Check tool names
tool_names = [tool.name for tool in meta_tools.tools]
assert "meta_filter_relevant_tools" in tool_names
assert "meta_search_tools" in tool_names
assert "meta_execute_tool" in tool_names

def test_meta_tools_functionality(self, tools_collection):
"""Test that meta tools work correctly"""
meta_tools = tools_collection.meta_tools()

# Get the filter tool
filter_tool = meta_tools.get_tool("meta_filter_relevant_tools")
filter_tool = meta_tools.get_tool("meta_search_tools")
assert filter_tool is not None

# Search for tools
Expand Down