Workspace/Lesson workspace
Loading progress
Grounding & reasoning40 min

Distinguish episodes, facts, and preferences

Lesson 1 of 3
How to study this lesson

Read one section, trace the worked example, and try the knowledge check. Bookmark saves a shortcut; notes appear in My notebook. Mark lesson complete is your own assessment and does not mark its lab passed.

By the end, you can

  • Assign a memory record to a useful functional category.
  • Preserve source evidence when consolidating episodes.
  • Scope user preferences without treating them as authorization.

Memory is an external data design

For a language-agent application, memory can mean persisted records that a later interaction retrieves. It does not require modifying model weights. The application chooses what to store, how to index it, when to retrieve it, and how to resolve changes. A long conversation transcript is one possible source, but dumping the entire transcript into every prompt is neither a complete memory architecture nor a reliable correction mechanism.

Start from the future decision a record should support. An incident history can help identify a useful diagnostic action. A verified catalog fact can answer a product question. A response-style preference can reduce repeated formatting requests. These records need different fields and lifecycles because the claims they make are different. Naming the distinction prevents convenient storage choices from silently defining product behavior.

Episodes preserve what happened in context

Episodic memory records an event with participants, time, task context, action, and observed outcome. On Tuesday, lookup A timed out under service account X is an episode. It should not become lookup A is unavailable forever. The event's historical context explains what it can support and what it cannot. Preserve both event time and recording time when delayed ingestion is possible.

Research on Generative Agents uses remembered experiences and retrieval to influence later behavior in a simulated environment. The transferable engineering idea is that past events can supply context for future decisions. Our support examples are original and make no claim to reproduce that simulation. In particular, an old success or failure is evidence to inspect, not an unconditional instruction to repeat the same action.

Semantic memory makes a claim beyond one episode

Semantic memory stores a proposition intended to hold within a defined scope, such as service checkout uses queue Q in environment staging. Store the proposition's source, valid time, environment, confidence basis, and status. A fact may be derived from several episodes, but the derivation should remain inspectable. Summarization compresses text; it does not automatically establish truth.

Suppose three incident notes mention a missing timeout. A careless consolidation creates all checkout failures are caused by timeouts. A bounded consolidation instead records timeout misconfiguration appeared in incidents I1, I2, and I3, with those references. The first overgeneralizes; the second preserves the actual evidence. Keep generated hypotheses separate from verified facts so retrieval does not launder speculative text into apparent organizational knowledge.

Preferences describe a person in a context

A preference record might say that a particular user prefers concise bullet summaries for weekly reports. It should include subject, context, value, source, and update time. It should not silently become a global rule for every user or every document. Preferences can change, conflict with a current request, or apply only to one project. The current explicit request is often the strongest evidence of what is wanted now.

A preference for quick execution is not permission to perform any external action. Keep action authorization in its own policy model. Similarly, inferring a preference from repeated behavior is weaker than an explicit statement. The application can label inferred records and use them conservatively. This allows personalization to improve continuity while leaving the user able to correct the record and understand why behavior changed.

A small record model supports safe consolidation

Use stable IDs and typed relationships between records. An episode can support a semantic claim; a correction can supersede a prior preference; a deletion can invalidate derived summaries. Store these links rather than replacing every source with one polished paragraph. The cost is more metadata, but it enables audits and prevents a correction from leaving stale copies scattered through retrieval.

The code classifies three explicitly authored records and prints their distinct scopes. It is a data-model example, not a learned memory extractor. A production extractor would propose candidate records, validate their evidence and scope, and apply the application's retention policy before persistence. Start with a conservative set of useful memory types and expand only when retrieval failures show that a missing distinction matters for the task.

Work through the code

Three immutable records show event, fact, and preference scopes. Source references identify supporting material. The code does not infer memories from conversation or decide whether a user has authorized storage.

typed_memory_records.py
python
from dataclasses import dataclass

@dataclass(frozen=True)
class Memory:
    identity: str
    kind: str
    scope: str
    value: str
    source: str

records = [
    Memory("e1", "episodic", "incident-17", "lookup timed out", "trace-17"),
    Memory("s1", "semantic", "staging", "checkout uses queue Q", "config-v4"),
    Memory("p1", "preference", "user-A:weekly-report", "concise bullets", "request-9"),
]
allowed = {"episodic", "semantic", "preference"}
for record in records:
    if record.kind not in allowed or not record.source:
        raise ValueError("memory needs a type and source")
    print(record.identity, record.kind, record.scope)
EXPECTED / ILLUSTRATIVE OUTPUT
e1 episodic incident-17
s1 semantic staging
p1 preference user-A:weekly-report

Run Python snippets locally with the prerequisites named above. The module coding lab runs directly in your browser.

Pause and reason

A user requested bullet points for one weekly update. Propose a conservative preference record and identify an overgeneralization to avoid.

Check your understanding

Three past incidents involved timeout configuration. Which semantic memory preserves the evidence best?

Your notes

Explain the mechanism in your own words. Add a failure you want to test.

Saved notes appear in your notebook

Go deeper with primary sources

Practice this module