AIニュース最前線
最新ニュースAI日報Hacker日報週報動画AIツールトレンド企業

AIニュース最前線

世界中のAI最新情報を日本語で毎時更新

最新ニュース日報トレンド企業プレミアムRSS
© 2026 ainew.jp特定商取引法に基づく表記
ニュース一覧元記事を開く
LangChain Blog·2026年6月17日 03:04·約10分で読める

深層エージェントにおけるコンテキスト管理

#Deep Agents#Context Management#LangChain#LLM Orchestration
TL;DR

LangChain Blog は、複雑なタスクを処理する深層エージェントの信頼性を高めるため、コンテキスト管理と最適化の手法について詳細に解説している。

AI深層分析2026年6月17日 04:03
4
重要/ 5段階
深度40%
5
関連度30%
5
実用性20%
4
革新性10%
4

キーポイント

1

深層エージェントにおけるコンテキストの重要性

長期的かつ複雑なタスクを実行するエージェントにおいて、適切な文脈(コンテキスト)を維持・管理することが性能向上の鍵となることを指摘している。

2

コンテキスト管理の最適化手法

不要な情報のフィルタリングや、関連性の高い情報の優先順位付けなど、リソース効率を最大化するための具体的な管理戦略を提案している。

3

エラー削減と信頼性向上

文脈の喪失や混同によるハルシネーション(幻覚)を防ぎ、エージェントの意思決定プロセスにおける一貫性と信頼性を高める手法を解説している。

影響分析・編集コメントを表示

影響分析

本記事は、単なるプロンプトエンジニアリングを超え、自律的なエージェントシステムを構築する際の基盤となる「文脈管理」の重要性を明確に示した。これにより、開発者はより複雑で信頼性の高い AI エージェントを設計・実装するための具体的な指針を得ることができ、次世代の AI アプリケーション開発における標準的なプラクティスとして定着する可能性が高い。

編集コメント

エージェント技術が実用段階へと移行する中で、コンテキストの扱い方が成否を分ける重要な要素として浮上しており、開発者にとって必読の内容と言えます。

*チェスター・カームとメイソン・ドーハーティによる*

AI エージェントの処理可能なタスク長さが継続的に拡大している中、コンテキストローテーションを防ぎ、LLM の有限なメモリ制約を管理するために、効果的なコンテキスト管理が極めて重要になっています。

Deep Agents SDKは、LangChain が提供するオープンソースで、必要な機能がすべて備わったエージェント・ハネスです。これは、計画を立てたり、サブエージェントを起動したり、ファイルシステムと連携して複雑で長時間実行されるタスクを実行する能力を持つエージェントを構築するための容易な道筋を提供します。これらの種類のタスクは一般的にモデルのコンテキストウィンドウを超えるため、この SDK はコンテキスト圧縮を促進するさまざまな機能を実装しています。

コンテキスト圧縮とは、タスク完了に関連する詳細情報を保持しつつ、エージェントの作業メモリ内の情報量を削減する技術を指します。これには、過去の対話の要約、古くなった情報のフィルタリング、あるいは何を保持し何を破棄するかを戦略的に決定することが含まれます。

Deep Agents は、エージェントがファイルのリスト表示、読み取り、書き込み、検索、パターンマッチング、およびファイル実行などの操作を実行できるようにする ファイルシステム抽象化 を実装しています。エージェントは必要に応じてファイルシステムを使用してオフロードされたコンテンツを検索・取得します。

Deep Agents は、異なる頻度でトリガーされる 3 つの主要な圧縮技術を実装しています:

  • 大規模なツール結果のオフロード: 大規模なツールの応答が発生するたびに、それらをファイルシステムにオフロードします。
  • 大規模なツール入力のオフロード: コンテキストサイズが閾値を超えると、ツール呼び出しからの古い書き込み/編集引数をファイルシステムにオフロードします。
  • 要約: コンテキストサイズが閾値を超え、さらにオフロード可能なコンテキストが存在しない場合、メッセージ履歴を圧縮するために要約ステップを実行します。

コンテキスト制限を管理するため、Deep Agents SDK はモデルのコンテキストウィンドウサイズの閾値分数でこれらの圧縮ステップをトリガーします。(内部では、特定のモデルに対するトークン閾値にアクセスするために LangChain の モデルプロファイル を使用しています。)

ツール結果のオフローディング

