#6560·deepagents

MemoryMiddleware cannot distinguish project-authored AGENTS.md instructions from learned memory

Author: ChampionsZhangCreated Sep 26, 2026Updated Sep 26, 2026
Labelstype:bugpackage:deepagentsorg:externalpriority:backlogpackage:dcodetopic:memory

Submission checklist

  • This is a bug, not a usage question.
  • I added a clear and descriptive title.
  • I searched existing issues and didn't find this.
  • I can reproduce this with the latest released version.
  • I included a minimal reproducible example and steps to reproduce.

Area (Required)

  • deepagents (SDK)
  • dcode
  • talon
  • acp
  • evals
  • daytona
  • modal
  • quickjs
  • runloop
  • vercel
  • langsmith-sandbox
  • Other / not sure / general

Related Issues / PRs

Related: #5720, PR #5717, #6502.

This issue is related to, but narrower than, the broader ownership problem discussed in #5720 and PR #5717:

  • #5720 discusses ownership and context-budget boundaries for persistent memory.
  • PR #5717 explores read-only vs writable semantics at the source/file level.
  • This issue focuses specifically on how project-authored instructions and learned memory are represented when they coexist inside the same AGENTS.md file.
  • #6502 discusses eager memory writing and bounded/progressive loading. That is a related loading-policy problem, but not the change proposed here.

Description

MemoryMiddleware currently loads the full contents of an AGENTS.md source into <agent_memory>.

That is compatible with using AGENTS.md as persistent project context, but it creates a representation ambiguity when the same file contains both:

  1. Project/user-authored instructions

    • repository conventions
    • build/test requirements
    • stable constraints
    • other explicitly authored project guidance
  2. Agent-learned memory

    • preferences learned during use
    • corrections
    • reusable observations
    • other knowledge written back by the agent

These two categories have different semantics and lifecycle expectations, but today they share the same representation inside MemoryMiddleware.

The problem is not that project-authored instructions should disappear from the model context. They can be valid and useful agent-facing system context.

The problem is that there is currently no explicit representation boundary between authored instructions and agent-learned memory when both occupy the same file.

Released behavior reproduction

I reproduced this through the real create_cli_agent() wiring rather than manually constructing a MemoryMiddleware prompt.

The released baseline uses:

deepagents-code==0.1.77
source commit: dcf4febea597a876043f0aea6ecae40c321ea541
Python: 3.12.14

The harness uses a fake model, so no provider API key or external model is required.

It builds the real CLI agent, invokes it, and records the actual model-visible system content blocks.

Default memory-enabled case

create_cli_agent() has enable_memory=True by default.

The release trace uses the actual repository as the project root, so the repository AGENTS.md is automatically discovered:

/reproduction-workspace/deepagents-release/AGENTS.md

The captured model-visible prompt contains repository-authored content such as:

# Global development guidelines for the Deep Agents monorepo

## PR conventions

#### Warnings are errors

inside <agent_memory>.

Conceptually:

<agent_memory>

/reproduction-workspace/deepagents-release/AGENTS.md

# Global development guidelines for the Deep Agents monorepo

...

## PR conventions

...

#### Warnings are errors

...

</agent_memory>

Memory-disabled control

Running the same released CLI wiring with:

python
enable_memory=False

removes that memory path.

The paired trace contains no <agent_memory> block, and none of the three repository probes above are present.

The release pair therefore demonstrates:

default CLI memory path
    → discovers project AGENTS.md
    → loads the whole file through MemoryMiddleware
    → repository-authored instructions appear inside <agent_memory>

same wiring with memory disabled
    → those contents do not enter through the memory path

The automatic discovery in this reproduction belongs to the CLI wiring.

The whole-file representation once a source is loaded belongs to SDK MemoryMiddleware.

Why this distinction matters

Authored instructions and learned memory have different semantics.

Conceptually:

project-authored instructions
    authored by: user / repository
    purpose: stable agent-facing requirements and constraints
    lifecycle: explicitly maintained

agent-learned memory
    produced by: agent during use
    purpose: reusable learned information
    lifecycle: may evolve as the agent learns

When both are represented as one undifferentiated memory payload, later memory lifecycle work has no explicit representation-level boundary to operate on.

For example, future work on:

  • compaction;
  • consolidation;
  • progressive loading;
  • hot/cold memory separation;
  • pruning;
  • migration;

would benefit from being able to identify learned memory independently from authored instructions.

This issue does not claim that the prototype below provides filesystem-level ownership or write protection.

It establishes a representation / prompt boundary only.

The broader permission and ownership problem remains covered by #5720 and PR #5717.

Candidate representation

One compatibility-preserving option is to allow an AGENTS.md file to opt into an explicit learned-memory region.

