docs/public/context-engineering.mdx
Find the smallest possible set of high-signal tokens that maximize the likelihood of your desired outcome.
Prompt Engineering: Writing and organizing LLM instructions for optimal outcomes (one-time task)
Context Engineering: Curating and maintaining the optimal set of tokens during inference across multiple turns (iterative process)
Context engineering manages:
Key Insight: LLMs have an "attention budget" that gets depleted as context grows
Too Prescriptive ❌
Too Vague ❌
Just Right ✅
<background_information>, <instructions>, ## Tool guidance, etc.)user_id not user)If a human engineer can't definitively say which tool to use in a given situation, an AI agent can't be expected to do better.
Do ✅
Don't ❌
Approach: Maintain lightweight identifiers (file paths, queries, links) and dynamically load data at runtime
Benefits:
Trade-offs:
Approach: Use embedding-based retrieval to surface context before inference
When to Use: Static content that won't change during interaction
Approach: Retrieve some data upfront, enable autonomous exploration as needed
Example: Claude Code loads CLAUDE.md files upfront, uses glob/grep for just-in-time retrieval
Rule of Thumb: "Do the simplest thing that works"
What: Summarize conversation nearing context limit, reinitiate with summary
Implementation:
Tuning Process:
Low-Hanging Fruit: Clear old tool calls and results
Best For: Tasks requiring extensive back-and-forth
What: Agent writes notes persisted outside context window, retrieved later
Examples:
Benefits:
Best For: Iterative development with clear milestones
What: Specialized sub-agents handle focused tasks with clean context windows
How It Works:
Benefits:
Best For: Complex research and analysis tasks
| Scenario | Recommended Approach |
|---|---|
| Static content | Pre-inference retrieval or hybrid |
| Dynamic exploration needed | Just-in-time context |
| Extended back-and-forth | Compaction |
| Iterative development | Structured note-taking |
| Complex research | Sub-agent architectures |
| Rapid model improvement | "Do the simplest thing that works" |
"Even as models continue to improve, the challenge of maintaining coherence across extended interactions will remain central to building more effective agents."
Context engineering will evolve, but the core principle stays the same: optimize signal-to-noise ratio in your token budget.
Based on Anthropic's "Effective context engineering for AI agents" (September 2025)