# Where cognition meets AI - teaching machines to remember what matters (Part 4)

## "Think before you remember!"

Part 3 covered the memory layer of NeuralEngram: working memory, episodic memory and the Ebbinghaus decay mechanism. A memory system, however, is only as effective as the component that decides when and how to use it. This article introduces that component: the **Planner Agent**.

## The role of the Planner

In human cognition, the prefrontal cortex is responsible for planning and attention. It determines what a situation requires before any recall takes place. A question about a personal event triggers memory recall; a factual question draws on general knowledge; a greeting requires no recall at all.

The Planner Agent performs the same function in NeuralEngram. It is the first agent to receive every message, and it is responsible for three tasks:

1.  Determining the intent of the message
    
2.  Retrieving the appropriate memories, if any are needed
    
3.  Reinforcing the memories that contributed to a successful response
    

The Planner does not generate the response itself. Response generation is handled by the Executor Agent, covered in Part 5. This separation of responsibilities keeps each agent focused and makes failures easier to diagnose: an incorrect answer can be traced either to a planning issue (wrong memories selected) or an execution issue (correct memories, incorrect response).

The overall flow is:

User message → Planner Agent → memory retrieval → Executor Agent → response → reinforcement

## Intent detection

Each incoming message is classified into one of four intents.

**Memory**: questions about the user's own past, such as "What did I tell you about my sister?" or "Where did I keep my keys?". These are identified by recall-related phrases ("remember", "last time", "remind me") and by personal references ("my", "did I", "where do I"). Personal references are essential, because users rarely phrase questions with explicit recall words.

**Reasoning**: requests for analysis, such as "Compare these two options" or "What are the pros and cons?".

**Small talk**: greetings and acknowledgements, such as "hi" or "ok thanks". A message is classified as small talk only if every word in it belongs to this category, so "Thanks, can you explain gravity?" is not treated as small talk.

**General**: all other questions, such as "What is photosynthesis?".

When a message matches more than one category, the Planner applies a fixed priority order: memory, reasoning, small talk, then general. A message such as "Compare what we discussed last time" is therefore treated as a memory question, since its answer depends on past context.

The classifier is rule-based. It requires no model call, adds no latency and behaves predictably, which makes it straightforward to test.

## Retrieval depth

Retrieving memories for every message, regardless of intent, introduces two problems. It adds irrelevant context to the language model's input, and, because the system reinforces every memory it uses, it strengthens memories that played no real part in the conversation. This counteracts the forgetting curve the system is built on.

The Planner therefore sets the retrieval depth according to intent:

| Intent | Maximum memories retrieved |
| --- | --- |
| Memory | 8 |
| Reasoning | 6 |
| General | 4 |
| Small talk | 0 (no retrieval) |

These values are upper limits. The number of memories returned depends on how many are relevant to the query.

## Relevance-filtered retrieval

When retrieval is required, the Planner converts the message into an **embedding**, a numerical representation of its meaning. Sentences with similar meanings produce similar embeddings even when they share no words; for example, "Where are my spectacles?" and "My reading glasses are on the bedside table".

The Planner then searches both memory layers in a single operation:

*   the **semantic layer**, which matches memories by meaning
    
*   the **episodic layer**, which also accounts for how strong each memory still is
    

Results from both layers are merged, duplicates are removed, forgotten memories are excluded, and the remaining memories are ranked by relevance.

Two design decisions govern this step:

**A single retrieval per message.** The Planner performs the search once and passes both the results and the embedding to the Executor Agent. This avoids duplicate searches and repeated embedding computation.

**A relevance threshold.** Each memory receives a similarity score between 0 and 1. Memories scoring below the threshold of 0.30 are discarded, even if they are the closest matches available. Supplying no context is preferable to supplying misleading context.

## Reinforcement

The Planner also links retrieval back to the Ebbinghaus mechanism. Once the Executor Agent produces a response, the Planner reinforces the memories that were used: their stability increases and their retention is reset. Each reinforced memory also receives positive feedback, which gradually raises its priority score. This implements spaced repetition through normal use; memories that are repeatedly useful persist longer.

Reinforcement follows two rules:

1.  **Only retrieved and used memories are reinforced.** All other memories continue to decay as intended.
    
2.  **Reinforcement occurs only after a successful response.** If response generation fails, no memory is credited.
    

## Example

Consider a user who previously stated: "I take my blood pressure tablet every morning after breakfast." Some days later, the user asks: "When do I take my medicine?"

1.  **Intent detection:** the phrase "do I" identifies a memory question.
    
2.  **Retrieval depth:** up to eight memories may be retrieved.
    
3.  **Retrieval:** the query is embedded once. Although the wording differs ("medicine" versus "tablet"), the meanings are similar, so the stored memory scores above the threshold. Unrelated memories score below it and are excluded.
    
4.  **Execution:** the Executor Agent receives only the relevant memory and responds accordingly.
    
5.  **Reinforcement:** after the successful response, the memory's retention is reset and its stability increased, so it will decay more slowly from this point.
    

A subsequent message such as "ok thanks" would be classified as small talk, and no retrieval would take place.

## Results

The retrieval pipeline was evaluated on a labelled benchmark of 30 queries: 22 questions answerable from stored memories, and 8 queries with no relevant memory (off-topic questions and small talk). A query counts as correctly handled if the relevant memory was retrieved, or if no memory was retrieved for a query that had none.

| Metric | Baseline | With Planner |
| --- | --- | --- |
| Retrieval accuracy | 73.3% | **93.3%** |
| Off-topic queries correctly given no memories | 0% | **100%** |
| Irrelevant memories per query | 4.23 | **0.27** |

The baseline retrieved a fixed set of memories for every message, without intent routing or a relevance threshold.

## Limitations

Intent detection is keyword-based. It does not capture deeper meaning, matches partial words (for example, "reasonable" is detected as the reasoning signal "reason"), and currently supports English only. Because the relevance threshold filters unrelated memories regardless of intent, a misclassification typically affects only retrieval depth, not the correctness of the context. A model-based intent classifier is planned as future work.

> Effective memory is not about storing more — it is about recalling the right information at the right time.

The next part covers the **Executor Agent**: how it combines the conversation, the memories prepared by the Planner and the language model to generate a response, and how each interaction is stored as new memory.
