Context engineering is the practice of deliberately constructing everything a language model sees at inference time, including system instructions, retrieved documents, tool outputs, conversation history, and working memory, in order to get reliable behavior from an AI agent operating over many steps. The term gained currency in 2025 as a successor framing to Prompt engineering, reflecting a shift in emphasis from crafting a single clever instruction toward managing the full, dynamically assembled state fed into a model's limited context window.
Proponents of the term, including AI researcher Andrej Karpathy, argued that as applications moved from single-turn chat toward multi-step agents, the dominant source of failure shifted from poor prompt wording to poor context management: irrelevant or missing information, stale tool outputs, and context windows cluttered with low-value content.
Techniques
Common context engineering techniques include selecting and compressing retrieved content, commonly via Retrieval-augmented generation, so that only the most relevant material occupies scarce context space. They also include structuring tool definitions, outputs, and error messages so an agent can act on them without ambiguity, an area where the open Model Context Protocol emerged as shared infrastructure for supplying tools and data consistently across models. Managing memory across turns or sessions, deciding what to summarize, discard, or persist, is another core piece, since even models with very large context windows show degraded attention to information placed in the middle of a long context. Ordering and formatting information deliberately matters as well, since model behavior has been shown to be sensitive to where key facts sit within a prompt, an effect sometimes described informally as content getting "lost in the middle."
Relationship to prompt engineering
Context engineering does not replace Prompt engineering so much as broaden its scope: writing a good instruction remains necessary, but is treated as one component of a larger system that also governs what data, tools, and history the instruction operates over. The distinction mirrors a broader shift in the field from single-shot completions toward agentic systems that make many model calls in sequence, where the cumulative effect of context management compounds across steps in ways a single well-written prompt cannot fix. By 2026 the term had become common in engineering job postings and internal tooling documentation at AI companies, though its boundaries with related practices such as retrieval system design and agent orchestration remained loosely defined.