Estrategias de memoria de entidades y resúmenes
Vaya más allá de los buffers sin procesar mediante el seguimiento de entidades con nombre y resúmenes acumulativos, para que los agentes recuerden los datos importantes en conversaciones largas sin disparar el presupuesto de tokens.
Estrategias de memoria de entidades y resúmenes es una lección gratuita de AI Agents with LangChain & Autonomous Workflows en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de AI Agents with LangChain & Autonomous Workflows, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de AI Agents with LangChain & Autonomous Workflows incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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.
Preguntas frecuentes
¿La lección «Estrategias de memoria de entidades y resúmenes» es gratis?
Sí — el texto completo de «Estrategias de memoria de entidades y resúmenes» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de AI Agents with LangChain & Autonomous Workflows, actualiza a CoddyKit PRO. El curso de AI Agents with LangChain & Autonomous Workflows incluye 4 lecciones en total.
¿Qué aprenderé en «Estrategias de memoria de entidades y resúmenes»?
Vaya más allá de los buffers sin procesar mediante el seguimiento de entidades con nombre y resúmenes acumulativos, para que los agentes recuerden los datos importantes en conversaciones largas sin d… Practicas AI Agents with LangChain & Autonomous Workflows con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar AI Agents with LangChain & Autonomous Workflows?
No se requiere experiencia previa. AI Agents with LangChain & Autonomous Workflows en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.
¿Cuánto tiempo toma la lección «Estrategias de memoria de entidades y resúmenes»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de AI Agents with LangChain & Autonomous Workflows?
Sí. Cada lección de AI Agents with LangChain & Autonomous Workflows incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Conceptos de memoria de los agentes
- Memoria de búfer conversacional
- Soluciones avanzadas de memoria
- Estrategias de memoria de entidades y resúmenes