fix(agent): make tool error guidance neutral (#6227)

* fix(agent): make tool error guidance neutral

* refactor(tools): share tool error guidance
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-15 16:58:39 +08:00
1 parent c24153db86
commit 841d2b880c
5 files changed
+55 -33

No files matched your search

+19 -10
View File
@@ -56,16 +56,22 @@ async def test_runner_returns_tool_exception_to_model_for_recovery():
{"name": "list_dir", "status": "error", "detail": "boom"}
]
tool_message = next(message for message in result.messages if message.get("role") == "tool")
retry_hint = "[Analyze the error above and try a different approach.]"
error_hint = (
"[Consider this result in the context of the user's goal "
"and decide whether and how to proceed.]"
)
assert "Error: RuntimeError: boom" in tool_message["content"]
assert tool_message["content"].count(retry_hint) == 1
assert tool_message["content"].count(error_hint) == 1
@pytest.mark.asyncio
async def test_tool_execution_does_not_duplicate_existing_retry_hint():
retry_hint = "\n\n[Analyze the error above and try a different approach.]"
async def test_tool_execution_does_not_duplicate_existing_error_hint():
error_hint = (
"\n\n[Consider this result in the context of the user's goal "
"and decide whether and how to proceed.]"
)
tools = SimpleNamespace(
execute=AsyncMock(return_value=ToolResult.error("Error: boom" + retry_hint)),
execute=AsyncMock(return_value=ToolResult.error("Error: boom" + error_hint)),
)
results, events = await execute_tool_calls(
@@ -78,8 +84,8 @@ async def test_tool_execution_does_not_duplicate_existing_retry_hint():
context=AgentHookContext(iteration=0, messages=[]),
)
assert results == ["Error: boom" + retry_hint]
assert results[0].count(retry_hint) == 1
assert results == ["Error: boom" + error_hint]
assert results[0].count(error_hint) == 1
assert events[0]["status"] == "error"
@@ -300,15 +306,18 @@ async def test_runner_recognizes_web_fetch_errors(monkeypatch, url, ssrf):
content = tool_message["content"]
assert content.startswith(str(raw_error) + "\n\n")
assert json.JSONDecoder().raw_decode(content)[0] == raw_payload
retry_hint = "[Analyze the error above and try a different approach.]"
error_hint = (
"[Consider this result in the context of the user's goal "
"and decide whether and how to proceed.]"
)
if ssrf:
assert result.tool_events[0]["detail"].startswith("ssrf_violation:")
assert "non-bypassable security boundary" in content
assert "Do not retry" in content
assert "tools.ssrfWhitelist" in content
assert retry_hint not in content
assert error_hint not in content
else:
assert content.count(retry_hint) == 1
assert content.count(error_hint) == 1
@pytest.mark.asyncio