The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: guard memory tool against missing action and operations (#64291)
AlexFucuson99cbd3e7d298c
diff --git a/tests/tools/test_memory_tool.py b/tests/tools/test_memory_tool.pyindex 5bce00017cc..da4bff3d56b 100644--- a/tests/tools/test_memory_tool.py+++ b/tests/tools/test_memory_tool.py@@ -436,6 +436,22 @@ class TestMemoryToolDispatcher:assert result["success"] is Falseassert "not available" in result["error"]+ def test_missing_action_and_operations_returns_actionable_error(self, store):+ # Neither the single-op 'action' nor the batch 'operations' was given:+ # the call must say what is missing instead of the opaque+ # "Unknown action 'None'" that invites blind retries (#64291).+ result = json.loads(memory_tool(target="memory", store=store))+ assert result["success"] is False+ assert "Missing required parameter" in result["error"]+ assert "action" in result["error"] and "operations" in result["error"]++ def test_null_action_and_operations_is_also_rejected(self, store):+ # Strict providers send JSON null for omitted optional fields.+ result = json.loads(memory_tool(action=None, operations=None, store=store))+ assert result["success"] is False+ assert "Missing required parameter" in result["error"]++def test_replace_missing_content_still_distinct_error(self, store):# When old_text IS present but content is missing, keep the originaldiff --git a/tools/memory_tool.py b/tools/memory_tool.pyindex a27d8cfc457..a768f015b18 100644--- a/tools/memory_tool.py+++ b/tools/memory_tool.py@@ -243,6 +243,16 @@ def _memory_tool(action, target, content, old_text, new_text, operations, store)if gate_result is not None:return "rejected", gate_resultreturn _applied(store.apply_batch(target, operations))+ # Reject calls that provide neither action (single-op) nor operations+ # (batch). Without this guard the dispatch falls through to the generic+ # "Unknown action 'None'" error, which gives the model no signal about+ # *why* the call was malformed and can trigger repeated retries. (#64291)+ if not action and not operations:+ return "rejected", tool_error(+ "Missing required parameter: provide 'action' (add/replace/remove) "+ "or 'operations' (batch list). Got neither.",+ success=False,+ )if action not in _STORE_ACTIONS:return "rejected", tool_error(f"Unknown action '{action}'. Use: add, replace, remove", success=False)invalid = (_validate_single_op(store, action, target, content, old_text)