Agent loop: be robust to non-JSON tool args strings

If tool_args_raw is not valid JSON at all (e.g. parser/provider passed
through a plain string like ls), normalize it into {command: ...} for
terminal or {input: ...} for other tools instead of dropping args.
This commit is contained in:
Shannon Sands 2026-02-14 09:28:23 +10:00
parent a2312076da
commit 33a00d9b8e

View file

@ -246,7 +246,11 @@ class HermesAgentLoop:
try:
decoded = json.loads(tool_args_raw)
except json.JSONDecodeError:
return {}, False
# Not valid JSON at all. Be robust: treat it as a plain string.
# (Some parsers/providers may pass through non-JSON strings.)
if tool_name == "terminal":
return {"command": tool_args_raw}, False
return {"input": tool_args_raw}, False
# Canonical case: decoded is already a dict
if isinstance(decoded, dict):