Context engineering is the design of everything a model sees while completing a task: system instructions, tool definitions, retrieved evidence, conversation state, working notes, memory, and the results of previous actions. For long-running agents, choosing and maintaining that context matters more than writing one perfect prompt.
Anthropic’s September 2025 guidance describes the shift from prompt engineering to managing the complete context state as agents operate over more turns and longer time horizons. See Effective context engineering for AI agents.
Why long context is not the same as good context
A larger context window allows more tokens, but every included item competes for attention. Old tool output, repeated instructions, entire documents, stale plans, and irrelevant messages can make the model slower and less consistent.
The goal is not maximum context. It is the smallest sufficient context for the next decision, with a reliable path back to evidence the agent may need later.
Useful context has five properties:
- relevant: it affects the current step;
- sufficient: necessary constraints and evidence are present;
- authoritative: source and trust level are clear;
- isolated: one tenant, user, or task cannot leak into another;
- economical: repeated or bulky material is referenced rather than copied indefinitely.
Treat context as separate layers
Stable instructions
Keep identity, task boundaries, tool policy, and output rules concise. Do not embed an entire knowledge base or frequently changing business policy in a system prompt.
Tool definitions
The model needs enough information to choose a tool and form valid arguments. Too many overlapping tools increase ambiguity and consume context on every turn. Use narrow capabilities, clear names, strict schemas, and examples only where they resolve a real ambiguity.
MCP makes tools discoverable across compatible clients, but discovery still needs selection. A production host may expose only the tools relevant to the current user, page, or stage of the task.
Retrieved evidence
Evidence should carry source identity, version, permissions, and citation metadata. Retrieve for the current question; do not append every result forever. If a result contains external instructions, treat those as data rather than policy.
Working state
Plans, completed steps, open questions, generated artifacts, and important tool results belong in explicit task state. The model should not have to reconstruct the workflow from a raw conversation transcript.
Long-term memory
Store durable user or task facts only when they have a defined future use. Separate memory from recent messages, provide correction/deletion paths, and avoid persisting secrets or one-off requests.
Use compaction as a state transition
Compaction is not merely “summarize the chat.” A useful compacted state preserves:
- the user’s goal and non-negotiable constraints;
- decisions already made and why;
- completed actions and their identifiers;
- unresolved questions and next steps;
- references to artifacts and source evidence;
- current permissions and budgets.
Discard repeated prose, transient status messages, and raw output that can be reopened. Store the compacted result as a versioned checkpoint so the agent can resume after failure or context rotation.
Anthropic’s November 2025 work on effective harnesses for long-running agents emphasizes durable progress artifacts and clean handoffs between context windows. The broader principle applies beyond coding agents.
Offload work without losing ownership
Subagents can isolate research, exploration, or specialist work from the coordinator’s main context. They are useful when tasks can run independently and return a bounded artifact.
Use a subagent when:
- the work has a clear input and output contract;
- the specialist needs a different tool set or context;
- parallel execution saves meaningful time;
- the coordinator does not need every intermediate step.
Do not use one merely to make an architecture look “multi-agent.” Delegation adds another identity, permission, failure, trace, and evaluation boundary. A normal function or deterministic worker is often better.
Keep tool output bounded
Tools should return what the agent needs for the next decision, not an unbounded dump.
Good patterns include:
- pagination and server-side filters;
- stable record identifiers plus a concise preview;
- typed summaries with an option to fetch detail;
- explicit truncation indicators;
- separate metadata and content fields;
- saved artifacts for large reports or files.
The model should know when output is partial. Silent truncation creates confident decisions from incomplete evidence.
How this appears in real products
In Aztrogent, page state, selected entities, conversation history, personality, and tool results are different context types. The agent needs relevant portfolio state without receiving every project and service description on every turn.
In EmbedChat AI, tenant identity, store platform, retrieved content, conversation memory, and available commerce tools must stay aligned. Context engineering there is also an isolation problem: a relevant result from the wrong tenant is still a severe failure.
Observe context decisions
Trace at least:
- which instruction and tool versions were active;
- what was retrieved and filtered out;
- context size by category;
- compaction events and checkpoint versions;
- memory reads and writes;
- subagent delegation and returned artifacts;
- tool output truncation;
- final outcome, cost, and latency.
This makes “the model forgot” diagnosable. The cause may be missing retrieval, poor compaction, an overwritten constraint, an irrelevant tool response, or a genuine model error.
Context engineering checklist
- [ ] Stable instructions are short and versioned
- [ ] Tools are selected for the current task and permissions
- [ ] Retrieved evidence includes provenance and access metadata
- [ ] Working state is explicit rather than inferred from chat
- [ ] Compaction preserves decisions, artifacts, and unresolved work
- [ ] Long-term memory has retention and deletion rules
- [ ] Large outputs are stored and referenced
- [ ] Subagents receive bounded tasks and return bounded artifacts
- [ ] Tenant and user context cannot cross boundaries
- [ ] Traces make context selection and mutation inspectable
Prompt engineering asks, “What should the model be told?” Context engineering asks, “What should this agent know now, what should it be able to retrieve later, and which state must remain outside the model entirely?” That is the more useful 2025–26 production question.