ツール呼び出しからの応答(例:大規模ファイルの読み取りや API 呼び出しの結果)は、モデルのコンテキストウィンドウを超えることがあります。Deep Agents は、20,000 トークンを超えるツール応答を検出すると、その応答をファイルシステムにオフロードし、代わりにファイルパス参照と最初の 10 行のプレビューで置換します。その後、エージェントは必要に応じて内容を再読したり検索したりできます。

image
image

ツール入力のオフローディング

ファイルの書き込みおよび編集操作は、エージェントの会話履歴に完全なファイル内容を含むツール呼び出しを残します。このコンテンツはすでにファイルシステムに永続化されているため、多くの場合冗長です。セッションコンテキストがモデルの利用可能なウィンドウの 85% を超えると、Deep Agents は古いツール呼び出しを切り捨て、ディスク上のファイルへのポインタで置換して、アクティブなコンテキストのサイズを削減します。

image
image

要約

オフローディングではもはや十分なスペースが得られない場合、Deep Agents は要約に切り替えます。このプロセスには 2 つの構成要素があります:

  • コンテキスト内サマリー:LLM が会話のセッション意図、作成されたアーティファクト、および次のステップを含む構造化された要約を生成し、エージェントの作業メモリ内の完全な会話履歴を置き換えます。(Deep Agents 要約プロンプトを参照)
  • ファイルシステム保存:完全な元の会話メッセージは、正真正銘の記録としてファイルシステムに書き込まれます。

この二重のアプローチにより、エージェントはサマリーを通じて目標と進捗の認識を維持しつつ、必要に応じて特定の詳細を検索して回復する能力(ファイルシステム検索経由)も保持されます。モデルが read_file ツールを使用して以前オフロードされたメッセージを取得している例については、こちらのトレース をご覧ください。

image
image

実践における様子

上記の手法は文脈管理のための機械装置を提供しますが、実際に機能しているかどうかをどう確認すればよいのでしょうか?terminal-bench などのベンチマークで捉えられた実世界のタスクでの実行では、文脈圧縮が断続的にトリガーされる可能性があり、その影響を単独で特定することが困難です。

ハネスの個々の機能のシグナルを高めるために、ベンチマークデータセット上でより積極的に関与させることが有用であることがわかりました。例えば、利用可能なコンテキストウィンドウの 10〜20% で要約トリガーを発動すると全体の性能が最適化されない可能性がありますが、それによって要約イベントが大幅に増加します。これにより、異なる構成(例:実装のバリエーション)を比較することが可能になります。例えば、エージェントに頻繁な要約を強制することで、セッション意図と次のステップのために専用のフィールドを追加した DeepAgents の要約プロンプトに対する単純な 変更 がパフォーマンス向上にどのように寄与するかを特定できます。

image
image

図:terminal-bench-2 における Claude Sonnet 4.5 のサンプル実行時のトークン使用量の推移(灰色の線はすべての実行、彩色された線は特定の 2 つの例を強調表示)。緑色の線は、要約イベントによって会話履歴が圧縮されるターン 20 付近で劇的なトークンの減少を示しています。オレンジ色の線は、大きなファイル書き込みツール呼び出しがコンテキストから除外されるターン 40 付近でのより小さな削減を示しています。Deep Agents のデフォルトである 85% ではなく、コンテキストウィンドウの 25% で圧縮トリガーを発動させることで、研究対象となるイベントをより多く生成できます。

ターゲット型評価

Deep Agents SDK は、個々のコンテキスト管理メカニズムを分離して検証するために設計された一連のターゲット型評価(evals)を維持しています。これらは意図的に小規模なテストであり、特定の失敗モードを明白かつデバッグ可能にするものです。

これらの evals の目的は、広範なタスク解決能力を測定することではなく、エージェントのハネス(harness)が特定のタスクの実行を妨げないことを保証することです。例えば:

  • 要約(summarization)はエージェントの目標を維持したか?一部の評価では意図的にタスク実行中に要約トリガーを発生させ、その後エージェントが継続して動作するかを確認します。これにより、要約がエージェントの状態だけでなくその軌跡も維持していることが保証されます。
  • エージェントは要約によって失われた情報を回復できるか?ここでは会話の初期段階に「干し草の中の針(needle-in-the-haystack)」と呼ばれる事実を埋め込み、要約イベントを強制的に発生させた後、タスク完了のためにその事実を後で想起することを要求します。要約後のアクティブなコンテキストにはこの事実は存在せず、ファイルシステム検索を通じて回復する必要があります。

