Skip to content

The agent that grows with you

refactor(state): parse tool_calls inside _stable_tool_key only for assistant rows

kshitijk4poor272f2bf23097
diff --git a/hermes_state_identity.py b/hermes_state_identity.py
index bf62f07c573..712ed60e2a5 100644
--- a/hermes_state_identity.py
+++ b/hermes_state_identity.py
@@ -96,14 +96,16 @@ def _restore_identity_columns(row: Any, msg: MutableMapping[str, Any]) -> None:
msg[ABSORBED_MESSAGE_UIDS] = absorbed
-def _stable_tool_key(row: Any, calls: Any) -> Optional[Tuple[Any, ...]]:
+def _stable_tool_key(row: Any) -> Optional[Tuple[Any, ...]]:
"""Display-dedupe key of a tool-bearing row built from its stable call id(s) instead of the payload a prune
rewrites (#117750: a pruned carried-forward copy must collapse with its durable original). ``None`` when the
row has no complete id set, so the caller keeps the full content key and distinct id-less calls never merge."""
role = row["role"]
if role == "tool" and row["tool_call_id"]:
return (role, None, row["timestamp"], row["tool_call_id"], row["tool_calls"], row["tool_name"])
- call_ids = tuple(coalesce_tool_call_id(tc) for tc in calls or ()) if role == "assistant" else ()
+ calls = _json_or(row["tool_calls"] or "[]", [], "Failed to deserialize tool_calls, falling back to []") \
+ if role == "assistant" else ()
+ call_ids = tuple(coalesce_tool_call_id(tc) for tc in calls or ())
if call_ids and all(call_ids):
return (role, None, row["timestamp"], row["tool_call_id"], call_ids, row["tool_name"])
return None
diff --git a/hermes_state_messages.py b/hermes_state_messages.py
index 421e7f04117..12c1c7ba83c 100644
--- a/hermes_state_messages.py
+++ b/hermes_state_messages.py
@@ -1183,7 +1183,7 @@ class SessionMessagesMixin:
"display_metadata": self._decode_display_metadata(row["display_metadata"])})
if handoff is not None and live_view is not None:
dedupe_content = self._encode_content(live_view.get("content"))
- return _stable_tool_key(row, _parse_tool_calls(row["tool_calls"])) or (
+ return _stable_tool_key(row) or (
row["role"], dedupe_content, row["timestamp"], row["tool_call_id"], row["tool_calls"], row["tool_name"])
def _is_model_only_row(self, row) -> bool: