Vibe Engines
YouTube
LEARNING PATH · AI Engineering

Master Context Engineering

For engineers whose agents forget, ramble, or blow the window.

Intermediate ~4h 15m10 lessons14 steps

The discipline that replaced prompt-tweaking, learned end to end: tokens and budgets, the four operations (write, select, compress, isolate), compaction and memory, cache-aware prompts — threaded through the handbook, labs, tools, papers and system designs.

  • Treat the context window as a budget and spend it deliberately
  • Apply write / select / compress / isolate to any overflowing agent
  • Design compaction, memory and just-in-time retrieval that keep long tasks coherent
  • Order prompts so caching slashes latency and cost
0 / 10 done · 0%
  1. HandbookNext up

    The Context Engineering Handbook

    The whole discipline in one sitting — read this first, revisit last.

  2. Lab

    The Tokenizer

    What a token actually is — watch BPE build them.

  3. ToolTool · optional

    Token Counter

    Measure a real prompt: tokens, cost, window fit.

  4. ToolTool · optional

    Context Window Visualizer

    Watch system prompt, tools, history and RAG fight for one budget.

  5. ToolTool · optional

    Context Budget & Cost Planner

    Price the window — what every extra segment costs.

  6. Challenge

    Trim History to a Token Budget

    Implement the compress operation under a hard budget.

  7. Handbook

    The RAG Handbook

    Select: retrieval is how the right knowledge enters the window.

  8. ToolTool · optional

    RAG Chunking Playground

    Tune chunk size and feel the precision/noise tradeoff.

  9. AI System Design

    Design an Agent Memory System

    Write: persist state outside the window, recall it on demand.

  10. Paper Breakdown

    MemGPT

    The OS view — context as RAM, storage as disk, the model as memory manager.

  11. Handbook

    The Agent Skills Handbook

    Isolate expertise: progressive disclosure, productized.

  12. Handbook

    The Loop Engineering Handbook

    When the loop compacts, spawns sub-agents, and re-reads notes.

  13. Handbook

    Self-Improving Agents

    The six places a lesson can land — context is the cheapest, and usually the right one.

  14. AI System Design

    Design ChatGPT

    Context engineering at planet scale — rebuilt every turn, cached by prefix.

How this path works

This path is for engineers whose agents or chat features get worse as a session grows: they forget an instruction from twenty turns ago, repeat a failed attempt, run out of window, or cost far more than the prototype did. It suits anyone building retrieval apps, copilots or long-running agents who already knows how to call a model.

Context engineering is the work of deciding, for every call, what the model sees: the system prompt, tool definitions, examples, retrieved knowledge, history and memory, and what is left out. In practice that means measuring tokens instead of guessing, applying four operations (write, select, compress and isolate) on purpose, and ordering a prompt so caching keeps working. In interviews it shows up as questions like how you would keep a fifty-turn agent coherent, or what you do when a conversation outgrows the window.

The order mirrors how the skill is learned. The handbook comes first as the map, and the path asks you to revisit it at the end. The tokenizer lab, token counter, window visualizer and cost planner then make the budget concrete. After that each operation gets hands-on time: compress by trimming history, select through retrieval and chunking, write through memory systems and MemGPT, and isolate through skills, sub-agents and loops. The ChatGPT design closes the path by doing all of it on every turn, at scale.

What each step gives you

  1. The Context Engineering Handbook

    The map for everything after it: what fills a production window (system prompt, tools, examples, retrieved knowledge, history, memory and the request), why stuffing more in fails through attention, cost and behavioral drift, and the four operations of write, select, compress and isolate. Read it first for the vocabulary, then return at the end and check that you can work its quadratic-cost example yourself.

  2. The Tokenizer

    Before you can budget a window you need its unit, and this lab shows text shattering into sub-word tokens, races character, word and sub-word tokenizers, and has you run Byte-Pair Encoding merges by hand. It explains the practical surprises, such as why code, numbers and rare names cost more tokens than ordinary prose and why models stumble at counting letters.

  3. Token Counter

    Paste a real system prompt, document or code file and get an estimated token count, the input cost across several models, and how much of each window size from 8K to 1M it would fill. Use it to replace guesses with numbers, starting from the rules of thumb that hold for English prose, about four characters per token, and why code and some non-Latin scripts cost more.

  4. Context Window Visualizer

    Set token counts for the system prompt, tool definitions, retrieved context, chat history, the user message and an output reserve, then watch a stacked bar fill the chosen window and overflow. The overflow panel estimates how much compaction would have to remove, which trains two habits: reserving room for the answer, and spotting which band, usually history or retrieval, is crowding out the rest.

  5. Context Budget & Cost Planner

    The same segments, priced: model a conversation turn by turn and see peak context, total input tokens with history resent on every turn, and the cost per conversation, day and month at a chosen price tier. It makes the compress operation concrete, because you can shorten the history you resend and watch the monthly bill fall before you change any code.

  6. Trim History to a Token Budget

    Implement the simplest compress operation: given the token counts of a conversation's messages, keep the most recent ones that fit a hard budget, walking back from the newest and stopping at the first message that would overflow. Hidden tests cover edge cases such as a single message larger than the whole budget, and the result is the baseline any summarizing compaction has to beat.

  7. The RAG Handbook

    Retrieval is the select operation at its most common, and this handbook covers the two-phase pipeline, chunking and its token arithmetic, embeddings and vector search, hybrid retrieval, reranking for precision at the top, grounded generation with citations, and evaluation, ending with a whole pipeline in about 60 lines. It prepares you to decide how many retrieved tokens a turn deserves and how to check that the right ones arrived.

  8. RAG Chunking Playground

    Chunking decides what a single retrieved unit costs and what it carries, so try fixed, recursive, sentence and paragraph strategies on your own text and read the token count of each chunk. A few rounds here show why a few hundred tokens with modest overlap is a common starting point, and when prose or code calls for a different split.

  9. Design an Agent Memory System

    The write operation as a system: why stuffing history fails, a working set plus a persistent store, a write path that distills instead of dumping, vector and structured stores, a recall path that scores relevance, recency and importance, consolidation and forgetting, and the risks of stale, private or poisoned memories. It prepares you for the design question of how an assistant remembers a user across weeks without its prompt growing.

  10. MemGPT

    MemGPT treats the context window as RAM and external storage as disk, with the model managing its own memory through function calls: paging documents in, writing facts out, and summarizing before eviction when memory pressure raises an interrupt. Read it right after the memory design to compare a fixed retrieval policy with self-directed memory, and to explain what each approach trades away.

  11. The Agent Skills Handbook

    Skills are the isolate operation packaged: a folder whose SKILL.md body loads only when its one-line description matches the task, so dozens of playbooks cost little more than their descriptions until one is used. The handbook compares skills with tools, MCP and fine-tuning, shows how to write descriptions that actually trigger, and treats skills as dependencies with a security surface of their own.

  12. The Loop Engineering Handbook

    Context engineering shapes one run, while loop engineering shapes the system around many runs: when to compact, when to hand a subtask to a sub-agent with a fresh window, and how state recorded outside the model lets the next run resume. Read it for the failure modes that are context problems in disguise, such as quality decaying in a marathon context and every run starting from amnesia.

  13. Self-Improving Agents

    When an agent learns from its own runs, the lesson has to land somewhere: in the context, external memory, the tool set, the scaffold, the verifier or the weights. This long handbook compares all six, and its case that context is usually the cheapest and most reversible place is why it sits on this path, along with its guidance on which traces are worth keeping.

  14. Design ChatGPT

    The capstone shows context engineering in a large consumer chat product: a conversation store sharded on its access pattern, context rebuilt from scratch on every turn, a model router as the cost lever, and prefix caching that only pays off when the stable parts come first. It prepares you to explain cache-aware prompt ordering and how caching a shared prefix saves prefill work on every turn.

