fix(memory): instruct in-turn consolidation + retry on overflow (#41755)
* fix(memory): make overflow errors instruct in-turn consolidation + retry When bounded memory is full, the add/replace overflow errors now explicitly tell the model to consolidate (merge/remove/shorten) and retry the write in the same turn, matching the documented behavior. The replace-overflow path now also echoes current_entries + usage for parity with add-overflow, so the model has the same context to act on. Closes #23378 (working-as-documented; this sharpens runtime to match docs). * fix(memory): broaden overflow remediation hint beyond 'stale' Say 'stale or less important' — entries don't have to be stale to be the right ones to drop when making room.
This commit is contained in:
@@ -332,7 +332,9 @@ class MemoryStore:
|
||||
"error": (
|
||||
f"Memory at {current:,}/{limit:,} chars. "
|
||||
f"Adding this entry ({len(content)} chars) would exceed the limit. "
|
||||
f"Replace or remove existing entries first."
|
||||
f"Consolidate now: use 'replace' to merge overlapping entries into "
|
||||
f"shorter ones or 'remove' stale or less important entries (see "
|
||||
f"current_entries below), then retry this add — all in this turn."
|
||||
),
|
||||
"current_entries": entries,
|
||||
"usage": f"{current:,}/{limit:,}",
|
||||
@@ -390,12 +392,17 @@ class MemoryStore:
|
||||
new_total = len(ENTRY_DELIMITER.join(test_entries))
|
||||
|
||||
if new_total > limit:
|
||||
current = self._char_count(target)
|
||||
return {
|
||||
"success": False,
|
||||
"error": (
|
||||
f"Replacement would put memory at {new_total:,}/{limit:,} chars. "
|
||||
f"Shorten the new content or remove other entries first."
|
||||
f"Shorten the new content, or 'remove' other stale or less important "
|
||||
f"entries to make room (see current_entries below), then retry — all "
|
||||
f"in this turn."
|
||||
),
|
||||
"current_entries": entries,
|
||||
"usage": f"{current:,}/{limit:,}",
|
||||
}
|
||||
|
||||
entries[idx] = new_content
|
||||
|
||||
Reference in New Issue
Block a user