Context Engineering
Agent Design for Research
MAE 6291 – Class 10
April 6, 2026
The Unifying Idea
Context engineering is a new term (mid-2025) for the framework that ties all our recent activities together.
Knowledge Bases
Loading papers and documentation into NotebookLM or Claude Projects.
Encoding Patterns
Writing CLAUDE.md and AGENTS.md to store persistent conventions.
On-Demand Context
Designing SKILL.md files to load only when specific tasks require them.
Defining Context Engineering
The art and science of the optimal token set.
The Art of Plausibility
— Tobi Lütke, CEO of Shopify (June 2025)
"Context engineering is the art of providing all the context for the task to be plausibly solvable by the LLM."
Beyond Simple Prompts
— Andrej Karpathy (2025)
"People associate 'prompts' with short descriptions, but the real work is the delicate art and science of filling the context window with just the right information for the next step."
Engineering View
Anthropic defines it as the strategies for:
"Curating and maintaining the optimal set of tokens during LLM inference."
This includes all information that lands in the window outside of the immediate prompt.
The Landscape in 2026
Peer-Reviewed Research: Formal validation of context strategies in engineering.
Practitioner Conferences: Dedicated tracks on "Attention Management."
Standardized Frameworks: Adoption of AGENTS.md and SKILL.md conventions.
Integrated Tooling: Models that proactively request context through MCP.
A Durable Skillset
Why it Lasts
Models will change and interfaces will evolve, but the fundamental constraint remains: The Transformer Architecture.
The quality of the output depends inextricably on the quality of the information in the window.
From Prompting to Context
What Changed and Why
Evolution of Practice: Beyond Chat
2022–2024: Prompt Engineering
2025–2026: Context Engineering
Zero-shot & Few-shot techniques
Role-based persona crafting
Structuring output schemas
Focus: The single user message.
Managing the total token budget
Designing the entire information environment
Filtering noise for signal
Focus: The entire context window.
Managing Finite Resources
A context window is an architectural limit, not just a preference.
Session Choice
Starting fresh sessions to reset history and attention.
Manual Compaction
Using /compact at natural task boundaries instead of auto-compaction.
Core Insight
Prompts, tools, memory, retrieved documents, conversation history, and instruction files
Context engineering is not about writing better prompts; it is about designing the entire information environment in which a model operates
The Architectural Constraint
In a Transformer, every token can attend to every other token. This allows capturing relationships regardless of distance.
At 100,000 tokens, that is 10 billion relationships processed simultaneously.
O(n²) Complexity
Double the context = Quadruple the compute.
The Attention Budget
High-Signal Context (Dense) vs. Bloated Context (Diluted)
100%
Precision is Finite
Think of attention as a conserved resource. Every token added dilutes the model's ability to focus on any single piece of data.
The Lost-in-the-Middle Phenomenon
Research indicates that retrieval performance is significantly higher at the beginning and end of a context window. Information in the center is functionally forgotten as the window stretches.
Context Rot Benchmark (Chroma Study)
Systematic evaluation of 18 frontier models on retrieval and replication tasks (July 2025).
Model Category | Task Performance (Short) | Task Performance (Long) | Primary Failure Mode |
Frontier (e.g. GPT-4.1) | 98% | 82% | Attention Dilution |
Claude 4 Series | 99% | 88% | Graceful Degradation |
Gemini 2.5 | 97% | 84% | Distractor Interference |
Open-Weights | 92% | 65% | Lost-in-the-Middle |
Finding: No model is immune to context rot.
Mechanisms of "Context Rot"
Dilution
Softmax normalization spreads weights thinner as token count increases, losing focus on critical details.
Position Bias
Models attend better to the start and end of a window, creating a "blind spot" in the center.
Interference
Semantically similar but irrelevant content (distractors) actively misleads the model's attention.
Distractors in Research
Research contexts are uniquely vulnerable to interference due to terminology overlap.
Shared Lexicon: Different papers using identical variables (e.g., $Re$, $Nu$) for distinct findings.
Structural Artifacts: Repeating headers/footers in literature collections.
Conflicting Findings: Model attends to "plausible but wrong" data from a discarded methodology.
The Core Design Insight
More context is not better context. A model with a one-million-token window does not benefit from having a million tokens loaded. It benefits from having the right tokens loaded—the minimum set of high-signal information needed for the current task.
The Components � of Context
A Taxonomy for Effective Engineering
Decomposing the Environment
To engineer context effectively, it helps to have a vocabulary for its parts. Every response works within these decomposed components:
Static
Remains constant across the entire session.
Dynamic
Changes and flows throughout the session.
Meta
The structural framework of capabilities.
Static Context
Static context is information that remains constant across an entire deployment.
These load at session start and persist throughout.
System Prompts: Define role, constraints, and behavior.
Instruction Files: CLAUDE.md and AGENTS.md files.
Project Memory: Information that persists through every project conversation.
Dynamic Context
Dynamic context reflects the information that changes during a session.
Appears only when determined relevant to the query.
Conversation History: Grows with each exchange.
Tool Results: Content from web searches, file reads, or code output.
Retrieved Data: Passages pulled from RAG pipelines or NotebookLM sources.
Meta-Context
Defining Capabilities
Meta-context is Structural Info that defines what the model can do, distinct from what it knows.
Tool Definitions: JSON schemas for available tools.
MCP Servers: Schemas telling the model which parameters to accept.
Action Frameworks: What kind of results to expect from tool calls.
Meta-Context
Every connected tool adds thousands of tokens of meta-context before the first user message is even sent.
Structural Knowledge
Defines what the model can do rather than what it knows.
MCP & Plugin Schemas
JSON definitions of tool names, parameters, and required data types.
The Design Surface
These categories are design surfaces where you make decisions that affect performance:
Static Design
Writing CLAUDE.md to define project-level awareness.
Meta Design
Choosing MCP servers to budget attention vs. work.
Dynamic Design
Structuring skills with Progressive Disclosure.
Skills as Context
SKILL.md files are packages of on-demand context.
They load only when a specific task requires them. This prevents the model from being overwhelmed by irrelevant details during its primary reasoning loops.
Case Study: Skill Architecture
The Skill Standard uses Progressive Disclosure to manage context levels.
Level 1
Description Only� (Always On)
Level 2
SKILL.md Instructions� (Load on Demand)
Level 3
Reference Files� (Targeted Retrieval)
Just-in-Time Loading Matrix
Component | Visibility Type | Timing | Design Purpose |
Level 1 (Meta) | Static/Always-On | Start of Session | Discovery/Awareness |
Level 2 (Dynamic) | On-Demand | Tool Activation | Task-Specific Logic |
Level 3 (Semantic) | Retrieved | Explicit Request | Deep Domain Knowledge |
Context Composition
15% Instructions: Static and Meta Context
30% High-Signal Data: Filtered RAG/History
25% Tooling: MCP Schemas/Capabilities
30% Noise: Raw PDF bloat, sprawl (Wasted Attention)
Total Context Window
Made-up numbers for illustration purposes.
OPERATIONALIZING LEAN AGENTS
“Context Hygiene”
Keeping context lean, intentional, and high-signal.
The Economic Argument
Wasteful context habits lead to reaching rate limits faster and increased latency.
Free tiers prioritize token efficiency.
Enterprise API costs scale linearly with token volume.
Longer contexts require more compute cycles per call.
Professional Skill of the Future
Token efficiency is becoming a core competency, not just a curiosity.
— Jensen Huang, NVIDIA CEO
"Individual engineers may eventually spend on the order of $250,000 per year on AI compute."
Habit 1: Format Discipline
Markdown Rules
Convert everything to clean Markdown before feeding to a model.
Strip Bloat
Remove layout metadata, repetitions, and embedded formatting instructions.
Structure
Preserve headers and equations (LaTeX), discard font/style metadata.
The PDF Problem
Models don't see typeset journal articles; they see extracted streams.
Layout Metadata: Bounding boxes and positional markers.
Repetitive Artifacts: Page headers, footers, and numbers.
Broken Characters: Ligatures and font symbols.
Efficiency: PDF vs. Markdown
Same Journal Article (15 Pages)
4x Signal-to-Noise Improvement
Habit 2: Avoiding Conversation Sprawl
Sprawl is the silent killer of agent performance.
It occurs when we allow a single session to grow indefinitely, filling the context window with "stale" reasoning and resolved errors.
The goal: High-intensity, focused sessions.
The Sprawl Mechanism
In the Transformer architecture, there is no "forgetting" within a session. History is active compute.
Total Context = (System + Meta) + History + New Prompt
On every turn, the model must re-process the entire conversation.
Resolved debugging loops from an hour ago still compete for attention.
Token costs and latency increase exponentially with history length.
Compaction vs. Refreshing
/compact
A mitigation. Summarizes history into a few paragraphs. Essential for context limits but often loses technical nuance and variable definitions.
Fresh Session
A solution. Forces you to define the "clean state." High-signal, zero-noise, and maximum attention density.
Rule of Thumb: The Reset
When should you start a new session?
10–15 Turns
Standard interaction limit before "Rot" becomes noticeable.
Task Boundaries
Moving from "Drafting" to "Editing" or "Simulating" to "Analyzing."
Circular Debugging
If the model repeats an error twice, the context is likely contaminated. Reset.
Research vs. Execution Sessions
Never "build" in the same session you used to "explore."
The Research Session
The Execution Session
Messy, long, exploratory.
Finding the right paper, testing a hypothesis.
Output: A clean specification or finding.
Starts fresh.
Only inputs the specification from the Research session.
High precision, no baggage.
Habit 3: Auditing Meta-Context
"The Plugin Tax: Every active tool makes the model slightly dumber at reasoning because it has more 'potential' actions to consider."
Rule: Meta-context consumes 2k–15k tokens silently through JSON schemas. If a tool isn't needed for the *current* 15-minute task, disable it.
The "Plugin Tax"
Meta-context is not free. Every tool definition consumes tokens from the finite context window.
Meta-context can consume your budget before you type a single word.
Configuration | Estimated Token Cost | Impact on Attention |
Single Simple Tool | ~500 - 1,000 | Negligible |
10 Detailed Tools (1 MCP) | ~3,000 - 5,000 | Minor Dilution |
5 Active MCP Servers | 15,000 - 20,000 | Significant Dilution |
The "Plugin Tax"
Unused tools are active waste, diluting attention for the primary task.
20k
Tokens Consumed Silently
Five MCP servers (e.g., GitHub, Search, Drive, Terminal, DB) can easily consume 15,000 to 20,000 tokens of your attention budget just for schemas.
Tool Minimization Guidelines
OpenAI/Anthropic Rule: Keep active tool definitions below 10 for maximum reliability.
The Distractor Problem: Too many tools lead to "tool hallucination" (calling the wrong function).
Latency: Meta-context is processed on every turn. Fewer tools = Faster response.
// BAD: � allowed-tools: ["*"] �� // GOOD: � allowed-tools: ["read_file", "write_file", "run_terminal"]
Model Mixing: Budget Forcing
A core context strategy is selecting the model based on the complexity-to-token ratio.
Reasoning
Complex logic, tiny context needs. Use: o1 / r1.
Execution
Large project context, high precision. Use: Claude 3.7 / GPT-4.5.
Lightweight
Formatting, summarizing, low stakes. Use: Haiku / 4o-mini.
The Three-Tier Model Matrix
Tier | Best For... | Context Strategy |
Tier 1: Reasoning | Math, Architecture, Logic | Zero history, high prompt density. |
Tier 2: Production | Coding, Long Writing | Managed history, CLAUDE.md active. |
Tier 3: Utility | Formatting, Data Cleaning | Massive context, shallow reasoning. |
Principles of � Agent Design
Operationalizing context engineering for � unsupervised workflows.
Principle 1: Indexing References
Avoid "Raw Dumping"
Never provide an agent with a raw, complete document when it only needs specific information. This floods the attention budget with noise.
Just-in-Time Retrieval
Maintain an index of what exists (identifiers, paths, queries). Let the agent "pull" full content only when explicitly needed for a sub-task.
Case Study: Claude Code Indexing
Claude Code does not load every file into the context at startup. Instead, it uses a lean discovery pattern:
Use find to map the directory structure.
Use grep to locate specific strings or patterns.
Read files selectively based on discovery results.
Principle 2: Pre-process Context
Convert Bloat
Convert raw PDFs and solver outputs to clean, structured Markdown or JSON before the agent sees them.
Clean Consumption
Every token spent "reading" formatting artifacts is a token lost for reasoning about the actual task.
Structured Data
Ensure simulation data enters the context "ready to use," not in need of heavy parsing or reformatting.
Principle 3: Caching Stable Context
Efficiency Through Caching in API-based workflows
System prompts, tool definitions, and reference documents that do not change can be cached via Prompt Caching.
This avoids the cost and latency of re-processing identical content on every API call, allowing for larger, more detailed static context.
Principle 4: Scoping Context
Minimal Scoping
Do not give a planning agent full codebase access when it only needs an architecture overview. Limit the information to the Role Requirements.
Partitioning
Different steps in a workflow (Drafting vs. Formatting) should receive different, partitioned context packages to maintain high signal-to-noise.
Restricting "Agent Wandering"
The allowed-tools Field: Explicitly restrict which tools an agent can access for a specific skill.
Attention Conservation: Every tool definition consumes meta-context tokens. Reducing the toolset preserves the attention budget.
Safety & Reliability: Preventing an agent from wandering into irrelevant territory or calling dangerous tools during a limited task.
Principle 5: Instrument & Measure
"You cannot optimize what you do not observe." Tracking waste is the first step toward efficiency.
Synthesis: The SKILL.md
A well-designed SKILL.md embodies all five principles of agent design:
Indexing
Level 1 discovery vs. Level 3 deep retrieval.
Scoping
Usage of allowed-tools to fix the role.
Pre-processing
Defining clean output formats for downstream agents.
Self-Audit: Context Habits
The PDF Check
Are you uploading raw PDFs or clean Markdown to your Knowledge Bases?
The Sprawl Check
Are you running marathon sessions or refreshing at task boundaries?
The Plugin Check
Do you know which MCP servers are currently connected and active?
Lab Hygiene vs. Context Hygiene
"In the lab, contamination ruins an experiment. In an AI workflow, contamination ruins an attention budget."
Both are avoidable, and both become habitual once you start noticing the drift in results.
Memory Systems
Extending context beyond the single session.
Type 1: Conversation Memory
Working Memory
Scope: The immediate chat window.
Persistence: Ephemeral. Dies when the session ends.
Risk: Lossy and prone to sprawl/rot.
Your Role: Hygiene manager. Keep it clean or kill it.
Type 2: Semantic Memory
The "Reference" Desk
The model consults this at the start of *every* session within a project.
Scope: Project-wide facts and conventions.
Persistence: Durable. Stays in the filesystem/Knowledge Base.
Examples: CLAUDE.md, PROJECT.md, NotebookLM libraries.
Your Role: Librarian/Architect. Encoding knowledge.
Type 3: Episodic Memory
Experience
Learning from past interactions without explicit documentation.
Scope: The user's entire history/style.
Persistence: Managed by the platform (e.g., Claude Memory).
Mechanism: The model "remembers" your preferences or past mistakes.
Your Role: Curator. Deleting bad "memories" and reinforcing good ones.
The Memory Hierarchy
Type | Comparison | Persistence | User Action |
Conversation | Working Memory | Session-only | /compact or Refresh |
Semantic | Knowledge | Project-long | Write CLAUDE.md |
Episodic | Experience | Lifetime | Reinforce Preferences |
Effective agents balance all three to stay lean and smart.
Strategic Memory Placement
Storage Layer | Type of Information | Retrieval Timing |
CLAUDE.md | Project Conventions, Tech Stack | Session Start (Always-On) |
SKILL.md | Task-Specific Workflows | Triggered Activation |
Knowledge Base | Literature, Domain Facts | Dynamic RAG Query |
Assignment 4 Memory Design
You will write a CLAUDE.md for your own project. This is your Semantic Memory Layer.
Think one level up: What does the agent need to do, and how should the context be structured to support those actions? (Skills: on-demand semantic memory.)
What does it need to know? (Project knowledge: retrieved semantic knowledge.)
What can you leave to conversation memory?
Research Agent Patterns
Architectures for the Scientific Workflow
Pattern 1: Single Agent (The Baseline)
A single model instance equipped with a specific set of tools and a narrow context.
Minimalist
The "Reasoning Loop" is entirely internal to the model.
Structure: One prompt, one history, one toolset.
Best For: Linear tasks where the model doesn't need to "switch modes."
Strength: Low latency, zero coordination overhead.
Why Single Agent is Often Enough
"Complexity is the enemy of reliability."
In research engineering, many tasks are best handled by a single, high-context agent:
Lit Reviews
Searching and summarizing connected papers.
Debugging
Reading code, running terminal, and fixing errors.
Pattern 2: Orchestrator-Worker
Used when a task has independent sub-components that can be parallelized or require different contexts.
Delegation
The Orchestrator manages the State; the Workers manage the Execution.
Orchestrator: Analyzes the task, creates a plan, and delegates to workers.
Workers: Specialized agents with restricted tools/context (e.g., "The Coder," "The Searcher").
Orchestration in Action
Claude Code /batch
Orchestrates parallel file modifications across a large codebase. Workers handle individual files to avoid context dilution.
Academic Pipelines
One agent fetches 50 citations; five "Worker" agents read 10 each; the Orchestrator synthesizes the final review.
Pattern 3: Evaluator-Optimizer
The Loop
Iterative refinement until a "Quality Threshold" is met.
Essential for high-stakes research outputs like code or publication drafts.
Optimizer: Generates the draft.
Evaluator: Acts as a peer-reviewer, providing critical feedback based on a checklist.
Result: Optimizer revises based on feedback.
Pattern 4: Router
Directing queries to the Optimal Context Package.
Math Query
Routed to an agent with SymPy and Wolfram tools.
Concept Query
Routed to an agent with the full Literature Knowledge Base.
Code Query
Routed to an agent with the terminal and file access.
The Practical Heuristic
How should you build your next agent?
Start Simple.
Add complexity only when you have evidence that a single-agent architecture is failing due to context rot or task sprawl.
Hidden Costs of Multi-Agent Systems
Telephone Game
Information is lost or distorted as it passes between agents.
Latency
Every "hand-off" adds seconds of processing and API calls.
State Drift
Workers lose track of the Orchestrator's original high-level goal.
In-Class Activity
Sketching a Research Agent Workflow
Activity: Task & Tools
Task Selection: Choose a specific research sub-task (e.g., "Generate a mesh for a CFD wing section" or "Summarize five papers on boundary layer stability").
Context Needs: What domain knowledge and naming conventions must be present?
Tool Sets: What MCP servers or file access does it need? What tools should be restricted?
Activity: Memory & Pattern
25 Minutes to Sketch. We will share and discuss context design vs. task requirements.
Memory Strategy: What lives in CLAUDE.md (Always-on) vs. a Skill (On-demand)? How do you recover state if you reset the session?
Design Pattern: Single Agent? Orchestrator-Worker? Evaluator-Optimizer? Justify your choice.
Wrap-up & Discussion
Does the context design match the task?