fix(sdk): align MemoryMiddleware prompt with investigate-first agent behavior#2461
Open
Adem Boukhris (AdemBoukhris457) wants to merge 1 commit intolangchain-ai:mainfrom
Open
Conversation
…e-first Add trust/verification guidance for loaded memory files. Replace absolute memory-before-all-tools wording with prompt updates after essential reads. Refresh smoke snapshot; add unit test for prompt content.
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
MemoryMiddlewareinjectsMEMORY_SYSTEM_PROMPTinto the system message on every model call. The old text told the model that learning from the user was a MAIN PRIORITY and that updating memory withedit_filehad to be the FIRST, IMMEDIATE action before responding to the user, before calling other tools, before doing anything else.That clashed with the default deep agent instructions in
BASE_AGENT_PROMPT(“Understand first”, read relevant files and gather evidence before acting). In the same turn, the model could be pulled toward writing memory first even when the task required reads or investigation first.Also, whatever appears inside
<agent_memory>comes from files on disk. The prompt treated that block as something to learn from and update, but did not say that file text can be wrong, stale, or adversarial. So imperative text insideAGENTS.md-style files was easy to treat like trusted “system” rules, which weakens defenses against prompt injection via memory files.What we changed
read_file(and other tools) when memory disagrees.system_prompt_with_memory_and_skillsand added a unit test that asserts the new trust/investigation wording and the absence of the oldFIRST, IMMEDIATE/before doing anything elselines.Fixes #2460