Memory and Context Terms: Context Window, System Prompt, Short/Long-Term Memory, Knowledge Base, Context Engineering
~12 min read
The 6 terms covering what an agent 'knows' at any given moment — from the hard limit of its context window to the deliberate practice of shaping what it sees.
This cluster answers a single underlying question: at any given moment, what does the agent actually have access to?
The hard ceiling is the Context window — the maximum amount of information an agent can consider at once. Everything the agent reasons over (instructions, conversation history, retrieved documents, tool outputs) has to fit inside this window; anything that doesn't fit simply isn't available to the model on that turn.
Within that window, the System prompt is the persistent background instructions or personality that define an agent's behavior — it's usually the first thing placed in the window and stays constant across a session, shaping how the agent interprets everything else it sees.
Two terms describe memory that persists ACROSS interactions rather than living only inside a single context window. Short-term memory is temporary context stored during a single session or conversation — it typically fits directly in the context window and disappears once the session ends. Long-term memory is persistent context stored across multiple sessions for continuity and learning — a user's stated preferences, past decisions, or facts the agent should remember weeks later, usually stored externally (a database or vector store) and retrieved back into the context window only when relevant.
A Knowledge base is a structured repository of information that agents can use for reasoning and decision-making — think of it as the agent's reference library, distinct from memory of past interactions: a knowledge base holds general facts and documents, while memory holds the agent's own history with a specific user or task.
Finally, Context engineering is the practice of shaping what information an agent sees to optimize its output — given that the context window is limited and everything the agent knows has to be deliberately placed inside it, context engineering is the discipline of deciding what goes in (and what's left out) so the agent reasons well rather than being overwhelmed or under-informed.
💻 Code example
class ContextManager:
"""Illustrates how the 6 memory/context terms combine into
what actually gets placed inside an agent's context window."""
def __init__(self, system_prompt: str, max_tokens: int = 8000):
self.system_prompt = system_prompt # persistent background instructions
self.max_tokens = max_tokens # the hard context window ceiling
self.short_term_memory: list[str] = [] # this session only
self.long_term_memory_store: dict = {} # persists across sessions
def build_context(self, user_query: str, knowledge_base_hits: list[str]) -> str:
"""This IS context engineering: deliberately deciding what
goes into the limited context window."""
relevant_long_term = self.long_term_memory_store.get("preferences", "")
parts = [
self.system_prompt,
f"Known user preferences: {relevant_long_term}", # long-term memory, retrieved on demand
f"Relevant knowledge: {'; '.join(knowledge_base_hits)}", # knowledge base
f"Recent conversation: {' | '.join(self.short_term_memory[-5:])}", # short-term memory
f"User: {user_query}",
]
return "\n".join(parts) # must fit within max_tokens (the context window)
💬 Deep Dive with AI
Key points
- •Context window: the maximum information an agent can consider at once — everything else below is about what competes to fit inside it
- •System prompt: persistent background instructions that shape how the agent interprets everything else in its context
- •Short-term memory (this session only) vs. long-term memory (persists across sessions) — different lifespans, usually different storage
- •Knowledge base: general reference information, distinct from memory of the agent's own past interactions
- •Context engineering: the deliberate practice of deciding what to place in the limited context window to optimize the agent's output