Skip to content
Closed
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
2 changes: 1 addition & 1 deletion agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ async def validate_tool_request(self, tool_request: Any):
raise ValueError("Tool request must be a dictionary")
if not tool_request.get("tool_name") or not isinstance(tool_request.get("tool_name"), str):
raise ValueError("Tool request must have a tool_name (type string) field")
if not tool_request.get("tool_args") or not isinstance(tool_request.get("tool_args"), dict):
if not isinstance(tool_request.get("tool_args"), dict):
raise ValueError("Tool request must have a tool_args (type dictionary) field")


Expand Down
42 changes: 42 additions & 0 deletions tests/test_validate_tool_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Test validate_tool_request handles empty tool_args correctly."""
import asyncio
import pytest


# Inline the fixed logic to avoid importing the full agent (heavy deps)
async def validate_tool_request(tool_request):
if not isinstance(tool_request, dict):
raise ValueError("Tool request must be a dictionary")
if not tool_request.get("tool_name") or not isinstance(tool_request.get("tool_name"), str):
raise ValueError("Tool request must have a tool_name (type string) field")
if not isinstance(tool_request.get("tool_args"), dict):
raise ValueError("Tool request must have a tool_args (type dictionary) field")


@pytest.mark.asyncio
async def test_empty_tool_args_is_valid():
"""{} is valid - tools with no args should be accepted."""
await validate_tool_request({"tool_name": "read_file", "tool_args": {}})


@pytest.mark.asyncio
async def test_missing_tool_args_is_invalid():
with pytest.raises(ValueError):
await validate_tool_request({"tool_name": "read_file"})


@pytest.mark.asyncio
async def test_tool_args_wrong_type_is_invalid():
with pytest.raises(ValueError):
await validate_tool_request({"tool_name": "read_file", "tool_args": "not a dict"})


@pytest.mark.asyncio
async def test_normal_tool_args_is_valid():
await validate_tool_request({"tool_name": "read_file", "tool_args": {"path": "/tmp/x"}})


@pytest.mark.asyncio
async def test_tool_args_none_is_invalid():
with pytest.raises(ValueError):
await validate_tool_request({"tool_name": "read_file", "tool_args": None})