Memory / carry what matters across the break
State lives in a session — memory survives it. A `remember` step extracts preferences at session end and injects them at start. The system now knows returning users, but cannot reach outside the context window.
Architectural Position
- fn
- The LLM call — rewrite, respond, and remember are all fn calls, each with their own prompt
- query_user
- The current user message
- prompt_extract
- The system prompt for extraction — instructs fn to identify durable preferences from the session transcript
- state
- The current session history
- memory
- Persistent user profile — written at session end, loaded at session start
- context
- Retrieved phone data plus the loaded user profile
- response
- A personalised response — informed by what the system knows about this user
Step by Step
# The failure from Layer 5
Session 1 (yesterday):
User: "I want a phone for my elderly mother,
budget ₹20k, prefer Indian brands"
System: [recommends Moto G84]
Session 2 (today):
User: "show me some options"
System: "Here are some popular phones..."
# Session state was wiped
# System forgot everythingState covers the current session. When it ends, everything is gone. Returning users start blank.
Implementation
What you build
rememberat session end:fnextracts durable preferences from the transcript intouser_profile.json- Session start:
user_profile.jsonloaded and injected intorewriteandrespondasmemory - UI: personalised from the first query in a returning session
What it fixes
System recognises returning users. Preferences persist across sessions. Recommendations improve over time.
Key Concepts
- User profile
- A structured store of facts extracted from past sessions — preferences, budget, personas. Persists across sessions in `user_profile.json`.
- remember
- The final fn call in the pipeline — fires at session end. Its job: extract durable preferences from the full transcript and write them to the user profile.
- Memory extraction
- Using an LLM to identify what from a conversation is worth persisting. Not everything a user says is a durable fact.
- Memory decay
- The policy for removing or down-weighting stale memories over time. Preferences change; old memories should not override new signals.
The Failure
The Forgetting LawModels forget everything not in context. The question is what to keep.
Session 1: the user establishes they want a phone for elderly mother, budget ₹20,000, prefers Indian brands. Session 2 (the next day): "show me some options." The pipeline has no idea who this user is. It starts from scratch. The user has to re-explain context they already gave. In a traditional app, the database remembers. In an LLM pipeline without memory, every session is a first meeting.
What it reveals
The pipeline can read and write a user profile — but it is still sealed. Cannot check live stock, fetch current prices, or book anything.