これらのターゲット型評価は、コンテキスト管理のための統合テスト(integration tests)として機能します。これらは完全なベンチマーク実行を代替するものではなく、反復時間を大幅に短縮し、失敗の原因がエージェント全体の動作ではなく特定の圧縮メカニズムに帰属することを可能にします。

ガイダンス

ご自身のコンテキスト圧縮戦略を評価する際には、以下の点を強調いたします:

  • 実際の現実世界ベンチマークから始め、個々の機能をストレステストしてください。まず代表的なタスクにハネスを実行してベースラインパフォーマンスを確立します。その後、圧縮をより積極的にトリガーするように人工的に調整します(例:コンテキストの 85% ではなく 10-20% で)。これにより、実行あたりの圧縮イベント数が増加し、個々の機能からのシグナルが強調されるため、異なるアプローチ(要約プロンプトの変異など)を比較しやすくなります。
  • 回復可能性をテストしてください。コンテキスト圧縮は、重要な情報が依然としてアクセス可能である場合にのみ有用です。圧縮後もエージェントが元の目標に向かって継続できること、かつ必要に応じて特定の情報を回復できることを検証するターゲット型のテストを含めてください(例:重要な事実が要約されても後で検索しなければならない「干し草の針」シナリオなど)。
  • ゴールドリフトを監視してください。最も厄介な失敗モードは、要約後にユーザーの意図を追跡できなくなるエージェントです。これは、要約後のターンで明確化を求めるためにタスクが完了してしまう、または誤ってタスク完了と宣言してしまう形で現れることがあります。意図されたタスクからのより微妙な逸脱は、要約に起因するものとして特定するのが難しい場合があります。サンプルデータセットに対して頻繁な要約を強制することで、これらの失敗を表面化できる可能性があります。

Deep Agents ハネスのすべての機能はオープンソースです。最新バージョンを試して、どの圧縮戦略があなたのユースケースに最も適しているか教えてください!

原文を表示

*By Chester Curme and Mason Daugherty*

As the addressable task length of AI agents continues to grow, effective context management becomes critical to prevent context rot and to manage LLMs’ finite memory constraints.

The Deep Agents SDK is LangChain’s open source, batteries-included agent harness. It provides an easy path to build agents with the ability to plan, spawn subagents, and work with a filesystem to execute complex, long-running tasks. Because these sorts of tasks can generally exceed models’ context windows, the SDK implements various features that facilitate context compression.

Context compression refers to techniques that reduce the volume of information in an agent's working memory while preserving the details relevant to completing the task. This might involve summarizing previous interactions, filtering out stale information, or strategically deciding what to retain and what to discard.

Deep Agents implements a filesystem abstraction that allows agents to perform operations such as listing, reading, and writing files, as well as search, pattern matching, and file execution. Agents use the filesystem to search and retrieve offloaded content as needed.

Deep Agents implements three main compression techniques, triggered at different frequencies:

  • Offloading large tool results: We offload large tool responses to the filesystem whenever they occur.
  • Offloading large tool inputs: When the context size crosses a threshold, we offload old write/edit arguments from tool calls to the filesystem.
  • Summarization: When the context size crosses the threshold, and there is no more context eligible for offloading, we perform a summarization step to compress the message history.

To manage context limits, the Deep Agents SDK triggers these compression steps at threshold fractions of the model's context window size. (Under the hood, we use LangChain's model profiles to access the token threshold for a given model.)

Offloading large tool results

Responses from tool invocations (e.g., the result of reading a large file or an API call) can exceed a model's context window. When Deep Agents detects a tool response exceeding 20,000 tokens, it offloads the response to the filesystem and substitutes it with a file path reference and a preview of the first 10 lines. Agents can then re-read or search the content as needed.

Offloading large tool inputs

File write and edit operations leave behind tool calls containing the complete file content in the agent's conversation history. Since this content is already persisted to the filesystem, it's often redundant. As the session context crosses 85% of the model’s available window, Deep Agents will truncate older tool calls, replacing them with a pointer to the file on disk and reducing the size of the active context.

Summarization

When offloading no longer yields sufficient space, Deep Agents falls back to summarization. This process has two components:

  • In-context summary: An LLM generates a structured summary of the conversation—including session intent, artifacts created, and next steps—which replaces the full conversation history in the agent's working memory. (See the Deep Agents summarization prompt.)
  • Filesystem preservation: The complete, original conversation messages are written to the filesystem as a canonical record.

