0Pricing
AI Agents with LangChain & Autonomous Workflows · レッスン

エンティティと要約のメモリ戦略

単純なバッファを超え、名前付きエンティティと逐次要約を追跡して、トークン予算を圧迫せずに長い会話でも重要な事実をエージェントに記憶させます。

「エンティティと要約のメモリ戦略」はCoddyKit上の無料AI Agents with LangChain & Autonomous Workflowsレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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時間対応のAIチューター)、AI Agents with LangChain & Autonomous Workflowsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 AI Agents with LangChain & Autonomous Workflowsコースには全4レッスンが含まれています。

「エンティティと要約のメモリ戦略」で何を学びますか?

単純なバッファを超え、名前付きエンティティと逐次要約を追跡して、トークン予算を圧迫せずに長い会話でも重要な事実をエージェントに記憶させます。 ブラウザで直接実行するハンズオンコードでAI Agents with LangChain & Autonomous Workflowsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

AI Agents with LangChain & Autonomous Workflowsを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのAI Agents with LangChain & Autonomous Workflowsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「エンティティと要約のメモリ戦略」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このAI Agents with LangChain & Autonomous Workflowsレッスンでコードを書いて実行できますか?

はい。すべてのAI Agents with LangChain & Autonomous Workflowsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. エージェントメモリの概念
  2. 会話バッファメモリ
  3. 高度なメモリソリューション
  4. エンティティと要約のメモリ戦略
← AI Agents with LangChain & Autonomous Workflowsに戻る