feat: add no-update sentinel handling to save_memory function and corresponding unit tests

This commit is contained in:
Anish Sarkar 2026-05-20 15:03:35 +05:30
parent 132e7b3c44
commit 8c9be9796a
2 changed files with 64 additions and 0 deletions

View file

@ -29,6 +29,15 @@ from app.services.memory.validation import (
logger = logging.getLogger(__name__)
_NO_UPDATE_SENTINELS = frozenset(
{
"NO_UPDATE",
"NO UPDATE",
"NO_CHANGE",
"NO CHANGE",
}
)
class MemoryScope(StrEnum):
USER = "user"
@ -149,6 +158,13 @@ async def save_memory(
notice: str | None = None
warnings: list[str] = []
if next_content.upper() in _NO_UPDATE_SENTINELS:
return SaveResult(
status="no_op",
message="No memory update requested.",
memory_md=old_memory,
)
if len(next_content) > MEMORY_HARD_LIMIT and llm is not None:
rewritten = await forced_rewrite(next_content, llm)
if rewritten is not None and len(rewritten) < len(next_content):