mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-29 06:31:32 +00:00
fix(acp): treat polished tool error payloads as failed
This commit is contained in:
parent
b38d2d133b
commit
9cf1140caa
2 changed files with 13 additions and 2 deletions
|
|
@ -202,7 +202,7 @@ def _json_loads_maybe(value: Optional[str]) -> Any:
|
|||
return None
|
||||
|
||||
|
||||
def _tool_result_failed(result: Optional[str]) -> bool:
|
||||
def _tool_result_failed(result: Optional[str], tool_name: str | None = None) -> bool:
|
||||
"""Return True when a structured Hermes tool result clearly failed.
|
||||
|
||||
Keep this deliberately conservative. Plain text can contain words like
|
||||
|
|
@ -221,6 +221,13 @@ def _tool_result_failed(result: Optional[str]) -> bool:
|
|||
if isinstance(exit_code, int) and exit_code != 0:
|
||||
return True
|
||||
|
||||
# Hermes core/polished tools commonly report tool-level failures as a
|
||||
# structured {"error": "..."} payload without an explicit success flag.
|
||||
# Keep generic plugin/unknown tool payloads conservative to avoid marking
|
||||
# optional diagnostic messages as failed.
|
||||
if tool_name in _POLISHED_TOOLS and data.get("error") and not data.get("content"):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
|
|
@ -1318,7 +1325,7 @@ def build_tool_complete(
|
|||
return acp.update_tool_call(
|
||||
tool_call_id,
|
||||
kind=kind,
|
||||
status="failed" if _tool_result_failed(result) else "completed",
|
||||
status="failed" if _tool_result_failed(result, tool_name) else "completed",
|
||||
content=content,
|
||||
raw_output=None if tool_name in _POLISHED_TOOLS or _is_structured_json_result(result) else result,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -365,6 +365,10 @@ class TestBuildToolComplete:
|
|||
result = build_tool_complete("tc-ok", "terminal", "tests failed: 1 assertion error")
|
||||
assert result.status == "completed"
|
||||
|
||||
def test_build_tool_complete_marks_structured_polished_tool_error_as_failed(self):
|
||||
result = build_tool_complete("tc-fail", "read_file", '{"error": "File not found"}')
|
||||
assert result.status == "failed"
|
||||
|
||||
def test_build_tool_complete_keeps_json_error_without_failure_flag_completed(self):
|
||||
result = build_tool_complete("tc-ok", "some_tool", '{"error": "timeout while reading optional source"}')
|
||||
assert result.status == "completed"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue