Anthropic Releases "AI Agent Context Engineering Guide"
In the field of artificial intelligence applications, prompt engineering has long held a prominent position, but now a new term is gradually emerging: context engineering. Based on language...
existartificialintelligentIn the field of application, prompt engineering has long been the focus, but now a new term is gradually emerging:Context engineeringThe work of building language models is no longer limited to finding the perfect one.Prompt wordsInstead of focusing on specific sentences, the focus shifts to answering more macro-level questions:What kind of context engineering configuration is most likely to elicit the model's expected behavior?
Context refers to the context derived from a large language model (LLMThe set of tokens included during sampling. The current engineering problem is how to...LLMOptimize the utility of these symbols under inherent constraints to stably achieve the target outcome. Effectively manage...LLMTypically, it is required to haveContextual thinking—that is, comprehensive considerationLLMThe overall state available at any given time, and what potential behaviors that state might trigger.
This article will explore this emerging context engineering technique and provide a refined set of mental models for building controllable andHigh efficiencyofartificialintelligentAgents.
Contextual Engineering vs. Hint Engineering
According to Anthropic, context engineering is a natural evolution of cue engineering. Cue engineering focuses on writing and organizing...LLMInstructions for obtaining optimal results (see our documentation for an overview and...)practical(strategy); while context engineering is a set of strategies.LLMThe strategy for planning and maintaining the optimal set of symbols (information) during the reasoning process, including all other information that may enter the context besides the cues.
existLLMEarly in the project, the design was...AIAt the heart of engineering work, since most use cases beyond everyday chat require hints optimized for single-round classification or text generation tasks, hint engineering, as its name suggests, primarily focuses on how to write effective hints (especially system hints). However, as we shift towards building hints that can operate across multiple rounds of inference and longer time spans...intelligentbodyWe need a strategy to manage the entire context state (system instructions, tools, Model Context Protocol (MCP), external data, message history, etc.).
LoopingintelligentbodyThis generates an ever-increasing amount of data that may be relevant to the next round of reasoning, and this information must be repeatedly refined. Context engineering is precisely the art and science of planning which content should enter a limited context window from the ever-evolving information universe.
Why context engineering is important for buildingpowerfulintelligentbodyImportant
althoughLLMWhile they are incredibly fast and capable of handling ever-increasing volumes of data, we've observed that, like humans, they can lose focus or become disorganized at certain points. Research on "needle-in-a-haystack" benchmarking reveals...Context rotPhenomenon: As the number of symbols in the context window increases, the model's ability to accurately recall contextual information decreases.
While some models exhibit slower decay, this characteristic is pervasive. Therefore, context must be considered a finite resource with diminishing marginal returns. Similar to the finite capacity of human working memory,LLMParsing large amounts of context consumes an "attention budget." Each newly introduced symbol consumes a portion of this budget, thus exacerbating the need for careful planning.LLMThe necessity of using symbols.
This scarcity of attention stems fromLLMArchitectural constraints.LLMBased on the Transformer architecture, each symbol can follow other symbols in the entire context, forming n² pairs of relations (where n is the number of symbols). As the length of the context increases, the model's ability to capture these relations is diluted, resulting in a natural tension between context scale and attention focus. Furthermore, the model's attention patterns are derived from the training data distribution (where short sequences are generally more common), meaning the model has limited experience with cross-contextual dependencies and insufficient specialized parameters.
Techniques such as positional encoding interpolation allow models to handle longer sequences by adapting them to the small context of the original training, but this can weaken symbolic position understanding. These factors create a performance gradient (rather than a hard cliff): the model remains highly usable in long contexts, but its accuracy in information retrieval and long-range inference may be lower than its performance in short contexts.
These realities imply that thoughtful context engineering is crucial for constructing...powerfulintelligentbodyIt is of utmost importance.
High efficiencyContext
GivenLLMGiven a limited attention budget, excellent contextual engineering means finding...Minimal set of high-signal symbolsThis aims to maximize the likelihood of achieving the desired outcome. Implementing this practice is easier said than done; below, we will explain the specific implications of this guiding principle in different contextual components.
System promptIt should be extremely clear, usingSimpleDirect language, suitableintelligentbodyThe appropriate level of understanding is the "Goldilocks zone" between two common failure modes. At one end, engineers hard-code complex, fragile logic in hints to elicit precise behavior, which introduces fragility and increases maintenance complexity; at the other end, they provide vague, high-level guidance that fails to provide adequate support.LLMThe output should provide specific signals or share context for erroneous assumptions. An optimal balance needs to be struck: specific enough to effectively guide behavior, yet flexible enough to provide strong heuristic guidance.
We recommend organizing prompts into different blocks (such as <background information>, <instructions>, ##tool guidance, ##output description, etc.) and using techniques such as XML tags or Markdown headings to delineate these blocks—although the exact format of the prompts may become less important as the model's capabilities improve.
Regardless of how system prompts are constructed, the goal should be to achieve...Minimal Information SetTo provide a complete overview of the expected behavior (Note: Minimal does not necessarily mean short; sufficient information still needs to be provided to ensure...)intelligentbody(Adhere to expected behavior). It's best to start with minimal testing tips, adding clear instructions and examples based on the failure modes found in the initial tests to improve performance.
toolletintelligentbodyInteracting with the environment and introducing new, additional context into the work. Because tools define...intelligentbodyThe contract between itself and its information/action space necessitates that tools improve efficiency: both returning symbolsHigh efficiencyThe information also encouragedHigh efficiencyofintelligentbodyBehavior.
In the use ofAIintelligentbodywriteAIintelligentbodyIn Tools, we discussed buildingLLMTools that are easy to understand and have minimal functional overlap. Similar to well-designed codebase functions, tools should be self-contained, robust, and have a very clear purpose. Input parameters should also be descriptive, explicit, and leverage the inherent strengths of the model.
The most common failure mode is a bloated toolset that covers too many functions or leads to ambiguous decision points regarding which tool to use. If human engineers cannot determine which tool should be used in a specific situation, they cannot be expected to succeed.AIintelligentbodyTo do better. As will be discussed later, forintelligentbodyPlanning a minimum viable toolset also enables more reliable context maintenance and pruning in long interactions.
Provide examples(i.e., few-sample hints) is a well-known best practice, and we continue to strongly recommend it. However, teams often cram a long list of edge cases into the hints in an attempt to clarify...LLMAll possible rules that should be followed when performing a specific task. We do notrecommendInstead of advocating this approach, it is recommended to develop a diverse set of standard examples to effectively depict...intelligentbodyThe expected behavior.LLMIn this context, the example is the "picture" that embodies the idea that "a picture is worth a thousand words".
Our overall guideline for context components (system prompts, tools, examples, message history, etc.) is: be thoughtful and keep contextual information rich and concise. Now let's delve into runtime dynamic context retrieval.
Contextual retrieval andintelligentbodysearch
In ConstructionHigh efficiencyAIintelligentbodyIn the article, we emphasized that it was based onLLMWorkflow andintelligentbodyThe difference. Since the publication of this article, we have tended to believe one.Simpleofintelligentbodydefinition:Autonomous use of tools within a loopLLM.
In our collaborations with clients, we have witnessed the convergence of this field.SimpleParadigm. As the capabilities of the underlying model improve,intelligentbodyThe level of autonomy can be scaled: smarter models allowintelligentbodyIt can independently navigate detailed problem spaces and recover from errors.
We see engineers designintelligentbodyThe way of communicating is changing. Today, many...AIThe native application employs some form of embedding-based pre-inference retrieval, in order to...intelligentbodyReasoning emerges from important context. As the field shifts towards more...intelligentbodyAs a result, the team is increasingly using "just-in-time" contextual strategies to enhance these retrieval systems.
Built using the "instant" methodintelligentbodyInstead of pre-processing all relevant data, Anthropic maintains lightweight identifiers (file paths, storage queries, web page links, etc.) and uses these references to dynamically load data into the context at runtime via tools.intelligentbodyEncoding schemeClaude Code employs this approach to perform complex data analysis on large databases. The model can write targeted queries, store results, and analyze massive amounts of data using Bash commands such as `head` and `tail`, without loading the complete data object into the context. This method mimics human cognition: we typically don't memorize entire information repositories, but instead introduce external organization and indexing systems (such as file systems, inboxes, and bookmarks) to retrieve relevant information as needed.
In addition to storage efficiency, the metadata of these references providesHigh efficiencyMechanisms for optimizing behavior (whether explicitly provided or intuitively perceived). This applies to operations within the file system.intelligentbodyThe file named `test_utils.py` in the `tests` folder and the file with the same name in `src/core_logic.py` implicitly serve different purposes. Folder hierarchy, naming conventions, and timestamps all provide important signals to help humans and...intelligentbodyUnderstand how and when to use information.
letintelligentbodyAutonomous navigation and data retrieval also supportGradual disclosure(progressive disclosure) – that is, allowingintelligentbodyThe relevant context is gradually discovered through exploration. Each interaction generates context that guides the next decision: file size implies complexity; naming conventions indicate purpose; timestamps can act as proxy for relevance.intelligentbodyIt can assemble understanding layer by layer, maintaining only the necessary content in working memory and leveraging note-taking strategies for additional persistence. This self-managed contextual window enables...intelligentbodyFocus on relevant subsets, rather than getting lost in detailed but potentially irrelevant information.
Of course, there are trade-offs: runtime exploration is slower than retrieving pre-computed data. Furthermore, careful engineering is needed to ensure...LLMPossessing the right tools and heuristics for effectively navigating its information landscape. Lacking proper guidance,intelligentbodyContext may be wasted due to misuse of tools, chasing dead ends, or failure to identify key information.
In certain scenarios, the most effectiveintelligentbodyPossible methodsHybrid strategy: Pre-retrieve partial data for speed and autonomously decide on further exploration. The "appropriate" level of autonomy depends on the task.Claude Code uses this hybrid model.intelligentbodyThe CLAUDE.md file was...SimpleBy pre-setting the context, primitives such as glob and grep allow it to navigate the environment and retrieve files on the fly, effectively avoiding the problems of expired indexes and complex syntax trees.
Hybrid strategies may be more suitable for contexts with lower content dynamism (such as legal or financial work). As model capabilities improve,intelligentbodyDesign will tend to makeintelligentModelintelligentActions should be taken to gradually reduce manual planning. Given the scope of the field...fastDevelopment, "to be the best"Simple"Effective things" may still be what we base our understanding on...ClaudeBuildintelligentbodyThe best advice from the team.
Context engineering for long-cycle tasks
Long-cycle task requirementsintelligentbodyWhen the number of symbols exceedsLLMMaintain coherence, context, and goal-oriented behavior within the action sequence of the context window. This is particularly important for tasks lasting from tens of minutes to hours (such as large codebase migrations or comprehensive research projects).intelligentbodySpecialized techniques are needed to circumvent the context window size limitation.
Waiting for a larger contextual window seems like an obvious strategy. However, it's foreseeable that contextual windows of all sizes will be plagued by contextual contamination and information relevance issues—at least in the context of…intelligentbodyThis is true in scenarios with extremely high performance requirements. To allowintelligentbodyTo work effectively over extended time spans, we have developed several techniques to directly address these contextual contamination constraints:Compression、Structured note-takingandmanyintelligentbodyMulti-agent architectures.
compression
Compression is the practice of summarizing dialogues that approach the limits of a context window and using that summary to reinitialize a new context window. Compression is often the primary means of improving long-term coherence in context engineering. At its core, compression distills the content of a context window in a high-fidelity manner, making...intelligentbodyIt can continue to work with minimal performance degradation.
For example inClaude In the code, we summarize and compress the most critical details by passing the message history to the model. The model retains architectural decisions, unresolved vulnerabilities, and implementation details, while discarding redundant tool outputs or messages.intelligentbodyUsers can then continue working with the compressed context and the five most recently accessed files. Users gain continuity without worrying about context window limitations.
The art of compression lies in selectively retaining and discarding content, as over-compression can lead to the loss of subtle but crucial context (the importance of which may only become apparent later). For engineers implementing compression systems, we recommend that in complex situations...intelligentbodyCarefully adjusted cues on the trajectory: First, maximize recall to ensure that compressed cues capture all relevant information in the trajectory, then iterate to improve accuracy and eliminate redundant content.
An example of low-hanging redundant content is clearing tool calls and results—once a tool is invoked deep in the message history,intelligentbodyWhy is it necessary to view the original results again? The safest and lightest form of compression is result clearing, which has recently been implemented as a feature...ClaudeDeveloper platform released.
Structured Notes
Structured notes (orintelligentbodyMemory is a kind ofintelligentbodyA technique for regularly taking notes and persisting them to memory outside the context window. These notes are later brought back into the context window.
This strategy provides persistent memory with minimal overhead. Like...Claude Code creates a to-do list, or a custom one.intelligentbodyMaintaining the NOTES.md file, thisSimpleThe pattern allowsintelligentbodyIt can track the progress of complex tasks and maintain key context and dependencies that would otherwise be lost across a large number of tool calls.
ClaudePlaying Pokémon demonstrates how memory transforms in non-coding domains.intelligentbodyAbility.intelligentbodyMaintain precise counts across thousands of game steps—tracking goals such as "I've been training Pokémon on Route 1 for the past 1234 steps, and Pikachu has leveled up 8 levels towards target level 10." Without any memory structure prompts, it develops a map of explored areas, remembers unlocked key achievements, and maintains strategic notes on battle tactics to learn which attacks are most effective against different opponents.
After the context is reset,intelligentbodyRead your own notes and continue for hours on training sequences or dungeon exploration. This coherence across summarization steps enables long-term strategies, while keeping everything in the background.LLMIt is impossible within the context window.
As part of the Sonnet 4.5 release, weClaudeThe developer platform publicly tested a memory tool that makes it easier to store and retrieve information outside the context window through a file-based system. This allows...intelligentbodyIt can build a knowledge base over time, maintain project state across sessions, and reference previous work without keeping everything in context.
sonintelligentbodyArchitecture
sonintelligentbodyArchitecture provides another way to circumvent contextual constraints. Unlike a...intelligentbodyAttempt to maintain the overall project state, dedicated sub-projectintelligentbodyFocusing tasks can be handled using a clean context window. MainintelligentbodyUse high-level planning and coordination, subintelligentbodyPerform in-depth technical work or use tools to find relevant information. Each sub-intelligentbodyIt may explore extensively, using tens of thousands or more symbols, but only returns a condensed summary of its work (usually 1,000-2,000 symbols).
This method achieves separation of concerns—the detailed search context is preserved within the sub-concept.intelligentbodyInternally, and dominantintelligentbodyThe focus is on synthesizing and analyzing results. This model is discussed in "How We Build Multi..."intelligentbodyThe study, titled "Research Systems," discusses how simpler approaches can handle complex research tasks.intelligentbodyThe system has been significantly improved.
The choice of these methods depends on the characteristics of the task. For example:
- Compression is suitable for tasks that require a lot of back-and-forth communication to maintain a flow of dialogue;
- Note-taking is suitable for iterative development with clear milestones;
- manyintelligentbodyThe architecture enables parallel exploration of complex research and analysis, yielding significant benefits.
Even as models continue to improve, maintaining consistency across expanded interactions will remain a challenge in building more effective [interactions].intelligentbodyThe core of it.
Context engineering represents our constructionLLMA fundamental shift in approach. As model capabilities increase, the challenge is no longer just crafting perfect cues—but rather thoughtfully planning which information enters the model within a limited attention budget at each step. Whether you are implementing compression for long-cycle tasks, designing symbols, or...High efficiencyTools, or letintelligentbodyExplore the environment in real time, but the guiding principle remains the same: findMinimal set of high-signal symbolsIn order to maximize the likelihood of the target outcome.
The techniques we outline will continue to evolve as the model improves. We have already seen that smarter models require less prescriptive engineering, allowing...intelligentbodyTo operate with greater autonomy. But even with expanded capabilities, viewing context as a valuable and limited resource will remain crucial for building reliable and effective [systems].intelligentbodyThe core of it.
ImmediatelyClaudeStart your context engineering journey with our developer platform and get helpful tips and best practices from our memory and context management manual.
By Anthropic applicationAIWritten by: Prithvi Rajasekaran, Ethan Dixon, Carly Ryan, and Jeremy Hadfield; with contributions from team members Rafi Ayub, Hannah Moran, Cal Rueb, and Connor Jennings. Special thanks to Molly Vorwerck, Stuart Ritchie, and Maggie Vo for their support.