Context Type 3-4: Knowledge and Memory
~12 min read
The next 2 of the book's 6 context types: Knowledge (domain facts and processes) and Memory (continuity across sessions, split into short-term and long-term).
Continuing this course's 6-type taxonomy from the previous subtopic (Instructions, Examples), this subtopic covers Types 3 and 4 — the two layers concerned with what the agent KNOWS, as opposed to how it should BEHAVE.
Type 3, Knowledge, is where you feed the agent domain knowledge — from business processes and APIs to data models and workflows. This bridges the gap between text prediction and decision-making: an LLM's raw pretraining gives it general language ability and broad world knowledge, but it has no idea about YOUR company's refund policy, YOUR specific API's exact parameter names, or YOUR internal data schema, unless that knowledge is explicitly supplied as context. This is the layer most directly connected to RAG (Retrieval-Augmented Generation, covered extensively elsewhere in this curriculum) — retrieved document chunks are a common way Knowledge context gets populated, though this course frames Knowledge as the broader CATEGORY (any domain information the agent needs), with RAG being one common MECHANISM for supplying it, not the only one.
Type 4, Memory, is about wanting the agent to remember what it did in the past — this layer gives it continuity across sessions. This course splits Memory into exactly two sub-kinds: short-term memory covers current reasoning steps and chat history — everything relevant WITHIN the current session, which typically fits directly in the context window and disappears once the session ends. Long-term memory covers facts, company knowledge, and user preferences — things that should persist ACROSS multiple separate sessions, typically stored externally (a database or memory system like Zep, used in this course's own hands-on workflow build covered in the companion topic) and retrieved back into context only when relevant, rather than kept permanently loaded.
The distinction between Knowledge and Memory is worth being precise about, since they can seem similar at first glance: Knowledge is general, often static domain information that would be the same regardless of WHO the agent is talking to (a company's refund policy is the same for every customer). Memory is specific to the ongoing relationship or session — facts about THIS particular user, THIS particular conversation's history. A support agent's refund policy is Knowledge; that it already told THIS customer their refund was approved five minutes ago is Memory.
💻 Code example
# Modeling Knowledge (general, static domain info) and Memory
# (short-term session history + long-term persisted facts) as
# distinct context sources the agent assembles from.
class KnowledgeBase:
"""Context Type 3: general domain knowledge, same for every user."""
def __init__(self, facts: dict):
self.facts = facts # e.g. company policies, API docs, data schemas
def lookup(self, topic: str) -> str:
return self.facts.get(topic, "No knowledge found on this topic.")
class MemoryStore:
"""Context Type 4: short-term (this session) vs long-term
(persists across sessions, keyed per-user)."""
def __init__(self):
self.short_term: list[str] = [] # this session only
self.long_term: dict[str, dict] = {} # user_id -> persisted facts
def remember_this_session(self, message: str):
self.short_term.append(message)
def persist_long_term(self, user_id: str, key: str, value: str):
self.long_term.setdefault(user_id, {})[key] = value
def recall_long_term(self, user_id: str) -> dict:
return self.long_term.get(user_id, {})
kb = KnowledgeBase({"refund_policy": "Refunds process within 5 business days."})
memory = MemoryStore()
memory.remember_this_session("User asked about a late refund")
memory.persist_long_term("user_42", "refund_status", "approved on 2026-06-28")
print("Knowledge (general):", kb.lookup("refund_policy"))
print("Memory (short-term):", memory.short_term)
print("Memory (long-term, user_42):", memory.recall_long_term("user_42"))
💬 Deep Dive with AI
Key points
- •Context Type 3, Knowledge, feeds domain information (business processes, APIs, data models, workflows) — bridging text prediction and real decision-making
- •RAG is one common mechanism for populating Knowledge context, but Knowledge is the broader category, not synonymous with RAG
- •Context Type 4, Memory, gives an agent continuity across sessions, split into short-term (current reasoning/chat history) and long-term (facts, company knowledge, user preferences)
- •Short-term memory typically lives directly in the context window and disappears after the session; long-term memory is stored externally and retrieved when relevant
- •Knowledge is general and the same for every user; Memory is specific to the ongoing relationship/session with a particular user