AIエージェントのための効果的なコンテキスト設計
AIエージェントにとってコンテキストは重要だが有限なリソースであり、効果的な管理・最適化戦略を探る。
キーポイント
プロンプトエンジニアリングからコンテキストエンジニアリングへの進化を提唱
AIエージェント開発におけるコンテキスト管理の重要性を強調
限られたコンテキストウィンドウ内での情報最適化が鍵
複数ターン推論に対応する新しいエンジニアリング手法
影響分析・編集コメントを表示
影響分析
この記事は、単発のプロンプト最適化から、長期的なAIエージェントの振る舞い制御へと焦点が移行していることを示しており、実用的なAIシステム開発の成熟段階を示唆している。Anthropicが提唱するコンテキストエンジニアリングの概念は、業界のベストプラクティス形成に影響を与える可能性が高い。
編集コメント
プロンプトエンジニアリングの次に来る重要な概念を明確に定義しており、実践的なAI開発者にとって必須の視点を提供している。
AIエージェントのための効果的なコンテキストエンジニアリング
AIエージェントにとって、コンテキストは重要ながら有限なリソースである。本記事では、AIエージェントを駆動するコンテキストを効果的に選定・管理する戦略を探る。
応用AI分野で数年間注目を集めてきた「プロンプトエンジニアリング」に続き、新たに「コンテキストエンジニアリング」という用語が台頭してきた。言語モデルを活用した構築は、適切なプロンプトの言葉やフレーズを見つけることよりも、「どのようなコンテキスト構成がモデルの望む動作を生成する可能性が最も高いか」という広範な問いに答える方向へ移行しつつある。
コンテキストとは、大規模言語モデル(LLM)から出力を生成する際に含まれる一連のトークンのことを指す。現在のエンジニアリング上の課題は、所望の結果を一貫して達成するために、LLMの固有の制約に対してこれらのトークンの有用性を最適化することである。LLMを効果的に制御するには、多くの場合「コンテキスト」を考慮した思考、つまり、任意の時点でLLMが利用可能な全体的な状態と、その状態がもたらす可能性のある動作を考えることが必要となる。
本記事では、この新興の技術であるコンテキストエンジニアリングを探求し、制御可能で効果的なエージェントを構築するための洗練された思考モデルを提示する。
コンテキストエンジニアリングとプロンプトエンジニアリングの違い
Anthropicでは、コンテキストエンジニアリングをプロンプトエンジニアリングの自然な進化形と捉えている。プロンプトエンジニアリングは、最適な結果を得るためのLLMへの指示の記述・構成方法を指す。一方、コンテキストエンジニアリングは、LLMの推論中に最適なトークン(情報)のセットを選定・維持するための一連の戦略を指し、プロンプト以外に含まれる可能性のあるすべての他の情報も対象となる。
LLMを用いたエンジニアリングの初期段階では、日常的なチャット以外のユースケースの多くが、単発の分類やテキスト生成タスクに最適化されたプロンプトを必要としたため、プロンプトの作成がAIエンジニアリング作業の主要部分を占めていた。その名が示す通り、プロンプトエンジニアリングの主な焦点は、特にシステムプロンプトをいかに効果的に記述するかにあった。しかし、複数回の推論と長期的な時間軸で動作する、より高度なエージェントの構築に向かうにつれ、システム指示、ツール、Model Context Protocol(MCP)、外部データ、メッセージ履歴など、コンテキスト状態全体を管理する戦略が必要となってきている。
ループ内で動作するエージェントは、次の推論ターンに関連する可能性のあるデータを次々と生成し、この情報は循環的に洗練されなければならない。コンテキストエンジニアリングは、絶えず進化する可能性のある情報の世界から、限られたコンテキストウィンドウに何を取り込むかを選定する技術と科学なのである。
高度なエージェント構築における
原文を表示
Engineering at AnthropicEffective context engineering for AI agents
Context is a critical but finite resource for AI agents. In this post, we explore strategies for effectively curating and managing the context that powers them.
After a few years of prompt engineering being the focus of attention in applied AI, a new term has come to prominence: context engineering. Building with language models is becoming less about finding the right words and phrases for your prompts, and more about answering the broader question of “what configuration of context is most likely to generate our model’s desired behavior?"
Context refers to the set of tokens included when sampling from a large-language model (LLM). The engineering problem at hand is optimizing the utility of those tokens against the inherent constraints of LLMs in order to consistently achieve a desired outcome. Effectively wrangling LLMs often requires thinking in context — in other words: considering the holistic state available to the LLM at any given time and what potential behaviors that state might yield.
In this post, we’ll explore the emerging art of context engineering and offer a refined mental model for building steerable, effective agents.
Context engineering vs. prompt engineering
At Anthropic, we view context engineering as the natural progression of prompt engineering. Prompt engineering refers to methods for writing and organizing LLM instructions for optimal outcomes (see our docs for an overview and useful prompt engineering strategies). Context engineering refers to the set of strategies for curating and maintaining the optimal set of tokens (information) during LLM inference, including all the other information that may land there outside of the prompts.
In the early days of engineering with LLMs, prompting was the biggest component of AI engineering work, as the majority of use cases outside of everyday chat interactions required prompts optimized for one-shot classification or text generation tasks. As the term implies, the primary focus of prompt engineering is how to write effective prompts, particularly system prompts. However, as we move towards engineering more capable agents that operate over multiple turns of inference and longer time horizons, we need strategies for managing the entire context state (system instructions, tools, Model Context Protocol (MCP), external data, message history, etc).
An agent running in a loop generates more and more data that could be relevant for the next turn of inference, and this information must be cyclically refined. Context engineering is the art and science of curating what will go into the limited context window from that constantly evolving universe of possible information.
Why context engineering is important to building capable agents
Despite their speed and ability to manage larger and larger volumes of data, we’ve observed that LLMs, like humans, lose focus or experience confusion at a certain point. Studies on needle-in-a-haystack style benchmarking have uncovered the concept of context rot: as the number of tokens in the context window increases, the model’s ability to accurately recall information from that context decreases.
While some models exhibit more gentle degradation than others, this characteristic emerges across all models. Context, therefore, must be treated as a finite resource with diminishing marginal returns. Like humans, who have limited working memory capacity, LLMs have an “attention budget” that they draw on when parsing large volumes of context. Every new token introduced depletes this budget by some amount, increasing the need to carefully curate the tokens available to the LLM.
This attention scarcity stems from architectural constraints of LLMs. LLMs are based on the transformer architecture, which enables every token to attend to every other token across the entire context. This results in n² pairwise relationships for n tokens.
As its context length increases, a model's ability to capture these pairwise relationships gets stretched thin, creating a natural tension between context size and attention focus. Additionally, models develop their attention patterns from training data distributions where shorter sequences are typically more common than longer ones. This means models have less experience with, and fewer specialized parameters for, context-wide dependencies.
Techniques like position encoding interpolation allow models to handle longer sequences by adapting them to the originally trained smaller context, though with some degradation in token position understanding. These factors create a performance gradient rather than a hard cliff: models remain highly capable at longer contexts but may show reduced precision for information retrieval and long-range reasoning compared to their performance on shorter contexts.
These realities mean that thoughtful context engineering is essential for building capable agents.
The anatomy of effectiv
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み