AI and agents · Context and memory · 6 min
Context engineering: the right information at the right time
Selecting, structuring and updating relevant context improves agents’ accuracy, cost and traceability.
More context does not mean a better answer
Sending all available knowledge can bury critical rules, raise cost and degrade accuracy. Context engineering decides which information goes in, with what priority and for how long it remains valuable.
Instructions must be kept distinct from retrieved documents and user-provided content. That separation prevents untrusted text from being interpreted as an operating command.
Retrieve with relevance and provenance
Useful retrieval combines semantic relevance, freshness, permissions and provenance. A passage without a source or outside the access policy should not become evidence for a decision.
Recent history avoids repeating work; summaries keep facts and decisions with a lighter context load. Compression is therefore a quality control as well as an optimization.
Reading the diagram
How to read this system
- 01Instructions, data, history and retrieval are different sources: they do not share the same level of trust.
- 02The context builder classifies, authorizes, selects and orders content before handing it to the model.
- 03The LLM generates from the available context; the output must be traceable to specific sources and versions.
- 04Retrieval is refreshed only when the task needs it, and always respecting permissions and provenance.
Essential concepts
Technical terms
- RAG
- Retrieval of external information to ground an answer.
- Provenance
- Origin, version and chain of custody of a piece of data.
- Context window
- Finite amount of information the model can process.
Architecture
Implications and controls
It is advisable to separate the document repository, the retrieval index, the authorization engine and the context builder. A retrieved document can inform an answer; it must not change the system’s rules.
Risks to consider
- Instruction injection in documents.
- Outdated or unauthorized information.
- Noise that displaces important rules.
Checklist
- Tag each passage with source, date and permissions.
- Authorize before retrieving.
- Summarize history without turning inferences into facts.
- Evaluate real and adversarial queries.
Conclusion
Context is a governed product: relevant, authorized, traceable and proportional to the decision.