“Contextual engineering” to make AI smarter

1. From Prompt Engineering to Context Engineering

In the past few years, the most common word used by AI developers is “Prompt Engineering” – how to use the most appropriate instructions to make the model show the desired results.
But today, we face a bigger question: how do we arrange space for AI to think when it is no longer just answering questions but is operating autonomously for long periods of time?
That’s where Context Engineering comes in.

2. What is “context engineering”?

In large language models (LLMs), “context” refers to all the information that the model can see during the inference process:
System commands, conversation history, tool calls, external data, ……
Context engineering is how to put the most valuable information in a limited context window, so that the model can “think right” at critical moments.

It’s no longer just about “writing prompts”, it’s a kind of data management and attention design engineering.
For developers, this means that every token (unit of text) must be used to its fullest potential.

3. Why is context engineering so important?

LLMs have the same “attention budget” as humans.
As the context gets longer, the model’s focus becomes scattered and its accuracy decreases. This phenomenon is known as context rot.
The transformer architecture allows each token to focus on all other tokens, which means that the larger the context, the more attention links increase in the square order, and the model’s “focus of understanding” is diluted.

Therefore, context is a finite resource.
Just as humans need to pay attention selectively, AI also needs to be designed to “think selectively”.

4. The principle of creating an effective context

To keep the model “focused,” Anthropic proposes several key strategies:

  1. Clear System Prompts
    • Express the expected behavior in simple and straightforward language.
    • Don’t write about complex logic, and don’t give empty guidance.
    • “Just right” commands are the kind that can give direction and retain flexibility.
  2. Streamlined and efficient tools
    • Each tool has clear functions and is clearly named.
    • Avoid overlapping or ambiguous tool designs.
    • Tools should help the model obtain information efficiently, not slow down its thinking pace.
  3. A typical Few-shot example
    • You don’t need to list all boundary cases.
    • As long as you pick out the “classic case” that represents the core of the mission, you can give the model the strongest behavioral hints.

The general principle is: make the context “high information density but small volume”.

5. Dynamic Context and “Real-Time Retrieval”

Traditional context is static: all information is fed to the model at once before inference.
But a more advanced strategy is just-in-time retrieval.

This way AI agents act like humans—looking for data only when needed.
Claude Code uses this design:
It does not read the entire database at once, but uses tools to dynamically load fragments, query results, file summaries, etc. at runtime.
This “on-demand thinking” keeps the model light while being exploratory.

6. Three major skills in long-term tasks

When tasks need to last for hours and span multiple rounds of reasoning, Claude employs three strategies to maintain coherence:

  1. Compaction
    Condense long conversations or program history into summaries, retaining only key information.
    Like a person taking notes, it condenses the “essence context”.
  2. Structured Note-taking
    The model periodically writes progress to an external notebook, such as NOTES.md.
    This allows it to retain memories during multi-stage missions and “recall” from notes even if the context is reset.
  3. Sub-agent Architecture
    One main agent is responsible for planning, and multiple sub-agents each handle special tasks, and then compress the results back into the main agent.
    This layering method not only reduces the burden of memory, but also improves task accuracy.

7. Conclusion: Context is a scarce resource

Context Engineering is a shift from “command” to “cognitive design”.
In the future, as models become smarter, humans will no longer need to dictate behavior by hand.
However, fine management of context remains the core of making AI stable and controllable.

“Do the simplest thing that works.”
—— Anthropic Applied AI Team

Original: https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents

Tubing:

Scroll to Top