Context Engineering tutorial

Learn to choose, arrange and check what an AI model sees, so its answers are correct, safe and affordable.

Start the course

Course contents

Foundations

  1. Context Basics — What context is, why a model only knows what is in its context window, how context engineering differs from prompt engineering, the 14 parts a context can hold, and why good context gives better answers.
  2. Context Windows — How text becomes tokens, how big the context window is, why the reply needs its own budget, why facts in the middle of a long context get missed, and how sampling settings work with the context.
  3. Context Selection — How to decide what goes into a context: include, exclude, summarize, or retrieve on demand. The minimum context principle, evidence sufficiency, speed and cost, and stable versus dynamic context.
  4. Context Formatting — How to label and separate the parts of a context with headings, XML tags, and delimiters, keep instructions apart from data, defend against prompt injection, and place rules, schemas, and sources.

Design Patterns

  1. Grounded Responses — How to make the model answer only from its sources: source of truth, refusal rules, evidence boundaries, and citations with quotes, ids, sections and pages that code can check.
  2. Retrieval Patterns — How to handle retrieved documents once they are in the context: relevance, not-enough-evidence, confidence, and metadata such as region, date, tier, role and clearance, plus conflict rules.
  3. Memory Patterns — How to plan tool use, track where facts came from, and compress a long conversation into a state snapshot that keeps goals, decisions, constraints and open tasks, without losing the ability to check it.
  4. Schema Design — How to give the model's reply a fixed shape with JSON Schema, Markdown or Pydantic, add fields for confidence and missing information, and check every reply in a validation pipeline.

Memory, Media and Tools

  1. Memory Management — How an app manages memory over time: short-term, long-term and state, extracting decisions and open tasks, compacting at the right time, and the lifecycle and privacy rules for stored memory.
  2. Document and Media Context — How PDFs, Word files, spreadsheets, slides, images, audio and video become labelled text a model can use, how to keep unclear parts marked as unclear, and a four-step framework for any file.
  3. Tool and Connector Context — How tool calls work, why tool definitions and results are context, how to check arguments and shape results with status, source and time, and how tools, APIs and connectors differ.

Optimization and Security

  1. Caching and Cost — How prompt caching reuses the stable start of a request, what to cache, what breaks it, how input, output and cached tokens are priced, and how to cut cost and waiting time.
  2. Context Security — How to defend a context against direct and indirect prompt injection, label data by trust, enforce role-based permissions in code, restrict tools when risk is high, and send risky actions for approval.

Production

  1. Debugging and Evaluation — How to find why a context failed with a step-by-step diagnostic checklist and traces, how to measure a context with an evaluation set, how to improve it in a loop, and what context engineering can't fix.
  2. Capstone: Real-World Context Setups — Put the whole course together: turn a weak employee handbook assistant, coding assistant, and research assistant into strong ones, and score any setup with one checklist.