feat(memory): batch operations for single-turn memory updates (#48507)

The memory tool was strictly one-op-per-call. With the store running near
its char limit by design, a new add that would overflow gets rejected with
'consolidate now, then retry' -- but the model could not consolidate and add
in one call. It had to remove/replace across several turns, then retry the
add, each turn re-sending the whole conversation context. Expensive thrash.

Add an 'operations' array: a list of add/replace/remove ops applied
atomically against the FINAL char budget. The model frees space and adds new
entries in ONE call, even when an add alone would overflow. All-or-nothing:
any bad op aborts the whole batch, nothing written.

Root-cause note: the two agent-level memory interception sites
(agent_runtime_helpers.py, tool_executor.py) silently dropped any param not
in their explicit kwarg list, so 'operations' never reached the handler and
batch calls failed with 'Unknown action None'. Both now pass it through and
bridge each add/replace op to external memory providers.

Also: success response is now terminal (done=true + 'do not repeat' note,
no full-entries echo that invited re-edits); schema rewritten to lead with
the batch mechanism and an explicit one-shot stop rule (2138 -> 1476 chars).

Live-verified: near-full consolidate-and-add went 7 calls -> 1 call,
stable across 3 reps. 103 memory/approval tests + 398 background-review/
run_agent tests green; 6 new batch tests added.
This commit is contained in:
Teknium 2026-06-18 10:19:33 -07:00 committed by GitHub
parent 2fa16ec2d2
commit 38c8a9c10f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 417 additions and 60 deletions

View file

@ -39,10 +39,15 @@ def test_memory_schema_has_no_forbidden_top_level_combinators():
def test_memory_schema_is_well_formed():
params = MEMORY_SCHEMA["parameters"]
assert params["type"] == "object"
assert params["required"] == ["action", "target"]
# Only ``target`` is universally required: ``action`` belongs to the
# single-op shape and is omitted when the batch ``operations`` array is used.
assert params["required"] == ["target"]
# Nested ``enum`` on property values is fine — only top-level is forbidden.
assert params["properties"]["action"]["enum"] == ["add", "replace", "remove"]
assert params["properties"]["target"]["enum"] == ["memory", "user"]
# Batch shape is exposed and its items reuse the same actions.
assert params["properties"]["operations"]["type"] == "array"
assert params["properties"]["operations"]["items"]["properties"]["action"]["enum"] == ["add", "replace", "remove"]
def test_memory_schema_is_json_serializable():