Skip to content
Open
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
8 changes: 5 additions & 3 deletions python/src/agent_squad/utils/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,13 @@ def _get_tool_use_block(
return None

async def _process_tool(self, tool_name, input_data):
tool = next((tool for tool in self.tools if tool.name == tool_name), None)
if tool is None:
return f"Tool '{tool_name}' not found"
try:
tool = next(tool for tool in self.tools if tool.name == tool_name)
return await tool.func(**input_data)
except StopIteration:
return f"Tool '{tool_name}' not found"
except Exception as e:
return f"Error processing tool '{tool_name}': {e}"

def to_claude_format(self) -> list[dict[str, Any]]:
"""Convert all tools to Claude format"""
Expand Down
27 changes: 19 additions & 8 deletions python/src/tests/utils/test_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,25 @@ def test_tool_with_properties():

@pytest.mark.asyncio
async def test_tool_not_found():
try:
tools = AgentTools([AgentTool(
name="weather",
func=fetch_weather_data
)])
await tools._process_tool("test", {'test':'value'})
except Exception as e:
assert str(e) == f"Tool weather not found"
tools = AgentTools([AgentTool(
name="weather",
func=fetch_weather_data
)])
result = await tools._process_tool("test", {'test': 'value'})
assert result == "Tool 'test' not found"


@pytest.mark.asyncio
async def test_tool_processing_error():
async def failing_tool(value: str):
raise ValueError("boom")

tools = AgentTools([AgentTool(
name="failing",
func=failing_tool
)])
result = await tools._process_tool("failing", {'value': 'x'})
assert result == "Error processing tool 'failing': boom"


def test_get_tool_use_block():
Expand Down