For example:

markdown
# Project instructions

Use Conventional Commits.

<!-- deepagents:memory:start -->
## Durable memory

MEMORY_SENTINEL: Prefer concise answers.
<!-- deepagents:memory:end -->

#### Warnings are errors

Run the unit tests with warnings treated as errors.

The intended representation is:

outside the markers
    → authored system context

inside the markers
    → learned memory inside <agent_memory>

I implemented this candidate locally and captured it through the same real create_cli_agent() wiring.

The candidate traces use:

combined candidate commit:
a1e276d04792b1b7fb006ddc505df6a369450d36

based on upstream:
0bacb9fb1814ec2168e35efd7f4ebba7d330d741

Python:
3.12.14

The proposed changes are split into PRs #6561 and #6562.

Candidate trace: structured AGENTS.md

The structured fixture contains:

markdown
# Global development guidelines for the Deep Agents monorepo

## PR conventions

Use Conventional Commits.

<!-- deepagents:memory:start -->
## Durable memory

MEMORY_SENTINEL: Prefer concise answers.
<!-- deepagents:memory:end -->

#### Warnings are errors

Run the unit tests with warnings treated as errors.

The captured prompt shows that:

  • Global development guidelines remains model-visible;
  • PR conventions remains model-visible;
  • Warnings are errors remains model-visible;
  • only the marked durable-memory content appears inside <agent_memory>;
  • the boundary markers themselves are not exposed in the memory block.

The learned-memory block is:

<agent_memory>

/reproduction-workspace/evidence-v5/fixtures/structured/AGENTS.md

## Durable memory

MEMORY_SENTINEL: Prefer concise answers.

</agent_memory>

The authored instructions remain present in separate system content outside that block.

This is the main behavior the candidate is intended to establish.

Candidate trace: legacy compatibility

The legacy fixture has no markers:

markdown
# Global development guidelines for the Deep Agents monorepo

## PR conventions

Use Conventional Commits.

## Durable memory

MEMORY_SENTINEL: Prefer concise answers.

#### Warnings are errors

Run the unit tests with warnings treated as errors.

Under the candidate implementation, the full file still appears inside <agent_memory>.

So existing unstructured files preserve the current whole-file memory-loading/classification behavior:

no markers
    → whole-file memory semantics

The candidate therefore does not automatically reinterpret existing unmarked AGENTS.md files.

Candidate trace: empty learned-memory section

The empty fixture contains:

markdown
# Global development guidelines for the Deep Agents monorepo

## PR conventions

Use Conventional Commits.

<!-- deepagents:memory:start -->
<!-- deepagents:memory:end -->

#### Warnings are errors

Run the unit tests with warnings treated as errors.

The captured prompt shows that the authored instructions remain model-visible outside <agent_memory>.

The memory block becomes:

<agent_memory>

(No memory loaded)

</agent_memory>

The normal memory capability guidance remains present.

This intentionally means:

memory enabled + empty learned-memory section

is not identical to:

memory disabled

An enabled memory capability can reasonably add memory-specific guidance even when there is no learned memory yet.

The issue here is the representation of authored content, not whether memory capability instructions exist.

Summary of captured evidence

Trace Input and result
release-default.json Released deepagents-code==0.1.77; default memory enabled; repository AGENTS.md automatically discovered; project development guidelines appear inside <agent_memory>
release-disabled.json Same release and repository; enable_memory=False; those guidelines do not enter through memory
patched-structured.json Candidate + structured fixture; authored instructions remain system-visible outside <agent_memory>; only MEMORY_SENTINEL enters the memory block
patched-legacy.json Candidate + unmarked legacy fixture; full file retains legacy memory-loading behavior
patched-empty.json Candidate + empty memory section; authored instructions remain visible; memory shows (No memory loaded) and retains memory guidance

The first two traces form the paired released-version reproduction.

The other three test distinct candidate inputs and are not intended as byte-for-byte comparisons with the released prompt.

Reproduction harness

The attached capture_cli_trace.py:

  • imports the real create_cli_agent();
  • creates a real ProjectContext;
  • uses project_agent_md_paths() for project discovery;
  • constructs the actual CLI agent;
  • invokes it using a GenericFakeChatModel;
  • captures the system messages the model receives;
  • records the individual model-visible content blocks;
  • records discovered project paths, source commit, Python version, requested memory mode, and probe matches.

Example candidate reproduction:

bash
python capture_cli_trace.py \
  --source-root /path/to/deepagents-at-candidate-commit \
  --project-root /path/to/fixtures/structured \
  --scratch /tmp/deepagents-memory-repro \
  --output /tmp/structured.json \
  --memory default

