Five components of agent memory in plain Markdown

April 25, 2026·IWE Team

Most agent-memory setups nail two or three of the five things memory has to do. Here’s the full five — persistence, structure, retrieval, writeback, forgetting — each mapped to plain Markdown files you can read and edit.

This post lays out the mental model we use for agent memory in IWE: what the five components are, how each one maps to the tool, and where the design is still evolving. For the underlying idea — one Markdown knowledge base shared by you and your agent — start with Markdown knowledge graph for humans and agents.

The problem

Most agent memory implementations cover two or three of five necessary components. Vector databases give you retrieval but the stored representation is opaque. Prompt files like .cursorrules or CLAUDE.md give you persistence and a thin slice of structure, but no retrieval beyond “dump the whole file into context” and no way for the agent to write back. Conversation history scrolls past the context window and is gone.

1. Persistence

Memory is .md files in a directory you choose. It survives sessions, restarts, OS reinstalls, and IWE itself — uninstall the binary and your memory is still there, readable in any text editor. Git versions it. rsync backs it up. grep searches it. There’s no migration path because there’s nothing to migrate from.

2. Structure

The structure is the graph. Three mechanisms create it:

Inclusion links — a Markdown link on its own line defines a parent-child relationship:

# Platform

[Auth flow](auth-flow.md)

[Rate limiting](rate-limiting.md)

Multiple parents — rate-limiting.md can be a child of both platform.md and billing.md without duplication. Real knowledge doesn’t fit in a tree.

Inline links — a link within a paragraph creates a cross-reference without hierarchy:

The auth flow uses [JWT tokens](jwt.md) with a 15-minute expiry.

What structured memory needs — entities, facts, decisions, relationships — maps directly to notes and links:

Memory conceptIWE representation
EntityA note
FactA section within a note
DecisionA note linked from the project that made it
RelationshipAn inclusion link or inline link
CategoryA note whose body is inclusion links to members
Temporal contextgit log on the file

3. Retrieval

IWE exposes the graph through a query language that reads like Mongo’s filter syntax but runs against Markdown files:

iwe find --fuzzy "authentication"                       # fuzzy search across titles
iwe find --filter 'status: draft, priority: {$gte: 8}'  # frontmatter predicates
iwe find --included-by projects/alpha:0                 # everything under alpha's subtree
iwe find --included-by projects/alpha:0 \
         --references people/dmytro \
         --filter 'status: draft'                       # compose structure + fields

The filter operators are the ones you already know: $eq, $ne, $in, $gt/$gte/$lt/$lte, $exists, $and, $or, $not. On top of that, four structural anchors walk the graph’s two edge types: --includes, --included-by for hierarchy, --references, --referenced-by for cross-references. Stack them to compose multi-edge queries — “drafts under this project that mention this person” is three flags, not a join.

For navigating, retrieve fetches a note plus its descendants to a given depth, tree shows the hierarchy, squash flattens a subtree into one document. Projection (--project title,status), sorting (--sort modified_at:-1), and limits round it out. count gives you an integer instead of results.

Retrieval is deterministic graph traversal, not similarity search. The structure the human wrote is the retrieval signal. When the agent gets wrong context, you trace which link brought it in and fix the graph. (For why some questions are lookups rather than retrievals at all, see Structured questions need a query layer. The same surface, seen from the database angle, is Markdown as a database.)

4. Writeback

The agent writes back the same way you do. Create a note, link it in, done. But writeback goes further than append-only — the same query language that drives reads also drives mutations:

iwe update -k meeting-notes --set status=reviewed --set priority=3
iwe update --filter 'status: draft, reviewed: true' \
           --set status=published \
           --unset draft_notes

update takes a filter or a key, applies --set and --unset to every match, and rewrites the frontmatter in place. The agent can promote a batch of drafts, tag a set of notes, or adjust priorities across a project — the same filter it used to find the notes is the one it uses to change them.

The MCP server exposes the same operations as tools: create, update, extract (split a section into its own note), inline (pull a referenced note back in), attach (link a note under a new parent). extract and inline let the agent refactor memory the same way a developer refactors code — a note that’s grown too long gets split, small notes that belong together get inlined into a summary.

This is what separates real memory from RAG: the agent can read, write, query, and restructure. One source of truth, no sync layer.

5. Forgetting

The hardest component. IWE has a first-class delete with the same filter language:

iwe delete --filter 'status: archived'
iwe delete --filter '{type: scratch, modified: {$lt: "2026-01-01"}}'

Delete is reference-aware: inclusion links to removed notes are cleaned up automatically, inline links are flattened to plain text. Nothing dangles. --dry-run previews without writing. Git means nothing is truly lost — deletions are commits you can reverse.

The full forgetting loop: iwe stats surfaces orphan nodes, dead links, and graph density. iwe find --roots shows unlinked documents — candidates for archival. extract and inline let you summarize subtrees into higher-level notes and archive the details. delete prunes what’s no longer needed. The agent can run this loop autonomously: find stale notes, summarize, prune, commit.

Not as elegant as automatic temporal decay, but every step is auditable and reversible.

Getting started

MCP (Claude Code, Cursor):

{
  "mcpServers": {
    "iwe": {
      "command": "iwec",
      "cwd": "/path/to/your/notes"
    }
  }
}

CLI (any agent with shell access):

iwe find --fuzzy "query"
iwe retrieve -k key --expand-includes 2
iwe new "Title" --content "..."

From scratch: iwe init creates .iwe/config.toml. Start writing Markdown with links. The graph forms from the links.

What’s next

  • Context budgeting — letting the agent specify a token budget so expansion doesn’t overshoot
  • Automatic orphan detection — surfacing stale notes based on graph position and git history
  • Richer MCP operations — more graph traversal tools for autonomous agent navigation

Of the five, forgetting is where the design is least settled — and where the model is most likely to change.

Search

Loading pages…