In-Context Memory via Prompts
What you'll learn: How to give your AI agent memory by simply including conversation history in each prompt.
The Core Idea
In-context memory is the simplest form of agent memory—you copy-paste the entire conversation history directly into the LLM's prompt every single time you make a request. No databases, no fancy storage systems. Just include "what happened before" as part of the input text.
Think of it like this: imagine you're talking to someone with no long-term memory. Every time you speak to them, you hand them a notebook containing everything you've discussed so far. They read it, understand the context, and respond accordingly.
How It Works in Practice
When a user sends a new message, you construct a prompt that includes:
- System instructions (the agent's role and guidelines)
- Previous user messages and assistant responses (formatted chronologically)
- The current user message
The LLM sees the full conversation thread each time and uses that context to generate appropriate responses. This works because modern LLMs have large context windows—they can "remember" by literally reading the history.
Advantages and Limitations
Pros: Dead simple to implement. No external storage needed. Works immediately with any LLM.
Cons: Context windows have limits (tokens aren't infinite). Costs increase with conversation length since you're re-processing the same history repeatedly. Eventually, you'll hit the context window ceiling.
This approach maps directly to what you've learned about short-term memory—it holds recent conversation turns but has capacity constraints.
Key Takeaway: In-context memory stores conversation history by including it directly in each prompt, making it the simplest but most token-intensive memory strategy for AI agents.