Skip to content

The agent that grows with you

fix(memory): memory schema advertises each field once (operations[] only)

Teknium38968d755266
diff --git a/tests/tools/test_memory_tool_schema.py b/tests/tools/test_memory_tool_schema.py
index a11a37b786e..4caba4b8954 100644
--- a/tests/tools/test_memory_tool_schema.py
+++ b/tests/tools/test_memory_tool_schema.py
@@ -17,7 +17,10 @@ These tests guard the schema against regressing back to a shape strict
backends reject.
"""
-from tools.memory_tool import MEMORY_SCHEMA
+import json
+
+from tools.memory_tool import MEMORY_SCHEMA, MemoryStore
+from tools.registry import registry
_FORBIDDEN_TOP_LEVEL_KEYS = ("allOf", "anyOf", "oneOf", "enum", "not")
@@ -30,3 +33,20 @@ def test_memory_schema_has_no_forbidden_top_level_combinators():
"Codex backend (chatgpt.com/backend-api/codex). Per-action "
"required-field checks belong in the runtime handler, not the schema."
)
+
+
+def test_each_memory_field_is_advertised_once_and_legacy_shapes_still_write(tmp_path, monkeypatch):
+ """The schema advertises one shape (target + operations[]) with no alias; the handler still
+ accepts the top-level single-op shape and the new_text alias models and transcripts send."""
+ params = MEMORY_SCHEMA["parameters"]
+ assert set(params["properties"]) == {"target", "operations"}
+ assert "new_text" not in json.dumps(params)
+
+ monkeypatch.setattr("tools.memory_tool.get_memory_dir", lambda: tmp_path)
+ store = MemoryStore(memory_char_limit=500, user_char_limit=300)
+ store.load_from_disk()
+ handler = registry.get_entry("memory").handler
+ assert json.loads(handler({"action": "add", "target": "memory", "new_text": "alpha fact"}, store=store))["success"]
+ batch = {"target": "memory", "operations": [{"action": "patch", "old_text": "alpha", "new_text": "beta"}]}
+ assert json.loads(handler(batch, store=store))["success"]
+ assert store.memory_entries == ["beta fact"]
diff --git a/tools/memory_tool.py b/tools/memory_tool.py
index aeb839a2e69..5c485066661 100644
--- a/tools/memory_tool.py
+++ b/tools/memory_tool.py
@@ -380,8 +380,7 @@ MEMORY_SCHEMA = {
"checked only on the FINAL result — so a single call can remove/patch stale entries "
"to free room AND add new ones, even when an add alone would overflow. The response "
"reports current/limit chars and confirms completion; one batch call finishes the "
- "update, so don't repeat it. Use the bare action/content/old_text fields only for a "
- "single lone change.\n\n"
+ "update, so don't repeat it.\n\n"
"WHEN: only for facts that apply to EVERY session regardless of task: who the user "
"is, stable environment facts, standing conventions with no task home. Anything "
"learned while doing a task (procedures, pitfalls, and the user's preferences and "
@@ -396,52 +395,45 @@ MEMORY_SCHEMA = {
"completed-work logs, temporary TODO state (use session_search for those). Reusable "
"procedures belong in a skill, not memory."
),
+ # Each field is advertised once, inside operations[]. The handler still ACCEPTS the
+ # top-level single-op shape (action/content/old_text) and the new_text alias: models
+ # drift and older transcripts replay them.
"parameters": {
"type": "object",
"properties": {
- "action": {
- "type": "string",
- "enum": ["add", "patch", "remove"],
- "description": "The action to perform (single-op shape). Omit when using 'operations'."
- },
"target": {
"type": "string",
"enum": ["memory", "user"],
"description": "Which memory store: 'memory' for personal notes, 'user' for user profile."
},
- "content": {
- "type": "string",
- "description": "Required for 'add' and 'patch'. For 'add', the new entry. For 'patch', the text that replaces old_text; the rest of the entry is kept. Alias: 'new_text'."
- },
- "old_text": {
- "type": "string",
- "description": "REQUIRED for 'patch' and 'remove': text from one entry. 'patch' replaces exactly this span (it must occur once in the entry); 'remove' deletes the whole entry. Omit for 'add'."
- },
- "new_text": {
- "type": "string",
- "description": "Alias for 'content'. If both are set, 'content' wins."
- },
"operations": {
"type": "array",
"description": (
- "Batch shape: a list of operations applied atomically in one call "
- "against the final char budget. Preferred when making multiple changes "
- "or consolidating to make room. Each item is {action, content?, old_text?}."
+ "Changes applied atomically in one call against the final char budget; "
+ "a single change is a one-item list."
),
"items": {
"type": "object",
"properties": {
"action": {"type": "string", "enum": ["add", "patch", "remove"]},
- "content": {"type": "string", "description": "Required for add and patch, as 'content' above."},
- "new_text": {"type": "string", "description": "Alias for 'content' in a batch op."},
- "old_text": {"type": "string", "description": "As 'old_text' above."},
+ "content": {
+ "type": "string",
+ "description": ("Required for 'add' and 'patch'. For 'add', the new entry. For 'patch', "
+ "the text that replaces old_text; the rest of the entry is kept."),
+ },
+ "old_text": {
+ "type": "string",
+ "description": ("REQUIRED for 'patch' and 'remove': text from one entry. 'patch' replaces "
+ "exactly this span (it must occur once in the entry); 'remove' deletes the "
+ "whole entry. Omit for 'add'."),
+ },
},
"required": ["action"],
"additionalProperties": False,
},
},
},
- "required": ["target"],
+ "required": ["target", "operations"],
},
}