Marcin Wojtala

Agentic Playbook #19

Lucid Memory

Part 1 of Memory Optimisation series | What if AI could question its own memories?

Persistent agent memory solves remembering without solving when to forget. Lucid Memory introduces Memory Debt and two lightweight practices, a Memory Debt Audit and a Lucid Memory Check, for challenging what agents remember against current evidence.

•8 min read•Intermediate•article

Have you ever realised, halfway through a dream, that you were dreaming?

Perhaps something didn't quite add up. A familiar place looked different. An impossible situation suddenly caught your attention. For a brief moment, you stopped simply participating in the experience and started questioning it.

You became aware that you were dreaming. It is called lucid dreaming.

What I find particularly fascinating about this phenomenon is the transition from accepting an experience to critically evaluating it.

It made me wonder whether we could introduce a similar concept into the way we work with AI agents.

Not because AI dreams in the same way humans do. Nor because it possesses consciousness. But because there is an interesting engineering parallel between questioning our perception of reality and teaching an AI agent to challenge the information it has accumulated.

I would like to introduce a concept I call Lucid Memory.

And as we move towards increasingly persistent and autonomous AI agents, I believe it deserves a place in my Agentic Playbook.

The obsession with remembering

For much of our recent journey with generative AI, memory was something I wanted more of. Larger context windows. Persistent conversations. Repository knowledge. Personal preferences. Architectural decisions. Engineering standards. I wanted our agents to remember everything so that I wouldn't have to explain ourselves repeatedly.

Understandably so.

An AI agent that understands our engineering ecosystem, remembers previous mistakes and builds upon accumulated knowledge can be considerably more useful than one that starts from scratch every morning, Groundhog Day...

But somewhere along the way, I think we overlooked a rather important question.

What happens when the things our agents remember are no longer true?

Imagine a software engineering team undergoing an architectural transformation. Six months ago, the team decided to introduce a particular state management library. The reasoning was sound. The AI agent captured the decision and began applying it consistently. Three months later, following further experimentation, the team adopted a different approach. The agent, however, continues introducing the original library into newly generated components. Not because the model lacks technical knowledge. Not necessarily because it is incapable of reasoning. But because we gave it a memory that survived the decision it was supposed to represent.

We solved the problem of remembering without solving the problem of knowing when to forget.

Dreaming vs lucid dreaming

We are beginning to see AI memory systems that consolidate information from previous interactions. These processes can extract useful knowledge, summarise conversations, identify recurring preferences and organise information for future retrieval.

Some of these background memory consolidation processes lend themselves rather nicely to the analogy of dreaming. While we are away, the system can process accumulated experiences and decide what might be worth retaining. But consolidation and critical evaluation are two different things.

Organising knowledge does not necessarily make that knowledge accurate. Summarising a conversation does not validate the assumptions made during it.

A beautifully organised collection of outdated assumptions is still a collection of outdated assumptions. This is where I would introduce a distinction.

Dreaming helps an agent organise what it remembers. Lucid Memory challenges whether those memories still deserve to guide its next decision.

Imagine an agent deliberately evaluating its accessible memories before relying on them.

Where did this information originate?

Is it still relevant?

Does it contradict something I learned more recently?

Am I treating an assumption as an established fact?

These are relatively simple questions. Yet they represent an important shift from passive memory consumption towards evidence-driven critical thinking.

Metacognition: thinking about thinking

In psychology, metacognition broadly describes our ability to reflect on and regulate our own thinking.

It allows me to recognise uncertainty, challenge our assumptions and reconsider how we arrived at a particular conclusion. Interestingly, experienced software engineers do this all the time.

We challenge architectural decisions. We revisit assumptions during incident reviews. We question whether a solution that worked successfully in one environment is appropriate for another.

Experience is valuable, but experience without reflection can also become a source of bias. Why should our approach to AI agents be any different?

We can introduce metacognitive-inspired practices into agentic workflows by asking agents to explicitly examine their retrieved context, identify contradictions and verify assumptions before acting.

Of course, asking a language model to question itself does not guarantee a more accurate answer. An agent can be just as convincingly wrong about its memories as it can be about anything else. This is why evidence matters.

Lucid Memory is not about trusting an agent to determine what is true through introspection alone. It is about introducing a deliberate opportunity to challenge inherited knowledge against independently verifiable sources.

Introducing Memory Debt

As engineers, we are familiar with technical debt.

We understand that decisions made today can introduce additional costs tomorrow. Sometimes we accept those costs deliberately. Sometimes they accumulate without us noticing.

I would argue that persistent AI agents introduce another category of debt.

Memory Debt.

I define Memory Debt as the accumulation of outdated, contradictory, duplicated, unverified or incorrectly scoped information that continues, or has the potential, to negatively influence an agent's behaviour.

What might that look like in practice?

• Architectural decisions that have since been superseded. • Temporary workarounds remembered as permanent engineering standards. • Individual preferences incorrectly generalised across an entire engineering team. • Historical incidents influencing recommendations despite their resolution. • Assumptions generated by the agent itself and subsequently retained as facts.

The last example is particularly interesting.

Imagine an agent makes an incorrect assumption during a development task. That assumption is subsequently summarised and stored in memory.

During its next task, the agent retrieves it as established context. The same assumption influences another decision, potentially creating further memories that reinforce the original mistake. Over time, the distinction between what was verified and what was merely assumed can disappear.

What began as a hypothesis becomes a remembered fact.

Unlike technical debt, Memory Debt may not be immediately visible in your repository. It can accumulate outside the codebase, quietly influencing how the next piece of code is generated.