--memory default intentionally omits the enable_memory argument so the CLI default is exercised.

--memory disabled explicitly passes:

python
enable_memory=False

For the released baseline, the release checkout is used as both --source-root and --project-root, so its real repository AGENTS.md is automatically discovered.

Possible approaches

Option A: structured AGENTS.md

Keep authored instructions and learned memory in the same file, but make the learned region explicit:

markdown
# Authored project instructions

...

<!-- deepagents:memory:start -->

learned memory

<!-- deepagents:memory:end -->

...

Advantages:

  • minimal API change;
  • existing unmarked files retain their current whole-file memory-loading/classification behavior;
  • users can opt in gradually;
  • authored and learned content can remain colocated.

The current candidate implements this approach.

Its writing discipline is currently prompt-based: the agent is instructed to read the file and keep learned-memory writes inside the marked section while preserving the surrounding content.

The markers do not enforce filesystem write permissions.

This representation also changes the prompt trust semantics of marker-external content: once it is moved outside <agent_memory>, it is no longer covered by the memory-specific trust and verification guidance. If authored project instructions should retain a different trust level, that may need an explicit representation of its own.

Option B: separate authored instructions and learned memory physically

Another approach is to use distinct storage surfaces:

AGENTS.md / instruction source
    → project-authored instructions

separate memory file or tree
    → learned writable memory

This creates a stronger physical distinction.

It may also be a better foundation for later memory organization such as bounded hot memory plus larger on-demand memory files.

The tradeoff is a broader compatibility/API change.

I do not think the marker-based candidate must necessarily be the final design.

It is primarily a concrete implementation demonstrating that the representations can be separated while preserving legacy whole-file loading for unmarked files.

Relationship to #5720

#5720 discusses the broader ownership and context-budget problem.

Its ownership side asks how user/application-authored instructions can be distinguished and protected from agent-owned writable memory.

PR #5717 explores that at the source level, including read-only vs writable source semantics.

This issue is narrower:

If authored instructions and learned memory coexist within one AGENTS.md, how should they be represented separately to the model?

The candidate addresses that intra-file representation question.

It does not replace #5720's permission or context-budget work.

Relationship to PR #5717

PR #5717 explores:

read-only source
vs
writable source

That answers:

Which source may the agent modify?

This issue asks:

Within one source, which content is authored project context and which content is learned memory?

These are complementary boundaries.

The structured candidate remains prompt-enforced and does not make marker-external content technically immutable.

Relationship to #6502

#6502 discusses:

  • eager memory-writing guidance;
  • memory growth;
  • bounded/progressive loading.

That is a separate lifecycle/loading problem.

However, progressive loading or future hot/cold organization benefits from first identifying which content is actually learned memory.

Otherwise project-authored instructions stored in the same file may be swept into learned-memory lifecycle policies.

This issue therefore provides a representation boundary that could support later loading work without proposing that work here.

Scope

This issue does not propose:

  • hot/cold memory implementation;
  • semantic retrieval;
  • vector search;
  • automatic compaction;
  • token-budget handling;
  • memory consolidation;
  • filesystem permission enforcement;
  • changing the whole-file loading/classification behavior of existing unmarked AGENTS.md files.

The requested design question is narrower:

Establish an explicit representation boundary between project-authored instructions and agent-learned memory when both coexist in the same AGENTS.md.

Candidate implementation

A concrete implementation is available in:

  • #6561 — SDK structured-memory parsing, prompt integration, and regression tests
  • #6562 — dcode prompt guidance for keeping writes inside marked memory sections

Both PRs were automatically closed by the repository contribution-policy bot because this issue had not yet been approved and assigned.

They were not closed following maintainer code review.

If maintainers prefer the structured representation, I can update/reopen the implementation after assignment.

If a physically separate instruction/memory surface is preferred, I am also happy to adapt the implementation in that direction.

The goal is not to mandate the marker syntax.

The goal is to make these two concepts distinguishable:

project-authored instructions

and:

agent-learned memory

within the current AGENTS.md workflow.

Evidence

Attached:

deepagents-agents-memory-evidence-clean.zip

The archive contains:

  • README.md
  • capture_cli_trace.py
  • fixtures/legacy/AGENTS.md
  • fixtures/structured/AGENTS.md
  • fixtures/empty-section/AGENTS.md
  • traces/release-default.json
  • traces/release-disabled.json
  • traces/patched-structured.json
  • traces/patched-legacy.json
  • traces/patched-empty.json

The ZIP contains evidence only; it does not contain the implementation patch.

Published trace paths are normalized to:

/reproduction-workspace

while preserving the prompt content and content-block boundaries.

deepagents-agents-memory-evidence-clean.zip