From 9d2e1124555f2c8b2a450b85b7b2ca7cba5f88f0 Mon Sep 17 00:00:00 2001 From: teknium1 Date: Mon, 16 Mar 2026 06:31:46 -0700 Subject: [PATCH] =?UTF-8?q?feat:=20improve=20memory=20prioritization=20?= =?UTF-8?q?=E2=80=94=20user=20preferences=20over=20procedural=20knowledge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Inspired by OpenAI Codex's memory prompt improvements (openai/codex#14493) which focus memory writes on user preferences and recurring patterns rather than procedural task details. Key insight: 'Optimize for reducing future user steering — the most valuable memory prevents the user from having to repeat themselves.' Changes: - MEMORY_GUIDANCE (prompt_builder.py): added prioritization hierarchy and the core principle about reducing user steering - MEMORY_SCHEMA (memory_tool.py): reordered WHEN TO SAVE list to put corrections first, added explicit PRIORITY guidance - Memory nudge (run_agent.py): now asks specifically about preferences, corrections, and workflow patterns instead of generic 'anything' - Memory flush (run_agent.py): now instructs to prioritize user preferences and corrections over task-specific details --- agent/prompt_builder.py | 12 +++++++++--- run_agent.py | 8 +++++--- tools/memory_tool.py | 4 +++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/agent/prompt_builder.py b/agent/prompt_builder.py index 06d636320e7..2b4720fd887 100644 --- a/agent/prompt_builder.py +++ b/agent/prompt_builder.py @@ -73,9 +73,15 @@ DEFAULT_AGENT_IDENTITY = ( MEMORY_GUIDANCE = ( "You have persistent memory across sessions. Save durable facts using the memory " "tool: user preferences, environment details, tool quirks, and stable conventions. " - "Memory is injected into every turn, so keep it compact. Do NOT save task progress, " - "session outcomes, or completed-work logs to memory; use session_search to recall " - "those from past transcripts." + "Memory is injected into every turn, so keep it compact and focused on facts that " + "will still matter later.\n" + "Prioritize what reduces future user steering — the most valuable memory is one " + "that prevents the user from having to correct or remind you again. " + "User preferences and recurring corrections matter more than procedural task details.\n" + "Do NOT save task progress, session outcomes, completed-work logs, or temporary TODO " + "state to memory; use session_search to recall those from past transcripts. " + "If you've discovered a new way to do something, solved a problem that could be " + "necessary later, save it as a skill with the skill tool." ) SESSION_SEARCH_GUIDANCE = ( diff --git a/run_agent.py b/run_agent.py index 8a4147a8b09..01c4ae2aae0 100644 --- a/run_agent.py +++ b/run_agent.py @@ -3542,7 +3542,8 @@ class AIAgent: flush_content = ( "[System: The session is being compressed. " - "Please save anything worth remembering to your memories.]" + "Save anything worth remembering — prioritize user preferences, " + "corrections, and recurring patterns over task-specific details.]" ) _sentinel = f"__flush_{id(self)}_{time.monotonic()}" flush_msg = {"role": "user", "content": flush_content, "_flush_sentinel": _sentinel} @@ -4541,8 +4542,9 @@ class AIAgent: self._turns_since_memory += 1 if self._turns_since_memory >= self._memory_nudge_interval: user_message += ( - "\n\n[System: You've had several exchanges in this session. " - "Consider whether there's anything worth saving to your memories.]" + "\n\n[System: You've had several exchanges. Consider: " + "has the user shared preferences, corrected you, or revealed " + "something about their workflow worth remembering for future sessions?]" ) self._turns_since_memory = 0 diff --git a/tools/memory_tool.py b/tools/memory_tool.py index f77e8116b97..d7950d38cbd 100644 --- a/tools/memory_tool.py +++ b/tools/memory_tool.py @@ -439,11 +439,13 @@ MEMORY_SCHEMA = { "Memory is injected into future turns, so keep it compact and focused on facts " "that will still matter later.\n\n" "WHEN TO SAVE (do this proactively, don't wait to be asked):\n" + "- User corrects you or says 'remember this' / 'don't do that again'\n" "- User shares a preference, habit, or personal detail (name, role, timezone, coding style)\n" "- You discover something about the environment (OS, installed tools, project structure)\n" - "- User corrects you or says 'remember this' / 'don't do that again'\n" "- You learn a convention, API quirk, or workflow specific to this user's setup\n" "- You identify a stable fact that will be useful again in future sessions\n\n" + "PRIORITY: User preferences and corrections > environment facts > procedural knowledge. " + "The most valuable memory prevents the user from having to repeat themselves.\n\n" "Do NOT save task progress, session outcomes, completed-work logs, or temporary TODO " "state to memory; use session_search to recall those from past transcripts.\n" "If you've discovered a new way to do something, solved a problem that could be "