A study plan

  1. Day 1

    Read Context Engineering, Explained in one sitting. Then take a prompt from your own agent or app and sort every part of it into the segments the handbook lists, noting which ones change on every turn and which never do.

  2. Days 2–3

    Play the Tokenizer lab, then put your real prompt through the Token Counter, the Context Window Visualizer and the Context Cost Planner. Record three numbers you will compare against later: peak context, tokens resent per conversation, and monthly cost at your expected traffic.

  3. Days 4–5

    Solve Trim History to a Token Budget, read The RAG Handbook, and run one of your own documents through the RAG Chunking Playground at two settings. Decide how many retrieved tokens a typical turn in your app actually deserves, and write the number down.

  4. Days 6–8

    Read Design an Agent Memory System, MemGPT and Agent Skills. On one page, design memory for your agent: what gets written and when, how recall is scored, what is forgotten, and which instructions should move out of the system prompt into a skill.

  5. Days 9–10

    Read The Loop Engineering Handbook, The Self-Improving Agents Handbook and Design ChatGPT. Reorder your prompt so stable content comes first, rerun the cost planner, then return to the first handbook and work its quadratic-cost example without looking.

Questions about this path

What is context engineering in AI?

Context engineering is deciding what a language model sees at each step: the system prompt, tool definitions, examples, retrieved documents, conversation history and stored memory, and just as deliberately what it does not see. Prompt engineering asks how to phrase one instruction, while context engineering treats the whole window as the thing you design, which matters most in agents, where the window is rebuilt on every turn. Most techniques fall into four operations: write information outside the window, select what enters it, compress what stays, and isolate work into separate contexts.

Does a bigger context window remove the need for context engineering?

No. A larger window changes how much you can include, not what you should include. As a window fills, models tend to recall information less reliably, especially material buried in the middle, and stale or irrelevant text can pull answers in the wrong direction. Every token is also processed and paid for on every call, so time to first token and cost both grow with input length. Long windows are useful headroom, but curating what goes in still decides quality and cost.

Why does my AI agent forget instructions in long conversations?

Usually because the instruction is no longer in the window, or no longer gets enough attention. Many harnesses trim or summarize old history when the window fills, and an instruction given early in a chat can be dropped or blurred in that summary. Even when it is still present, it competes with piles of tool output. Put durable rules in the system prompt, compact old turns into summaries that keep constraints word for word, keep a notes file the agent re-reads, and move big subtasks into sub-agents with fresh windows.

How should I order a prompt to benefit from prompt caching?

Put stable content first and volatile content last. Providers that support prompt or prefix caching reuse the processed beginning of a prompt only when it matches a recent one exactly, so any change early in the prompt invalidates the cache for everything after it. In practice the system prompt and tool definitions go first, then long reference material that rarely changes, then conversation history, with the newest user message and freshly retrieved chunks at the end. Keep timestamps and random IDs away from the top.

Models stopped being the bottleneck; what you feed them became it. This path takes you from "what is a token" to designing the memory architecture of a long-running agent — the full context-engineering curriculum, in the order the ideas actually build on each other.

You start with the handbook for the whole discipline and the four operations, then make the budget tangible (tokenizer, counter, visualizer), then go hands-on with each: trimming under a budget, selecting via retrieval and chunking, persisting with memory systems, and isolating with skills and sub-agent patterns. It ends at planet scale — how ChatGPT itself rebuilds context every single turn.

← All learning paths