7 Memory
This chapter covers
- What memory is and why LLM agents need it
- Episodic memory, memory stores, and the Memory class
- Wiring memory recall and record operations into the LLM agent task execution lifecycle
With MCP tools and skills now part of our framework, our LLM agent can tackle a wider range of tasks. Each run, however, starts fresh, as if previous ones never happened, leaving our LLM agent with no way to learn from past experiences. We address this gap by adding memory to our LLM agent.
Unlike tool and skills, there is no standard protocol for defining and using memory. All LLM agent frameworks and harnesses support some form of it, but what counts as memory varies, and none of the proposed taxonomies have been widely accepted. To learn the fundamentals of memory, we’ll focus on implementing episodic memory. This form of memory enables LLM agents to record completed task executions and recall relevant ones for future tasks to avoid repeated work and apply past lessons.
To do this, we introduce a new Episode class to represent a completed task execution, a new core type, Memory, and a base class, BaseMemoryStore, to serve as the data backend. We’ll also wire the required memory operations into the task execution lifecycle. By the end of this chapter, our LLM agents will be able to recall past experiences to perform better on future tasks.
Figure 7.1 shows our updated build plan and the work we have ahead of us in this chapter.