The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(memory): report single patch results consistently
Yuan Li73808abcd704
diff --git a/agent/memory_manager.py b/agent/memory_manager.pyindex 2252311eeb8..2de403ac5f3 100644--- a/agent/memory_manager.py+++ b/agent/memory_manager.py@@ -915,6 +915,8 @@ class MemoryManager:previous = entries.get(str(index), entries.get(index)) if isinstance(entries, dict) else Noneelse:previous = result.get(f"{field}_entry")+ if field == "patched" and previous is None:+ previous = result.get("patched_entry_before")if isinstance(previous, str) and previous:metadata["previous_content"] = previousself.on_memory_write(action, target, str(op.get("content") or op.get("new_text") or ""), metadata=metadata)diff --git a/hermes_cli/write_approval_commands.py b/hermes_cli/write_approval_commands.pyindex e3fbd181330..92701022762 100644--- a/hermes_cli/write_approval_commands.py+++ b/hermes_cli/write_approval_commands.py@@ -104,9 +104,10 @@ def _approve(subsystem: str, rest: list[str], memory_store) -> str:def _changed_entries(result: dict, kind: str) -> list[str]:- """Full text of every entry a memory replace overwrote (``kind="replaced"``) or remove- deleted (``"removed"``), single-op or batch shape."""+ """Full text of every entry a memory write changed, single-op or batch shape."""single = result.get(f"{kind}_entry")+ if kind == "patched" and single is None:+ single = result.get("patched_entry_before")batch = result.get(f"{kind}_entries") or {}return ([single] if single else []) + [batch[k] for k in sorted(batch, key=int)]diff --git a/tests/agent/test_memory_write_bridge.py b/tests/agent/test_memory_write_bridge.pyindex 650bf2a645b..2782b0ed2ae 100644--- a/tests/agent/test_memory_write_bridge.py+++ b/tests/agent/test_memory_write_bridge.py@@ -107,8 +107,10 @@ def test_build_metadata_callback_is_merged_per_op():@pytest.mark.parametrize('batch,operations,previous', [(False, [{'action': 'remove', 'old_text': 'Prefers tea'}], ['Prefers tea']),(False, [{'action': 'replace', 'old_text': 'Prefers tea', 'content': 'Prefers coffee'}], ['Prefers tea']),+ (False, [{'action': 'patch', 'old_text': 'Prefers tea', 'new_text': 'Prefers coffee'}], ['Prefers tea']),(True, [{'action': 'remove', 'old_text': 'Prefers tea'}], ['Prefers tea']),(True, [{'action': 'replace', 'old_text': 'Prefers tea', 'new_text': 'Prefers coffee'}], ['Prefers tea']),+ (True, [{'action': 'patch', 'old_text': 'Prefers tea', 'new_text': 'Prefers coffee'}], ['Prefers tea']),(True, [{'action': 'add', 'content': 'Uses the blue notebook'},{'action': 'replace', 'old_text': 'blue notebook', 'new_text': 'Uses the green notebook'},diff --git a/tests/tools/test_memory_patch_action.py b/tests/tools/test_memory_patch_action.pyindex 5bf130cb44d..362ad30cd16 100644--- a/tests/tools/test_memory_patch_action.py+++ b/tests/tools/test_memory_patch_action.py@@ -10,6 +10,7 @@ import pytestfrom tools.memory_tool import memory_toolfrom tools.memory_tool_store import MemoryStore+from hermes_cli.write_approval_commands import _changed_entriesPACKED = "todo: item A; item B; item C"@@ -23,6 +24,12 @@ def packed_store(tmp_path, monkeypatch):class TestPatchSingleOp:+ def test_single_patch_previous_entry_is_reported(self):+ assert _changed_entries({+ "patched_entry_before": PACKED,+ "patched_entry_after": "todo: item A; item B done; item C",+ }, "patched") == [PACKED]+def test_patch_splices_only_the_matched_span(self, packed_store):result = json.loads(memory_tool(action="patch", old_text="item B", new_text="item B done", store=packed_store))diff --git a/website/docs/user-guide/features/memory.md b/website/docs/user-guide/features/memory.mdindex 70d892a3a2a..70d2f3b2bc8 100644--- a/website/docs/user-guide/features/memory.md+++ b/website/docs/user-guide/features/memory.md@@ -93,6 +93,7 @@ The agent uses the `memory` tool with these actions:- **add** — Add a new memory entry- **replace** — Replace an existing entry with updated content (uses substring matching via `old_text`)+- **patch** — Replace matching text inside an existing entry while preserving the rest (uses `old_text` and `new_text`)- **remove** — Remove an entry that's no longer relevant (uses substring matching via `old_text`)There is no `read` action — memory content is automatically injected into the system prompt at session start. The agent sees its memories as part of its conversation context.