Agent Builderでのメモリの活用方法
LangChainのAgent Builderにおけるメモリ機能の仕組みと、ユーザーがエージェントに指示を出すことで短期記憶を長期記憶として定着させる実用的な活用方法について解説している。
キーポイント
Agent Builderのメモリ構造
エージェントは「短期記憶(スレッド内)」と「長期記憶(永続ファイルシステム)」の2つのメモリを持ち、後者はMarkdown形式でスキルや指示を保存する。
ユーザーによる記憶の定着化
ユーザーが「そのアプローチを覚えろ」などの明示的な指示を出すことで、エージェントはフィードバックを長期記憶(コアインストラクション)として更新し、次回から同じ結果を得られる。
自律的な記憶提案機能
明確なフィードバックを与えた場合、エージェントは変更を提案しユーザーの承認を得てから記憶に保存する仕組みがあり、明示的な指示がなくても一定の自動化が行われる。
スキルとコンテキストの活用
専門的な文脈や反復作業をスキルの形でメモリに保存することで、エージェントの精度と効率を継続的に向上させることが可能。
Skillsは必要に応じて読み込まれる長期記憶
Skillsはエージェントに事前の全情報暗記を強いるのではなく、タスクに応じて必要な情報のみを読み込む参照ライブラリのような役割を果たし、ハルシネーションを防ぐ。
エージェントのメモリファイルは直接編集可能
Agent Builderはフィードバックに基づいて自身を更新するが、エージェントの思考プロセスを理解したり、小さな変更を迅速に行ったりするために、メモリファイルへの直接編集が推奨される。
影響分析・編集コメントを表示
影響分析
この記事は、エージェント開発における「記憶」の実装方法と運用戦略を具体的に示しており、LangChainエコシステムの利用者にとって実用的な知見を提供する。技術的には大した革新はないものの、ユーザーエクスペリエンスを向上させるためのベストプラクティスとして、現場でのエージェント構築に即座に応用可能な価値がある。
編集コメント
エージェントの「記憶」を抽象的な概念ではなく、ファイルシステムという具体的な実装として説明している点が秀逸です。開発者だけでなくエンドユーザーにとっても、エージェントとの対話品質を高めるための具体的なアクション(指示の出し方)が示されており、実務での活用価値が高い記事です。
著者: ジェイコブ・タルボット
Agent Builderは、フィードバックを記憶するため、使えば使うほど賢くなります。あなたが行うあらゆる修正、共有する好み、うまくいったアプローチは、あなたのエージェントが保持し、次回に適用できるものになります。
メモリは、Agent Builderをチームメイトのように感じさせる要素の一つです。しかし、どんなチームメイトとも同様に、効果的なコミュニケーションの方法を知っておくと役立ちます。ここでは、エージェントのメモリを最大限に活用する3つの実践的な方法を紹介します。
Agent Builderを無料で試す
メモリの仕組みに関する簡単な入門
ヒントの詳細に入る前に、内部で実際に何が起こっているかを理解しておくと役立ちます。ヒントから読み始めたい場合は、先に進んでください。
Agent Builderは、自律的で長時間実行されるタスクのためのLangChainのオープンソースエージェントハーネスである「Deep Agents」上に構築されています。あなたのエージェントは、推論用のLLM、アクションを起こすためのツール(ウェブ検索、Slack、Googleスプレッドシートなど)、サブエージェントを生成する機能、そしてファイルシステムにアクセスできます。
そのファイルシステムが、メモリが存在する場所です。メモリには2つのタイプがあります:
短期記憶: エージェントがタスク中に作成するファイルで、計画、ツール呼び出しの出力(ウェブ検索結果など)、タスクの進捗状況などが含まれます。これらは会話(スレッド)の存続期間中は存在しますが、会話をまたいで保持されることはありません。
長期記憶: エージェントが永続的なパス(/memories/)に保存するファイルです。これらはすべての会話にわたって残り続けます。あなたのエージェントのコアとなる指示やスキルはここに保存されます。メモリは標準的なMarkdownファイルを使用して保存されます。
本当にそれだけです。メモリは抽象的に聞こえますが、エージェントが仕事を上手くこなせるように読み書きする単なるファイルなのです。
エージェントに「覚えるよう」指示する
エージェントと作業している間、あなたは常に有用なコンテキストを生み出しています。うまく機能するフォーマットを繰り返し改良したかもしれませんし、結果をどのように提示してほしいかを正確に洗練させたかもしれません。そのコンテキストは短期記憶に存在しますが、そこに留めておく必要はありません。
エージェントに、学んだことを保存するよう指示できます。次のようなことを試してみてください:
「そのアプローチは非常にうまくいった。今後は常にそれを使用するように指示を更新してくれ」
「私は長い段落よりも箇条書きを好むことを覚えておいてくれ」
「この会話から学んだことをあなたのメモリに組み込んでくれ」
あなたのエージェントは、生産的な作業セッションの後にチームメイトがメモを取るのと同じように、あなたのフィードバックに基づいて長期的な指示を更新します。時間が経つにつれて、これは修正が少なくなり、最初からより良い結果が得られることを意味します。
実際には、このステップが常に必要とは限りません。もし「文章スタイルを直接的で簡潔な散文に変えてくれ」のように明確なフィードバックをエージェントに与えると、エージェントはそれを覚える価値のあることとして認識します。エージェントは指示の変更を提案し、保存する前にあなたの承認を求めます。エージェントに覚えるよう指示することが最も有用なのは、学び取るべきことがあまり明らかでない場合です。例えば、一緒に問題について繰り返し作業し、うまくいくアプローチにたどり着いたが、それを明示的に述べたことがないような場合です。
0:00 /0:23 1× 専門的なコンテキストにはスキルを使用する
スキルは長期記憶の一形態ですが、重要な区別があります: スキルは、タスクがそれを必要とするときにのみ読み込まれます。これは、エージェントにすべてを事前に暗記させる代わりに、参考図書館を与えるようなものと考えてください。エージェントは棚にあるタイトルを見て、関連があるときだけ本を取り出します。
これは、より多くのコンテキストが常に良いとは限らないため重要です。すべてを一度に保持しようとするエージェントは、現在のタスクにとって重要なことに集中できなくなる可能性があります。これは幻覚(誤った生成)を引き起こす原因となり得ます。
実例を挙げましょう。私は自社製品についてのコンテンツ作成に使用するエージェントを持っています。LangSmith Deploymentについて書いているときは、エージェントにその製品の機能、対象ユーザー、ポジショニングを参照してほしいです。Agent Builderについて書いているときは、まったく異なるコンテキストが必要です。そして、LangChainの今後のエージェントカンファレンス「Interrupt」のような無関係なことについて書いているときは、詳細な製品コンテキストはまったく必要ありません。
そこで、私は各製品ごとにスキルを設定しました。私のエージェントのコア指示は、声のトーンや文章スタイルを扱います。スキルは、製品固有のコンテキストを扱います。エージェントは、私が何について書いているかに基づいて適切なスキルを取り込み、それ以外は無視します。
あなたはいつでもエージェントにスキル作成を依頼できます: 「[トピック]のためのスキルを作成してくれ。[エージェントが必要とするコンテキストの内容]を含めて」
0:00 /0:10 1× エージェントのメモリを直接編集する
あなたのエージェントの指示と設定ファイルは、直接編集可能です。Agent Builderはあなたのフィードバックに基づいて自身の指示を更新するので、これを実行する必要はありません。しかし、考慮すべき2つの良い理由があります。
エージェントの考え方を理解するのに役立ちます。エージェントの指示を読むことは、チームメイトのプロジェクト計画をレビューするようなものです。エージェントがどのようにあなたの問題にアプローチしているか、何を優先しているか、その前提があなたのものと一致していない可能性がある場所を見ることができます。もし、不要なステップや誤った前提など、何かがおかしく見える場合は、直接修正できます。
時には、単に速いからです。スケジュールされたタスクの実行時間を変更したい場合や、指示の1行を微調整したい場合、直接編集は数秒で済みます。エージェントに変更を依頼することもできますが、小さく正確な更新の場合は、自分でファイルを編集するのが最速の方法となることがあります。
エージェントの指示を表示および編集するには、エージェントのメモリファイルに移動できます。
0:00 /0:15 1× 構築を始めよう
これらは、時間の経過とともにあなたのエージェントをより賢くするためのいくつかの簡単な方法です: 覚えるよう指示すること、専門的なスキルを与えること、内部を覗くことを恐れないこと。
もし気に入ったものを作成したら、コミュニティSlackで私たちと共有してください。
Agent Builderを試す
ニュースレターに参加する
LangChainチームとコミュニティからの最新情報
リクエストを処理中です...
成功しました!受信トレイを確認し、リンクをクリックして購読を確認してください。
申し訳ありません。問題が発生しました。もう一度お試しください。
原文を表示
By Jacob Talbot
Agent Builder gets better the more you use it because it remembers your feedback. Every correction you make, preference you share, and approach that works well is something that your agent can hold onto and apply the next time.
Memory is one of the things that makes Agent Builder feel like a teammate. But like any teammate, it helps to know how to communicate with them effectively. Here are three practical ways to make the most of your agent's memory.
Try Agent Builder free
A quick primer on how memory works
Before we dig into the tips, it helps to understand what's actually going on under the hood. You can skip ahead to the tips if you'd prefer.
Agent Builder is built on Deep Agents, LangChain's open source agent harness for autonomous, long-running tasks. Your agent has access to an LLM for reasoning, tools for taking actions (like web search, Slack, or Google Sheets), the ability to spawn subagents, and a filesystem.
That filesystem is where memory lives. There are two types of memory:
Short-term memory: Files your agent creates during a task such as plans, outputs from tool calls (such as web search results), and task progress. These exist for the duration of the conversation, or thread, but don’t persist across conversations.
Long-term memory: Files your agent saves to a persistent path (/memories/). These stick around across every conversation. Your agent's core instructions and skills live here. Memory is stored using standard Markdown files.
That's really it. Memory sounds abstract, but it's just files your agent can read and write to get better at its job.
Tell your agent to remember
When you're working with your agent, you're constantly generating useful context. Maybe you've iterated on a format that works well, or you've refined exactly how you want results presented. That context lives in short term memory but it doesn't have to stay there.
You can tell your agent to save what it's learned. Try something like:
"That approach worked really well. Update your instructions to always use that going forward."
"Remember that I prefer bullet points over long paragraphs."
"Incorporate what you learned from this conversation into your memory."
Your agent will update its long-term instructions based on your feedback in the same way a teammate would take notes after a productive working session. Over time, this means fewer corrections and better results from the start.
In practice, this step isn't always necessary. If you give your agent clear feedback, like "Change your writing style to direct, concise prose," it will recognize that as something worth remembering. It'll propose the change to its instructions and ask for your approval before saving it. Telling your agent to remember is most useful when the takeaway is less obvious, such as when you've been iterating on a problem together and arrived at an approach that works, but never stated it explicitly.
0:00 /0:23 1× Use skills for specialized context
Skills are a form of long-term memory, but with an important distinction: they're only loaded when the task calls for them. Think of it like giving your agent a reference library instead of making it memorize everything upfront. The agent sees the titles on the shelf and only pulls a book down when it's relevant.
This matters because more context isn't always better. An agent trying to hold onto everything at once can lose focus on what matters for the current task. This can lead to hallucinations.
Here's a practical example. I have an agent I use for writing content about our products. When I'm writing about LangSmith Deployment, I want the agent to reference that product's features, audience, and positioning. When I'm writing about Agent Builder, it needs different context entirely. And when I'm writing about something unrelated, like LangChain’s upcoming agent conference, Interrupt, it doesn't need detailed product context at all.
So I set up skills for each product. My agent's core instructions handle voice and writing style. The skills handle product-specific context. The agent pulls in the right skill based on what I'm writing about and ignores the rest.
You can ask your agent to create a skill anytime: "Create a skill for [topic] that includes [what context the agent needs]."
0:00 /0:10 1× Edit your agent's memory directly
Your agent’s instructions and configuration files are accessible to edit directly. You don't need to do this because Agent Builder updates its own instructions based on your feedback. But there are two good reasons to consider it.
It helps you understand how your agent thinks. Reading your agent's instructions is like reviewing a teammate's project plan. You can see how the agent is approaching your problem, what it prioritizes, and where its assumptions might not match yours. If something looks off, such as an unnecessary step or a wrong assumption, you can fix it directly.
Sometimes it's just faster. If you want to change when a scheduled task runs, or tweak a single line in the instructions, a direct edit takes seconds. Asking the agent to make the change works too, but for small, precise updates, editing the file yourself can be the quickest path.
To view and edit your agent's instructions, you can navigate to the agent's memory files.
0:00 /0:15 1× Start building
These are a few simple ways to make your agent smarter over time: tell it to remember, give it specialized skills, and don't be afraid to look under the hood.
If you build something you love, share it with us in the Community Slack.
Try Agent Builder
Join our newsletter
Updates from the LangChain team and community
Processing your application...
Success! Please check your inbox and click the link to confirm your subscription.
Sorry, something went wrong. Please try again.
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み