0Pricing
AI Agents with LangChain & Autonomous Workflows · Pelajaran

Strategi Memori Entitas dan Ringkasan

Melampaui buffer mentah dengan melacak entitas bernama dan ringkasan bergulir agar agen mengingat fakta penting dalam percakapan panjang tanpa menghabiskan anggaran token.

Strategi Memori Entitas dan Ringkasan adalah pelajaran AI Agents with LangChain & Autonomous Workflows gratis di CoddyKit. Ini adalah pelajaran 4 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar AI Agents with LangChain & Autonomous Workflows, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus AI Agents with LangChain & Autonomous Workflows mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

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.

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Strategi Memori Entitas dan Ringkasan” gratis?

Ya — teks lengkap “Strategi Memori Entitas dan Ringkasan” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus AI Agents with LangChain & Autonomous Workflows, upgrade ke CoddyKit PRO. Kursus AI Agents with LangChain & Autonomous Workflows mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Strategi Memori Entitas dan Ringkasan”?

Melampaui buffer mentah dengan melacak entitas bernama dan ringkasan bergulir agar agen mengingat fakta penting dalam percakapan panjang tanpa menghabiskan anggaran token. Kamu berlatih AI Agents with LangChain & Autonomous Workflows dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai AI Agents with LangChain & Autonomous Workflows?

Tidak diperlukan pengalaman sebelumnya. AI Agents with LangChain & Autonomous Workflows di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 4 dari 4.

Berapa lama pelajaran “Strategi Memori Entitas dan Ringkasan” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran AI Agents with LangChain & Autonomous Workflows ini?

Ya. Setiap pelajaran AI Agents with LangChain & Autonomous Workflows menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Konsep Memori Agen
  2. Memori Penyangga Percakapan
  3. Solusi Memori Tingkat Lanjut
  4. Strategi Memori Entitas dan Ringkasan
← Kembali ke AI Agents with LangChain & Autonomous Workflows