Key Takeaways
- Context engineering is the discipline of designing everything that enters an LLM’s context window on every call: instructions, tools, retrieved knowledge, memory, conversation state, and constraints.
- Prompt engineering optimizes the instruction; context engineering manages the full, dynamic information environment across multi-step agent runs.
- The context window is finite and degrades with length and noise; every token competes for attention.
- Practical context engineering reduces to four operations: write (persist outside the window), select (pull the relevant slice in), compress (keep the window high-signal), and isolate (give subtasks clean boundaries).
- In an agent loop, context is assembled before the model reasons and is updated after tools and memory operations run.
Introduction
Early LLM work was largely about finding the right words in a prompt. Agent work is different. Agents generate new data every turn: tool outputs, observations, partial plans, and that data must be refined, stored, or discarded before the next call. The question shifts from “how do I phrase this?” to “what configuration of information is most likely to produce the desired behavior on this turn?”
That broader practice is context engineering.
This article gives a clear, citable definition, contrasts it with prompt engineering, walks through the anatomy of the context window, and presents the practical operations that keep agents coherent over long horizons. It sits inside the agent loop (Article 4) and draws on retrieval (Article 3) and agent memory (Article 5) as primary sources that context engineering selects and compresses.
1. Context Engineering vs Prompt Engineering
| Dimension | Prompt Engineering | Context Engineering |
|---|---|---|
| Scope | Instructions / one message | Entire context window over time |
| State | Mostly stateless / one-shot | Stateful, evolves across steps |
| Core skill | Phrasing and examples | Information-flow architecture |
| Failure mode | Vague or misread instruction | Context rot, distraction, contradictory state |
| Typical use | Single completion or chat turn | Multi-step agents, long-running tasks |
- Prompt engineering remains necessary and valuable. Clear system instructions, good examples, and precise format constraints still matter.
- They are a subset of context engineering, not a substitute. Once an agent runs for many turns, the dominant failures move from “the instruction was ambiguous” to “the model saw the wrong, stale, or overwhelming set of tokens.”
In short: Prompt Engineering shapes the ask; context engineering shapes what the model knows before it answers.
2. Anatomy of the Context Window
A modern agent call typically assembles:
- System / developer instructions
- Tool definitions and schemas
- Retrieved documents or knowledge (RAG / hybrid search)
- Durable memory (preferences, facts, policies, episodes)
- Recent conversation / working memory
- Tool results from the current trajectory
- Constraints, format requirements, safety rules
Two practical realities follow:
- The window is finite. Every token competes for attention.
- Position and noise matter. Models exhibit “lost-in-the-middle” effects; long, low-signal transcripts degrade quality even when the right fact is present somewhere in the window.
“More context” is not automatically better. High-signal, well-scoped, timely context is better.
3. Why Agents Force the Discipline
- Single-turn tasks can often survive a carefully written prompt. Agents cannot.
- Every iteration of the agent loop (Article 4) produces new observations.
- Those observations may be relevant next turn, next session, or never again.
- The harness must decide what to keep, what to store outside the window, what to retrieve later, and what to discard.
- Context assembly is the first step of every loop iteration; context engineering is the discipline that makes that step deliberate.
4. The Core Operations of Context Engineering
A widely used practical taxonomy groups the work into four operations:
1. Write
- Persist information outside the window (memory, logs, scratchpads) so it does not have to compete for attention every turn.
- Examples: durable agent memory stores, scratchpads, tool logs, external files.
- Why it matters: without a write path, the only memory is the current window, which resets when the run ends.
2. Select
- Pull only the relevant slice into the current call (retrieval, memory search, context cards).
- Examples: vector / hybrid retrieval, scoped memory search, filtering tool results, ranking by relevance and recency.
- Why it matters: noise and cross-user leakage are selection failures.
3. Compress
- Summarize, compact, or drop stale content so the window stays high-signal.
- Examples: thread summaries, context cards, progressive disclosure of older turns, trimming low-value tool output.
- Why it matters: unbounded append produces context rot and rising token cost.
4. Isolate
- Give subtasks or sub-agents their own context boundaries so noise and contradictory state do not leak.
- Examples: sub-agents that return only a summary, separate windows for research vs synthesis, scoped memory per tenant or user.
- Why it matters: one contaminated window can derail an otherwise correct plan.
These operations sit inside the agent loop: context is assembled before the model reasons and is updated after tools and memory operations run.
5. How Retrieval, Memory, and Compression Work Together
- Retrieval supplies external knowledge on demand.
- Agent memory supplies continuity and durable state across sessions.
- Compression (summaries, context cards) keeps the active window usable.
A simple flow:
6. Practical Principles
- Prefer high-signal tokens over volume.
- Reassemble context on every turn rather than blindly appending.
- Scope memory and retrieval hard (user / tenant / agent) before ranking.
- Treat tool results as first-class context that must be managed, not merely appended.
- Measure: context quality shows up in task success, token cost, and consistency across long runs.
Oracle AI Database appears here only as one concrete place where durable memory and hybrid retrieval can live under shared governance of the sources that the “write” and “select” operations draw from. The discipline itself is substrate-agnostic.
7. Where This Fits in the Series
Context engineering is the discipline that lives inside the agent harness. Reliable context assembly is a prerequisite for safe tool calling, predictable agent behavior, and meaningful evaluation.
- Article 4 defined the agent loop (context assembly is step one).
- Article 5 covered memory as a primary source that context engineering selects and compresses.
- Article 3 covered retrieval as another primary source.
- Articles 8 move to tool calling, the harness runtime, and evals all of which depend on the quality of the context that reaches the model.
Most Asked Questions
Is prompt engineering dead?
No. It remains essential for instructions, format, and examples. It is a subset of the broader discipline of context engineering.
What is the difference between context window and memory?
The context window is what the model can see on the current call (working memory). Durable memory is stored state that can be selected into future windows.
Do I still need RAG if I do context engineering?
Often yes. RAG is one of the main “select” mechanisms for external knowledge. Context engineering decides when and how to use it.
How do context cards / summaries fit in?
They are compression techniques: they turn long history or large tool results into a high-signal, prompt-ready package.
What is “context rot”?
Progressive degradation of answer quality as the window fills with low-signal, stale, or contradictory tokens.
How does this relate to the agent loop and the harness?
Context assembly is the first step of every loop iteration. The harness is the code that performs write / select / compress / isolate and then invokes the model.
Resources
- LangChain: Context Engineering for Agents
- From RAG to memory systems: building stateful AI architecture
- The agent loop decoded: three levels every agent engineer must know
- What is agent memory? A beginner’s guide for AI developers
- Which agent memory approach is best for long conversations
- Comparing file systems and databases for effective AI agent memory management
- Oracle AI Agent Memory documentation
- Oracle AI Developer Hub
- Oracle AI Database Free / FreeSQL
- Article 4: The AI Agent Loop
- Article 5: RAG vs Agent Memory
- Article 6: Building an Agent Memory System with oracleagentmemory
- Article 8: Understanding Tool Calling and Agent Harnesses
Latest Release
- oracleagentmemory 26.8 on PyPI
- Oracle AI Agent Memory 26.8 documentation
- What’s New in Oracle AI Agent Memory: Graph-Aware Retrieval, Image Memory, and Enterprise Controls
Conclusion
Context engineering is the discipline of managing the full information environment an agent sees on every model call. It includes, but is larger than, prompt engineering. The practical work reduces to four operations: write, select, compress, isolate, that run inside the agent loop.
Once those operations are explicit, the remaining engineering problems become clearer: what to persist, how to retrieve it under scope, how to keep the window high-signal, and how to evaluate whether the context policy is actually improving agent behavior.
Try Yourself: Take any multi-turn agent you already run and instrument the four operations: what is written outside the window, what is selected in, what is compressed, and what is isolated. Then compare token cost and task success before and after. For a concrete memory substrate that supports the “write” and “select” steps under shared governance, see the oracleagentmemory Get Started guide or the notebooks in the Oracle AI Developer Hub.