7 Adding Agent Memory with Context and Chat Message History
This chapter covers
- Inject external context to the agent via context providers
- Provide and store agent interactions with ChatHistoryProviders
- Implement file-based, in-memory, and vector store providers
Agents need memory to be useful. Without it, every interaction starts from scratch. The agent forgets what happened two messages ago. This chapter shows how Agent Framework handles memory through two distinct but complementary systems: context for injecting external knowledge and chat history for maintaining conversational flow.
7.1 Understanding Agent Memory: Context and Chat History
Agents maintain knowledge across interactions through two complementary mechanisms, each addressing different aspects of memory. Chat History captures the conversational flow within a session, while Context injection brings external knowledge into each interaction (figure 7.1). Understanding both mechanisms is essential for building agents that resume conversations after interruptions and reason over information beyond what appears in the dialogue.
Figure 7.1 Chat Client Agent augmented with memory providers (AIContextProvider and ChatHistoryProvider)