This dual approach ensures the agent maintains awareness of its goals and progress (via the summary) while preserving the ability to recover specific details when needed (via filesystem search). See an example in this trace, where the model uses the read_file tool to fetch previously offloaded messages.

What this looks like in practice

While the techniques above provide the machinery for context management, how do we know they're actually working? Runs on real-world tasks, as captured in benchmarks such as terminal-bench, may trigger context compression sporadically, making it difficult to isolate their impact.

We’ve found it useful to increase the signal of individual features of the harness by engaging them more aggressively on benchmark datasets. For example, while triggering summarization at 10 - 20% of the available context window may lead to suboptimal overall performance, it produces significantly more summarization events. This allows for different configurations (e.g., variations of your implementation) to be compared. For example, by forcing the agent to summarize frequently, we could identify how simple changes to the deepagents summarization prompt, in which we added dedicated fields for the session intent and next steps, help improve performance.

Figure: Token usage over time in sample runs of Claude Sonnet 4.5 on terminal-bench-2 (gray lines show all runs; colored lines highlight two specific examples). The green line shows a dramatic token drop around turn 20 when a summarization event compresses the conversation history. The orange line shows a smaller reduction around turn 40 when a large file write tool call is evicted from context. By triggering compression at 25% of the context window (rather than the Deep Agents default of 85%), we generate more events to study.

Targeted evals

The Deep Agents SDK maintains a set of targeted evaluations designed to isolate and validate individual context-management mechanisms. These are deliberately small tests that make specific failure modes obvious and debuggable.

The goal of these evals is not to measure broad task-solving ability, but to ensure that the agent’s harness does not get in the way of certain tasks. For example:

  • Did summarization preserve the agent’s objective? Some evals deliberately trigger summarization mid-task and then check whether the agent continues. This ensures that summarization preserves not only agent state but also its trajectory.
  • Can the agent recover information that was summarized away? Here we embed a “needle-in-the-haystack” fact early in the conversation, force a summarization event, and then require the agent to recall that fact later to complete the task. The fact is not present in the active context after summarization and must be recovered via filesystem search.

These targeted evals act as integration tests for context management: they don’t replace full benchmark runs, but they significantly reduce iteration time and make failures attributable to specific compression mechanisms rather than overall agent behavior.

Guidance

When evaluating your own context compression strategies, we’d emphasize:

  • Start with real-world benchmarks, then stress-test individual features. Run your harness on representative tasks first to establish baseline performance. Then, artificially trigger compression more aggressively (e.g., at 10-20% of context instead of 85%) to generate more compression events per run. This amplifies the signal from individual features, making it easier to compare different approaches (e.g. variations in your summarization prompt).
  • Test recoverability. Context compression is only useful if critical information remains accessible. Include targeted tests that verify agents can both continue toward their original goal after compression and recover specific details when needed (e.g., needle-in-the-haystack scenarios where a key fact is summarized away but must be retrieved later).
  • Monitor for goal drift. The most insidious failure mode is an agent that loses track of the user's intent after summarization. This may manifest as the agent completing in the turn after summarization to ask for clarification, or to mistakenly declare the task complete. More subtle deviations from the intended task may be harder to attribute to summarization; forcing frequent summarization on sample datasets may help surface these failures.

All features of the Deep Agents harness are open source. Try out the latest version and let us know what compression strategies work best for your use cases!

この記事をシェア

関連記事

LangChain Blog★42026年6月19日 02:32

LangSmith のノーコードエージェントビルダーの紹介

LangChain が提供する LangSmith に、プログラミング不要で AI エージェントを構築できる新機能が導入された。

LangChain Blog★42026年6月16日 01:48

マルチエージェントシステムをいつどのように構築するか

LangChain は、複数の AI エージェントが協調して複雑なタスクを解決するマルチエージェントシステムの設計手法と実装タイミングについて解説している。

LangChain Blog★32026年6月16日 01:43

エージェントフレームワークをどう捉えるべきか

LangChain Blog は、開発者が複雑なエージェントフレームワークの設計思想や選択基準を理解するための思考法を解説している。

今日のまとめ

AI日報で今日の重要ニュースをまとめ読み

ニュース一覧に戻る元記事を読む