Context Engineering: Windows, Budgets, Memory, and Retrieval
Prompt engineering is a subset. Context engineering is the whole game. A prompt is a string you type. Context is everything that goes into the model's window: system instructions, retrieved documents, tool definitions, conversation history, few-shot examples, and the prompt itself. The best AI engineers in 2026 are context engineers. They decide what goes in, what stays out, and in what order. Related: Phase 11 · 15 (Prompt Caching) — the cache-friendly layout is an extension of context engineering. Phase 5 · 28 (Long-Context Evaluation) for how to measure lost-in-the-middle with NIAH/RULER. Calculate token budgets across all context window components (system prompt, tools, history, retrieved docs, generation headroom). Implement context window management strategies: truncation, summarization, and sliding window for conversation history. Prioritize and order context components to maximize the model's attention on the most relevant information. Build a context assembler that dynamically allocates tokens based on query type and available window space. Claude Opus 4.7 has a 200K token window (1M in beta). GPT-5 has 400K. Gemini 3 Pro has 2M. Llama 4 claims 10M. These numbers sound enormous until you fill them. Here is a real breakdown for a coding assistant. System prompt: 500 tokens. Tool definitions for 50 tools: 8,000 tokens. Retrieved documentation: 4,000 tokens. Conversation history (10 turns): 6,000 tokens. Current user query: 200 tokens. Generation budget…
Context Engineering: Windows, Budgets, Memory, and Retrieval: Prompt engineering is a subset. Context engineering is the whole game. A prompt is a string you…
This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.
Browse the complete course catalog or open this lesson on GitHub.