GuideIntermediate
Context Engineering
This guide treats a model call's context window for what it actually is: a finite resource to budget, not a canvas for writing the perfect prompt. The driving case is Reservo's Support Assistant, a question-answering assistant (no tools, no loop) that answers member questions about cancellations, pricing, room specs, and membership using documents that are already retrieved by a deterministic mock function — real retrieval belongs to a different guide. With that case, the guide covers the system prompt as a versioned, auditable component (never free-form writing), the structure of the payload (block order, delimiters), selecting content under a fixed token budget when there are more candidates than fit, compacting the conversation history (compressing while preserving what matters, in two stages), few-shot examples treated as just another budget line item, context rot (more input tokens degrade performance, citing real research) with isolation as a conceptual mitigation, and measuring the effect of every change by form — never semantically. All the engineering (counting, selecting, structuring, compressing, measuring) actually runs on Python 3.14; the model's response is honestly treated as a concept. Token counting always uses an order-of-magnitude estimate (`len(text) // 4`), labeled as such, never a real third-party tokenizer.
- 64
- lessons
- 8
- modules
- English · Spanish
- available in
- Yes
- certificate
- Free
- access
Outcomes
What you'll be able to do
- Distinguish context engineering (budgeting and structuring the window) from prompt engineering (writing prompt text), and place every real component of a Claude context: `system`, history, documents, examples, output constraints
- Write the system prompt as versioned, auditable text passed in the top-level `system` parameter — never as a `role: "system"` message inside `messages` — and verify it meets minimum rules (citing the source, what to do when information is missing)
- Structure the context with a defined block order and clear delimiters (tags), and validate that structure with a form checker
- Select what content fits under a fixed token budget when there are more candidates than room: greedy selection by a given relevance score, deduplication, and a per-source cap on chunks
- Compact a conversation history that grows turn by turn, beyond simple positional trimming: extracting key fields into a structured record and two-stage compaction for long sessions
- Decide whether few-shot examples are worth including, how many fit under the remaining budget, and where they go in the context structure — comparing their token cost against an extra document
- Measure context rot (the real performance degradation as input tokens grow, not just the cost) and apply isolation as a mitigation concept, with its boundary marked against real sub-agent orchestration
- Measure the effect of any context change with form-based evals — tokens under budget, correct order, key fields preserved — never a semantic judgment or a model-based evaluator
- Count tokens with an honest, consistent approximation throughout the guide, never disguised as an exact count
- Integrate everything into a context pipeline (`build_context`) that assembles the system prompt, structure, budget-constrained selection, compaction, and few-shot, compared against a naive payload that dumps the whole corpus with no criteria
Before you start
What you need to bring
It's for you if...
- Developers building LLM apps or agents on top of retrieved documents who need a disciplined way to decide what enters the context window
- Anyone who already knows prompt engineering (roles, few-shot, structured outputs) and wants to move from "writing a good prompt" to budgeting and structuring context as an engineering resource
- Developers already using RAG who receive retrieved chunks but are missing the next step: curating, ordering, and compressing them before sending them to the model
- Backend or AI engineers preparing for long-term memory, production RAG, or multi-agent orchestration who need this budgeting discipline as a foundation
Requirements and materials
- Prior knowledge of prompting or agent fundamentals: what a prompt is, `user`/`assistant` roles, zero-shot vs few-shot
- Basic Python: functions, `dataclasses`, lists, and dictionaries
- Python 3.14 installed with its standard library; no API key or internet connection required — all the engineering runs locally
Content
The syllabus, module by module
Open any of them to see its lessons.
- Module 2: System prompts and instructions
- The system prompt as a budget item
- Where the system prompt goes: the top-level `system` parameter
- Rules for using the documents
- Handling missing information
- Output format instructions
- Auditing the system prompt: `lint_system_prompt`
- Mini-project: the Reservo Assistant's system prompt
- Module 5: Compaction — summarizing history and long results
- Why history grows and what to compact
- Extracting key fields into a structured record
- Summarizing a long result
- Two-stage compaction for long sessions
- What compaction must preserve
- Going beyond agent-fundamentals M6
- Mini-project: a compaction pass for the Assistant
- Module 7: Context rot, isolation, and measuring context changes
- What is context rot
- Simulating degradation as context grows
- Measuring a form signal with and without the techniques
- Isolation: giving a sub-task its own clean window
- The habit of measuring before and after
- Putting the measurement loop together
- Mini-project: measure a context change
Common questions
What people usually ask
No limit. It's a free guide: come in whenever you like, as often as you like.
No. Modules run from easier to harder, but you can jump to the one you need. Progress is saved per lesson.
Whatever is needed is listed under “What you need to bring”, above. If nothing is listed there, you can start from zero.
In the Club's WhatsApp group, and every two weeks there's a live with an instructor where questions get worked through.
Yes. It's issued automatically once you finish every lesson, with a verifiable code you can share on LinkedIn.
Start whenever you like
What students say
These reviews are from enrolled students who completed at least 50% of the course. We moderate reviews only on content grounds (spam, offensive language, personal data), never for being critical or negative.
No approved reviews yet.
Be the first to share your experience!