0Pricing
AI Agents with LangChain & Autonomous Workflows · Lesson

Entity & Summary Memory Strategies

Go beyond raw buffers by tracking named entities and rolling summaries so agents remember the important facts across long conversations without exploding the token budget.

Entity & Summary Memory Strategies is a free AI Agents with LangChain & Autonomous Workflows lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AI Agents with LangChain & Autonomous Workflows learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Buffers Are Not Enough

A plain buffer stores every message verbatim. In long chats this quickly exceeds the model context window and wastes tokens on irrelevant chatter.

Two smarter strategies fix this: summary memory compresses the past, and entity memory tracks specific facts about people and things.

What Is Summary Memory?

Summary memory uses an LLM to keep a running, condensed summary of the conversation. Instead of replaying 50 turns, the agent reads a few sentences capturing the gist.

  • Keeps token usage roughly constant
  • Preserves long-term context
  • Loses fine-grained wording

ConversationSummaryMemory

LangChain's ConversationSummaryMemory calls the LLM after each turn to update the summary. You pass it the same model the agent uses.

from langchain.memory import ConversationSummaryMemory
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model='gpt-4o-mini')
memory = ConversationSummaryMemory(llm=llm)

Saving and Reading the Summary

As turns happen you save context; reading the variables returns the compressed history rather than raw turns.

memory.save_context(
    {'input': 'My name is Ana and I love hiking.'},
    {'output': 'Nice to meet you, Ana!'}
)
print(memory.load_memory_variables({}))

Summary Buffer: Best of Both

ConversationSummaryBufferMemory keeps recent turns verbatim AND summarizes older ones once a token limit is crossed. Recent context stays sharp while old context is compressed.

from langchain.memory import ConversationSummaryBufferMemory

memory = ConversationSummaryBufferMemory(
    llm=llm,
    max_token_limit=200
)

What Is Entity Memory?

Entity memory extracts named things — people, projects, places — and stores a fact sheet for each. When an entity reappears, the agent recalls exactly what it knows.

This is ideal for personal assistants that must remember user preferences.

ConversationEntityMemory

The entity memory uses the LLM to detect entities and maintain a per-entity store.

from langchain.memory import ConversationEntityMemory

memory = ConversationEntityMemory(llm=llm)
memory.save_context(
    {'input': 'Deepak is leading the Mars project.'},
    {'output': 'Got it.'}
)

Inspecting the Entity Store

Each entity accumulates facts. Asking about an entity loads only its relevant summary into the prompt.

vars = memory.load_memory_variables(
    {'input': 'What is Deepak working on?'}
)
print(vars['entities'])

Choosing a Strategy

Pick based on the use case:

  • Buffer: short, exact conversations
  • Summary: long chats where the gist matters
  • Summary Buffer: long chats needing recent precision
  • Entity: assistants tracking facts about specific subjects

Cost and Latency Trade-offs

Summary and entity memory make extra LLM calls on every turn to update their state. That adds cost and latency.

Use cheaper, faster models for the memory-update step than for the main agent reasoning when possible.

Combining Memories

For sophisticated agents you can combine memories with CombinedMemory, e.g. a summary for flow plus entity memory for facts. Just ensure their output keys do not collide.

from langchain.memory import CombinedMemory

memory = CombinedMemory(memories=[summary_mem, entity_mem])

Quick Check

Test your understanding of advanced memory strategies.

Recap

You learned memory strategies beyond raw buffers:

  • Summary memory compresses history with the LLM
  • Summary buffer keeps recent turns exact and summarizes the rest
  • Entity memory tracks facts about named subjects
  • Each adds LLM calls — balance cost vs. recall
  • Combine memories for richer agents

Choosing the right strategy keeps agents both knowledgeable and efficient.

Frequently asked questions

Is the “Entity & Summary Memory Strategies” lesson free?

Yes — the full text of “Entity & Summary Memory Strategies” is free to read here on the web, and the AI Agents with LangChain & Autonomous Workflows course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AI Agents with LangChain & Autonomous Workflows course, upgrade to CoddyKit PRO.

What will I learn in “Entity & Summary Memory Strategies”?

Go beyond raw buffers by tracking named entities and rolling summaries so agents remember the important facts across long conversations without exploding the token budget. You practise AI Agents with LangChain & Autonomous Workflows with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start AI Agents with LangChain & Autonomous Workflows?

No prior experience is required. AI Agents with LangChain & Autonomous Workflows on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Entity & Summary Memory Strategies” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this AI Agents with LangChain & Autonomous Workflows lesson?

Yes. Every AI Agents with LangChain & Autonomous Workflows lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Agent Memory Concepts
  2. Conversation Buffer Memory
  3. Advanced Memory Solutions
  4. Entity & Summary Memory Strategies
← Back to AI Agents with LangChain & Autonomous Workflows