استراتيجيات ذاكرة الكيانات والملخصات
تجاوز المخازن الأولية بتتبّع الكيانات المسماة والملخصات المتجددة، حتى يتذكر الوكلاء الحقائق المهمة عبر المحادثات الطويلة دون استهلاك مفرط لميزانية الرموز.
استراتيجيات ذاكرة الكيانات والملخصات درس مجاني في AI Agents with LangChain & Autonomous Workflows على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في AI Agents with LangChain & Autonomous Workflows، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة AI Agents with LangChain & Autonomous Workflows 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
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.
الأسئلة الشائعة
هل درس «استراتيجيات ذاكرة الكيانات والملخصات» مجاني؟
نعم — نص درس «استراتيجيات ذاكرة الكيانات والملخصات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة AI Agents with LangChain & Autonomous Workflows، انتقل إلى CoddyKit PRO. تتضمن دورة AI Agents with LangChain & Autonomous Workflows 4 دروس في المجموع.
ماذا ستتعلم في «استراتيجيات ذاكرة الكيانات والملخصات»؟
تجاوز المخازن الأولية بتتبّع الكيانات المسماة والملخصات المتجددة، حتى يتذكر الوكلاء الحقائق المهمة عبر المحادثات الطويلة دون استهلاك مفرط لميزانية الرموز. تتمرن على AI Agents with LangChain & Autonomous Workflows مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ AI Agents with LangChain & Autonomous Workflows؟
لا تُشترط خبرة سابقة. AI Agents with LangChain & Autonomous Workflows على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «استراتيجيات ذاكرة الكيانات والملخصات»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس AI Agents with LangChain & Autonomous Workflows هذا؟
نعم. كل درس في AI Agents with LangChain & Autonomous Workflows يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- مفاهيم ذاكرة الوكيل
- ذاكرة المخزن المؤقت للمحادثة
- حلول الذاكرة المتقدمة
- استراتيجيات ذاكرة الكيانات والملخصات