Foundations: Agent Concepts, State, and Memory
Cover core concepts including agent architectures, types of memory and state, temporal modeling, and strategies for representing user context and intents.
Content
Types of memory: short, episodic, semantic
Versions:
Watch & Learn
AI-discovered learning video
Types of Memory for Agents: short, episodic, semantic — the trio that actually remembers
"If stateful agents are people, memory is everything from the sticky note on their forehead to the dusty photo album in the attic."
You're already familiar with agent roles, behavior models, and the big stateless vs stateful choice from earlier modules. Now we zoom into the how of remembering: the three memory flavors every practical ADK-based agent needs — short (working) memory, episodic memory, and semantic memory. We'll cover what each is, why it matters for personalization, how they interact, and pragmatic hints for implementing them in the ADK ecosystem.
Quick map: why we split memory
Think of building agents like running a household. You want quick access to what you're cooking (short memory), a scrapbook of milestone moments (episodic), and a knowledge cabinet of facts and preferences (semantic). Each layer has different lifetimes, structures, and retrieval strategies — and mixing them up is how agents get weird or creepy.
The three types, demystified
1) Short memory (working memory)
- What it is: Immediate conversational context and transient task state. The stuff the agent needs right now.
- Duration: Seconds to minutes (until the session or task ends, or until explicitly flushed).
- Structure: Lightweight key-value pairs, recent messages, in-memory buffers.
- Examples: Latest user utterance, last 3 system actions, intermediate outputs for a multi-step plan.
Why it matters: Short memory keeps the conversation coherent and lets the agent follow the thread without expensive lookups. It's the difference between "Oh — I remember you mentioned that" and "Wait, what were we talking about?"
Implementation note: store in process memory (cache) or ephemeral ADK context objects. Keep it small; it's read/write heavy and usually not persisted.
2) Episodic memory
- What it is: Logged events and contextual snapshots tied to user sessions, moments, or interactions — basically the agent's diary.
- Duration: Hours to years (configurable). More permanent than short-term, but can be pruned.
- Structure: Time-stamped records: conversation transcripts, actions taken, decisions, user confirmations, notable events with metadata (channel, sentiment, outcome).
- Examples: "User changed subscription on 2026-03-11", a troubleshooting session transcript, first-time onboarding steps.
Why it matters: Episodic memory supports long-range personalization, auditability, and continuity across sessions. It's what allows the agent to say "Last time we fixed X, you preferred method A".
Implementation note: store in a persistent store (event DB, document DB). Index by user ID and time; tag with topics and outcomes to accelerate retrieval.
3) Semantic memory
- What it is: Generalized facts, concepts, and distilled user preferences derived from experience or external knowledge. Think of it as the agent's encyclopedia and user model merged.
- Duration: Long-lived; evolved and updated over time.
- Structure: Vector embeddings, structured user profiles, ontologies, rules, or feature stores.
- Examples: "User prefers vegetarian recipes", embedding for user's product taste, knowledge that "premium tier -> 20% discount".
Why it matters: Semantic memory enables personalization without replaying entire conversations. It answers the question What do we know about this user that should shape future behavior?
Implementation note: common storage is a vector DB for embeddings (semantic search) paired with a relational or document store for structured profile fields.
Comparison at a glance
| Attribute | Short Memory | Episodic Memory | Semantic Memory |
|---|---|---|---|
| Lifetime | Seconds–minutes | Days–years | Long-term (persistent) |
| Structure | Key-value, buffers | Time-stamped logs | Embeddings, structured profiles |
| Use case | Context, coherence | Recall past events, audits | Personality, preferences, facts |
| Storage | In-memory cache | Document DB / event store | Vector DB + profile DB |
How they interact — the pipeline
- User says something -> short memory updates (immediate context).
- If something notable happens (e.g., user confirms an address), create an episodic entry.
- Periodically or via triggers, consolidate recurring or stable info from episodic logs into semantic memory (update profile or embeddings).
This consolidation step is critical: it prevents the agent from endlessly re-storing the same trivial facts and converts repeated episodes into actionable preferences.
"Consolidation is the agent's version of 'learning from experience' — not just remembering, but abstracting what matters."
Practical ADK design patterns (pseudo-code + tips)
Pseudocode: Memory objects
short_memory = { recent_messages: [], task_state: {} }
episodic_store.save(user_id, { timestamp, event_type, payload })
# semantic update: run offline job or real-time rule
if count_events(user_id, 'liked_recommendation') > 3:
semantic_profile.update(user_id, { preference: 'likes_recommendations' })
# retrieval: combine all three
context = short_memory.get(user_id)
episodes = episodic_store.query(user_id, last=30_days)
semantics = semantic_store.lookup(user_id)
# construct prompt or decision with weighted recall
prompt = build_prompt(context, retrieve_relevant(episodes), semantics)
Retrieval strategies
- Always check short memory first for immediate context.
- Use filters and recency when querying episodic (e.g., last 90 days for support issues).
- Use semantic search (vector similarity) to fetch conceptually-related preferences or facts.
- Merge results with priority: short > semantic (explicit user setting) > episodic (contextual history), unless a specific business rule overrides.
Best practices & pitfalls
- Privacy by design: store only what you need, encrypt PII, support deletion requests. Episodic logs are gold for personalization but risky legally.
- TTLs and pruning: set sensible lifetimes for episodic logs; compress or summarize old episodes into semantic facts.
- Cost vs latency: short memory = cheap & fast; semantic vector search = cost & latency trade-offs; episodic queries = variable. Cache smartly.
- Avoid leakage: don't automatically surface sensitive episodic details in prompts.
- Interpretability: keep metadata on how semantic facts were derived (source episodes, confidence scores).
Short checklist for implementing memory in ADK
- Define what belongs in short vs episodic vs semantic for your agent.
- Choose storage tech: in-memory caches, document/event stores, vector DBs.
- Implement consolidation pipelines (episodic -> semantic).
- Add access controls, audit logs, and retention policies.
- Test retrieval relevance and update flows with real user data.
Final takeaway — make it human
- Short memory keeps the conversation alive.
- Episodic memory builds a chronological story of interactions.
- Semantic memory stores what matters about the person.
Treat them as a symphony, not a haystack. When each plays its role, your ADK agent feels smart, respectful, and genuinely helpful — rather than the digital equivalent of that one friend who never remembers your birthday.
"Design memory well, and your agent will remember the important things without being a stalker about it."
Key next steps: map out a memory schema for your agent persona (what to store where), sketch consolidation triggers, and draft retention/privacy rules. We'll use this blueprint when we design behavior models tied to memory in the next module.
Comments (0)
Please sign in to leave a comment.
No comments yet. Be the first to comment!