And increasing the memory capacity of an agent does not necessarily resolve this problem. It may simply increase its capacity to accumulate debt.

Technical debt is the cost of yesterday's engineering decisions. Memory Debt is the cost of continuing to believe them after they are no longer valid.

When did you last audit your agent's memory?

• We audit our dependencies. • We review our code. • We revisit our architecture. • We maintain our documentation.

Yet how often do we inspect the persistent information influencing our AI agents?

If you are using Claude Code, try running the /memory command. It allows you to explore memory and instruction files and access the automatically generated memory directory.

If you are using OpenAI Codex, the /memories command, where available, allows you to configure memory usage and generation. You can also inspect its generated local memory files, typically found under ~/.codex/memories/ or ~/.codex/memories_v2/.

The precise location depends on your version and configuration.

Both tools offer different mechanisms for managing persistent knowledge, but the underlying engineering challenge remains the same.

Now, simply inspecting these memories is probably not enough.

Imagine asking a colleague to review their own assumptions without providing access to the evidence that might contradict them.

Would you consider that a particularly reliable audit?

Probably not.

So why would we expect something different from our AI agents?

I would suggest introducing two lightweight practices into our agentic engineering workflows.

Practice 01: The Memory Debt Audit

Think of this as a dependency audit, but for accumulated knowledge.

Periodically ask your agent to inspect its accessible persistent memories and compare them against authoritative sources.

The objective is not to delete everything that looks suspicious. It is to produce a prioritised, evidence-based set of recommendations that we can review.

Here is a prompt you can experiment with:

PROMPT: Memory Debt Audit

Act as a memory auditor. Identify and inspect the persistent memory sources accessible to you. Distinguish automatically generated memories from developer-authored instructions and current session context.

For each relevant memory, assess its origin, scope, age, supporting evidence and potential impact on future engineering tasks.

Identify contradictions, outdated assumptions, duplicated information and superseded decisions. Validate findings against current code, configuration, documentation and approved architectural decisions where available.

Classify each finding as KEEP, UPDATE, REMOVE or REVIEW. Assign a high, medium or low impact rating and explain your recommendation.

Cite relevant file paths and supporting evidence. Explicitly identify inaccessible sources and unverifiable claims. Do not treat another memory as independent verification.

Produce a prioritised Memory Debt report. Do not modify any files, instructions, settings or memories.

I would consider running this periodically, following a significant architectural change or as part of an existing engineering hygiene exercise (I have created a skill for it).

We already dedicate time to maintaining the quality of our codebase.

Perhaps we should dedicate some of that time to maintaining the quality of the knowledge used to generate it.

Practice 02: The Lucid Memory Check

While the Memory Debt Audit is retrospective, the Lucid Memory Check is preventative.

Before an agent begins a consequential engineering task, ask it to identify which persistent memories are influencing its proposed approach.

More importantly, ask it to verify the assumptions behind them.

PROMPT: Lucid Memory Check

Before executing this task, identify the accessible persistent memories that materially influence your proposed approach.

For each material memory, explain its relevance, origin and applicable scope. Verify critical assumptions against current authoritative evidence.

Identify contradictions, outdated information and unresolved uncertainty. Distinguish verified facts from remembered preferences, historical decisions and inferred assumptions.

Do not rely on unverified memories for consequential engineering decisions. If a material conflict cannot be resolved, request clarification before proceeding.

Provide a concise summary of the assumptions you verified, challenged or excluded, alongside supporting evidence and any limitations in memory visibility.

Do not modify persistent memory as part of this check.

Imagine your agent responding:

"I was going to follow our previous authentication pattern, but the latest architectural decision supersedes it."

Or perhaps:

"I remember that integration tests were optional for this service, but I cannot find any current evidence supporting that assumption."

These are small but meaningful shifts in how we work with AI.

One practice challenges the knowledge we have accumulated. The other challenges how we intend to use it.

I wouldn't necessarily introduce this check for every minor development task. There is an associated cost in latency, token consumption and engineering overhead.

However, for consequential architectural, security or infrastructure changes, I believe it is worth exploring.

It could eventually become a reusable skill or even part of an agentic Definition of Ready.

One important engineering consideration: a prompt is not an enforceable guardrail. For genuinely read-only audits, use appropriate permissions and memory-generation settings. Neither prompt guarantees complete memory visibility or prevents automatic background updates.

Remembering less, understanding more

I suspect that as AI agents become increasingly capable, we will gradually move away from the idea that more context is always better.

Instead, we will start differentiating between the quantity of information available to an agent and the quality of information it should rely upon. There is a meaningful difference.

An experienced engineer is not valuable simply because they remember every decision they have ever made. They are valuable because they understand which experiences remain relevant, which assumptions deserve challenging and when a previous decision needs to be reconsidered.

Perhaps we should aspire to something similar in our agentic engineering practices.

Not artificial consciousness.

Not an agent that genuinely dreams.

But an agentic workflow that treats memory as something to be questioned, maintained and occasionally discarded.

Perhaps the next evolution of AI memory is not about how much our agents can remember, but how effectively they can challenge what they remember.

That, to me, is the essence of Lucid Memory.

This is the first article in my three-part Agentic Playbook series on Memory Hygiene.

In the following articles, I will explore how we architect persistent knowledge across agentic engineering environments and what happens when the memories influencing our agents become an attack surface.

For now, I would like to leave you with one question.

When was the last time you audited your AI agent's memory?

References

• Anthropic: How Claude remembers your project • OpenAI: Memories • OpenAI: Developer slash commands

Continue the Playbook