# Context Engineering

AI Glossary · Prompting & Context
Canonical URL: https://aisat.uk/glossary/context-engineering
Author: Lucy Gilmore, Assistant General Counsel, Product, Privacy & AI at Sprinklr | Practical Privacy, Product & AI Governance & Defensible Risk Decisions (https://www.linkedin.com/in/lucy-gilmore/)
Breadcrumb: [Glossary](https://aisat.uk/glossary) > [Prompting](https://aisat.uk/glossary?category=prompting) > Context Engineering

## TL;DR

> **Context engineering** is the discipline of designing, selecting, formatting, and managing all information inside a language model's context window at inference time. Moving beyond single-turn prompt writing, it treats system instructions, retrieved knowledge, tool schemas, memory, and conversation history as a unified, token-budgeted software architecture.

## How Context Engineering works in practice

As production applications evolved from single prompts into multi-turn agents and RAG pipelines, failures stopped coming from poorly phrased sentences and started coming from polluted or starved context windows. Context engineering treats the model's context window like scarce RAM in a systems programming environment, dynamically assembling the right payload before every inference call.

A complete context-engineering pipeline controls five layers: static system rules and output schemas (placed at the prefix to maximise KV-cache hits via prompt caching); curated tool definitions filtered to only those relevant to the current turn; just-in-time retrieved documents ranked and deduplicated; compacted conversation state that summarises older turns or strips bulky raw tool outputs; and structured user input delimited with clear XML or Markdown boundaries.

For example, a Leeds healthcare software team building an NHS clinical coding assistant saw accuracy drop whenever patient notes exceeded 40,000 tokens. By re-architecting their context pipeline to strip boilerplate referral headers, compress historical outpatient letters into structured timelines, and load ICD-10 lookup tables on demand via tool calls, they cut cost per query by 62 per cent and raised coding precision by 14 points.

## Why it matters and trade-offs

Even when frontier models advertise one-million-token context windows, stuffing everything into the prompt degrades recall in the middle of the window ('context rot'), inflates time-to-first-token latency, and drives up API spend on every subsequent turn. Disciplined context engineering is often the highest-leverage way to improve an AI product's accuracy and unit economics without training a custom model.

The main pitfall is over-aggressive compaction that silently discards a constraint or identifier the model needs five turns later. Teams should instrument their context assembly step alongside their eval suite, measuring token distribution across system prompts, tool payloads, and retrieved chunks on every production release.

## Related AI concepts

- [Retrieval-Augmented Generation (RAG)](https://aisat.uk/glossary/retrieval-augmented-generation): Retrieval-Augmented Generation (RAG) is an AI architecture that retrieves relevant passages from external documents or databases at query time and injects them into a language model's context window to generate cited, grounded answers.
- [Prompt Injection](https://aisat.uk/glossary/prompt-injection): Prompt Injection is a security vulnerability in which adversarial instructions submitted directly by a user or hidden indirectly inside retrieved web pages, emails or documents override a language model's system prompt to hijack tool calls or exfiltrate data.
- [Large Language Model (LLM)](https://aisat.uk/glossary/large-language-model): A Large Language Model (LLM) is a deep transformer neural network containing billions of parameters trained on massive text and code corpora to comprehend, summarise, translate, reason over and generate human and programming languages.
- [Evals (Evaluations)](https://aisat.uk/glossary/evals): Evals (Evaluations) are automated, repeatable testing pipelines that score an AI application's outputs against a golden dataset using deterministic assertions, reference metrics and LLM-as-a-judge rubrics before any prompt or model change ships.
