
Aki Wijesundara
Manu Jayawardana
What we will cover in this session.
Why memory is state, not retrieval
Types, storage, OKF, and patterns
How context gets spent and compacted
Write, consolidate, then retrieve
Keeping long-running tasks alive
When memory becomes an attack surface
Capstone prep and what good engineers do
Live walkthroughs throughout

The model is stateless by design. Memory is the layer you add so the agent can persist beyond a single call.
We are moving from a one-shot model API to an agent that must stay coherent across many turns and sessions.
The model has no built-in past. You rebuild the context from scratch on every request.
An external memory system holds what the model cannot keep inside its weights or a single window.

These two ideas fail differently, scale differently, and cost differently. Treat them as separate systems.

You may use the same retrieval tools, but the job is different.

Open a live coding-agent session and inspect it with /context.

Match the retrieval mechanism to the kind of data you are storing.
The active context window: the prompt, reasoning traces, and KV cache for this turn.
Distilled facts the agent should know later, like “Postgres is the primary datastore.”
Lossless records of what happened and when: logs, decisions, and debug traces.
Reusable skills and workflows: skill libraries, CLAUDE.md, and slash commands.

Each layer answers a different question. Use this map to evaluate what your agent actually needs.

Sometimes the answer is not “add a vector database.” Sometimes it is simply “write a file.”

Organisation knowledge is scattered across catalogs, wikis, comments, and people's heads. Agents should not have to reassemble that from scratch every time.
Agents read and update the files. Humans curate when needed, the way they curate code.
Obsidian vaults, CLAUDE.md and AGENTS.md, notes with cross-links, and metadata-as-code repos.
Updating cross-references. Touching many files in one pass. Keeping metadata consistent. That is exactly what LLMs are good at.
Andrej Karpathy coined the term LLM wiki: raw sources compiled by an LLM into a living markdown knowledge base, usually viewed in Obsidian.

A vendor-neutral standard for the wiki pattern: markdown concept files with YAML frontmatter, and no required SDK.
Only type is required. The content model stays yours.
Humans or agents can write the files, and any agent or viewer can read them.
You ship knowledge as files in git. There is no proprietary account to open first.
okf/SPEC.md.
Optimise for accuracy per unit of complexity, not for accuracy alone.

Two open-source tools from Garry Tan. Skim now, dig into the repos later if useful.
A Claude Code toolkit with about 23 opinionated role tools (CEO, designer, eng manager, release, docs, QA). It is about how the coding agent works.
An agent brain layer: personal or company knowledge with search, a typed graph, and synthesis. It is about what the agent remembers from notes.

Same idea as gbrain: vector search vs typed graph on one notes corpus. The lab uses a local equivalent.
Returns pages that talk about Acme, ranked by similarity.
Returns the actual people linked through typed edges written at ingest.

No context window solves this on its own: not 1M tokens, and not 10M either.

Compaction compresses history into a denser working state so the agent can keep going.

Trigger early when you can, and never rely on compaction to preserve critical rules.

For coding agents, context delivery is often a navigation problem, not only a compression problem.

If a rule matters, put it above the compaction line so it cannot quietly disappear.

We run two identical Claude Code sessions on the same task and the same repo.
You say “Add // REVIEWED to every file you edit.” The agent complies before compaction, then quietly stops afterwards.
You put the same rule above the compaction line. The agent keeps following it after compaction.

Same idea as gbrain search vs think: retrieve pages, or synthesise an answer. Search is cheap. Thinking costs a model call.
Returns five ranked pages. It found material, but it did none of the synthesis work.
Returns a synthesised answer plus a gap analysis, such as “nothing since 22 April.”

Building memory often costs more energy than querying it. Measure write cost as carefully as retrieval quality.
Pull atomic facts or triples with a model. Accurate, but expensive.
Dependency parsing can reach about 94% of LLM quality at a fraction of the cost.
gBrain pattern-matches wikilinks into typed edges at ingest, with no model call.

Rule: if a fact changes often, stays local to one task, or has low confidence, keep it in session state or an artifact, not in permanent memory. This is where quality is won or lost, and it is also where pollution and poisoning enter the system.

Useful work also happens in the background: Cursor background agents, Letta sleep-time compute, and the gBrain dream cycle.

Watch an agent decide what to persist, then recall it later in a fresh session.
memory_replace or memory_capture fire as it decides what to keep.
Checkpointing saves state. Durable execution guarantees that the work can finish.
“I saved your state. You take it from here.”
“Your workflow will run to completion.”

Persist completed boundaries, then recover without repeating mutations.

We use LangGraph with a Postgres checkpointer: three nodes, and node 2 loops over 100 items.
The workflow completes end to end without interruption.
Restart with the same thread_id and it resumes cleanly.
It stopped at item 60, then restarts from item 0.
thread_id, and sixty items of work are lost. If those were emails, you would send sixty duplicates. Idempotency keys close that gap.
Security used to mean protecting model weights. Now it also means protecting the operational context an agent carries forward.

Sanitise before the memory update, not after the damage is already stored.

This demo shows how one memory write can persist across sessions.

Ten habits. Memory is an architecture problem, not only a model problem.

Use these for any memory system, any vendor, and any paper.

Use these to practice applying the framework.
Pick a legal, customer-support, coding, or clinical workload. Choose a pattern and justify it with accuracy per unit of complexity (0 to 4).
Design a merge policy for dietary preferences: contradictions, temporary states, and confidence decay.
You are six hours into a twelve-hour migration and the process dies. What is lost, what re-runs, and what fires twice?
An attacker gets exactly one write. Map the blast radius. How would you detect it, and how would you trace it after the fact?

This is the last session. Use the next two weeks to ship something publishable and rehearse a clear demo.
Start with what you are solving. Fun projects are fine. If there is no hard business problem, say what the product does and why it is interesting.
Walk through how the system is put together: agents, memory, tools, APIs, and how the pieces talk to each other.
Name the technology stack and any tools you used. Keep it concrete so the audience can see what is real.
Show the product working. Keep the story aligned with the problem and architecture.

A decision-tree view of the same four layers. Useful when you need to pick a strategy under pressure.

Put critical rules above the compaction line. Gate every write. Design forgetting on purpose. Treat memory as an attack surface. See you on demo day.