diff --git a/nanobot/utils/runtime.py b/nanobot/utils/runtime.py index dce75a195..2971ae128 100644 --- a/nanobot/utils/runtime.py +++ b/nanobot/utils/runtime.py @@ -98,7 +98,8 @@ def external_lookup_signature(tool_name: str, arguments: Any) -> str | None: if tool_name == "web_fetch": url = str(arguments.get("url") or "").strip() if url: - return f"web_fetch:{url.lower()}" + # URL paths and query values can identify different resources by case. + return f"web_fetch:{url}" if tool_name == "web_search": query = str(arguments.get("query") or arguments.get("search_term") or "").strip() if query: diff --git a/tests/agent/test_runner_tool_execution.py b/tests/agent/test_runner_tool_execution.py index d0fde4c99..c61c2f009 100644 --- a/tests/agent/test_runner_tool_execution.py +++ b/tests/agent/test_runner_tool_execution.py @@ -486,7 +486,12 @@ async def test_runner_preserves_structured_plugin_success_that_starts_with_error @pytest.mark.asyncio -async def test_runner_blocks_repeated_external_fetches(): +@pytest.mark.parametrize(("urls", "expected_fetches"), [ + (["https://example.com"] * 3, 2), + ([f"https://example.com/{path}" for path in ("API", "Api", "api")], 3), + ([f"https://example.com/?id={value}" for value in ("ABC", "Abc", "abc")], 3), +]) +async def test_runner_blocks_repeated_external_fetches(urls, expected_fetches): provider = MagicMock() captured_final_call: list[dict] = [] call_count = {"n": 0} @@ -496,7 +501,7 @@ async def test_runner_blocks_repeated_external_fetches(): if call_count["n"] <= 3: return LLMResponse( content="working", - tool_calls=[ToolCallRequest(id=f"call_{call_count['n']}", name="web_fetch", arguments={"url": "https://example.com"})], + tool_calls=[ToolCallRequest(id=f"call_{call_count['n']}", name="web_fetch", arguments={"url": urls[call_count['n'] - 1]})], usage=None, ) captured_final_call[:] = messages @@ -517,9 +522,12 @@ async def test_runner_blocks_repeated_external_fetches(): )) assert result.final_content == "done" - assert tools.execute.await_count == 2 + assert tools.execute.await_count == expected_fetches blocked_tool_message = [ msg for msg in captured_final_call if msg.get("role") == "tool" and msg.get("tool_call_id") == "call_3" ][0] - assert "repeated external lookup blocked" in blocked_tool_message["content"] + if expected_fetches == 2: + assert "repeated external lookup blocked" in blocked_tool_message["content"] + else: + assert blocked_tool_message["content"] == "page content"