Skip to content
Sajith JeewanthaSoftware Engineer

Track 10 · Specialisation

Prompt & Context Engineering

Decide exactly what a model sees: clear prompts, the right examples, retrieved knowledge, memory and tools, packed into a limited context window. Then optimise and evaluate it like code.

Last updated
Total effort
390 h · ≈ 39 weeks
Your progress

Overview

Prompt engineering was about wording: how to phrase an instruction so the model does what you want. Context engineering is the bigger job of deciding everything that goes into the model's context window on each call: the system prompt, examples, retrieved documents, conversation history, memory, tool definitions and tool results. The window is finite and attention degrades as it fills, so every token has to earn its place. This track teaches you to write prompts precisely, to understand how and why long contexts fail, to assemble and compress context on purpose, and to treat prompts as code: versioned, tested, and sometimes optimised automatically.

Why it matters heading into 2027

In June 2025 Shopify's Tobi Lütke and Andrej Karpathy argued that context engineering describes the real skill better than prompt engineering. Within months LangChain, Simon Willison and Anthropic had written it up, and Anthropic's September 2025 guide made it a core practice for building agents. As agents run longer and call more tools, the hard problem is no longer one clever prompt; it is managing a context that changes every step without letting it rot. Research such as Chroma's Context Rot report and Lost in the Middle shows that more context is not automatically better. This is now a core skill for anyone building agents, and the agentic-AI skill cluster is the fastest-growing in job postings.

Prerequisites

  • Have built at least one small app that calls an LLM API (AI Engineering Beginner stage).
  • Know what tokens and a context window are, and roughly how a Transformer attends over its input.
  • Basic Python for scripting experiments and evals.

Learning path

How the stages build on each other, and where this track hands off to others.

flowchart TB
  P["Prereqs: one LLM app · tokens · Python"] --> B
  subgraph B["1 · Beginner — prompts that work"]
    direction LR
    B1["clear instructions"] --> B2["few-shot examples"] --> B3["structure · XML tags"]
  end
  subgraph I["2 · Intermediate — context, not just prompts"]
    direction LR
    I1["retrieval vs memory vs tools"] --> I2["context budget"] --> I3["failure modes"]
  end
  subgraph A["3 · Advanced — long-running context"]
    direction LR
    A1["compaction · notes"] --> A2["sub-agent isolation"] --> A3["cache-aware layout"]
  end
  subgraph E["4 · Expert — optimise & measure"]
    direction LR
    E1["DSPy · GEPA"] --> E2["prompt evals in CI"] --> E3["context-rot experiments"]
  end
  B --> I --> A --> E
  A -.-> HAR["Harness Engineering"]
  I -.-> AI["AI Engineering"]
  E -.-> SEC["AI Security & Safety"]

Stages

Tick items as you go — progress is saved in this browser only. Times are focused hours (reading + building); the week estimates follow the study time you pick above.

01Beginner50 h · ≈ 5 weeksWrite prompts that are clear, specific and testable. Learn the techniques that reliably help, and build the habit of checking every prompt against examples.

Key concepts

Build these

Ready for the next stage when…

02Intermediate80 h · ≈ 8 weeksMove from writing prompts to assembling context. Learn what to put in the window, what to leave out, and how long contexts fail.

Key concepts

Build these

Ready for the next stage when…

03Advanced120 h · ≈ 12 weeksManage context across long, multi-step agent runs: compaction, structured notes, sub-agents with their own clean windows, and layouts that keep prompt caches warm.

Key concepts

Build these

Ready for the next stage when…

04Expert140 h · ≈ 14 weeksTreat prompts and context policies as programs to optimise and measure. Use automatic prompt optimisation, run controlled long-context experiments, and publish what you learn.

Key concepts

Build these

Ready for the next stage when…

Field guide

The ideas behind the checklist, with diagrams and the math where it helps.

From prompt to context

A prompt is one string. A context is everything the model sees on this call. In a modern agent, the part you wrote by hand is often a small fraction of the window; the rest is history, retrieved data and tool output that changes every step.

flowchart TB
  subgraph STABLE["Stable prefix (cache-friendly)"]
    direction LR
    SYS["system prompt<br/>role · rules · style"] --> TOOLS["tool definitions"] --> EX["few-shot examples"]
  end
  subgraph DYN["Dynamic part (changes every step)"]
    direction LR
    MEM["memory / notes<br/>(loaded on demand)"] --> RET["retrieved documents"] --> HIST["conversation + tool results<br/>(compacted)"] --> Q["current request"]
  end
  STABLE --> DYN --> W["context window"] --> M["model"] --> A["answer or tool call"]
  A -- "tool result" --> HIST

Order matters for two reasons. Keeping the stable parts first lets the serving engine reuse its KV cache across calls (cheaper and faster). Putting the current request last, close to where the model starts generating, avoids it being lost in the middle.

A context budget

Treat the window like memory in a small device. If the window holds WW tokens and you need room for the answer:

Tsystem+Ttools+Texamples+Tmemory+Tretrieved+Thistory+Tanswer≤WT_{\text{system}} + T_{\text{tools}} + T_{\text{examples}} + T_{\text{memory}} + T_{\text{retrieved}} + T_{\text{history}} + T_{\text{answer}} \le W

Fitting is not the goal, though. Quality usually drops well before the limit, so set your own budget for each component (for example “retrieved docs ≤ 8k tokens, history compacted above 30k”) and log the actual numbers. A useful signal is the share of the window that is relevant to the current step:

signal ratio=tokens the step actually needstokens in context\text{signal ratio} = \frac{\text{tokens the step actually needs}}{\text{tokens in context}}

You can’t measure the numerator exactly, but asking the question changes your design: fewer tools, shorter tool results, and retrieval on demand instead of pasting everything in.

Prompting techniques that still matter

  • Be specific about the output. Give a schema, an example, and what to do when the answer is unknown.
  • Use structure. Wrap documents, examples and instructions in clear tags so the model can tell them apart.
  • Show, don’t just tell. Two or three varied examples often beat a paragraph of rules.
  • Let it think when it helps. Chain-of-thought helps non-reasoning models on multi-step problems; reasoning models already do this internally, so focus on clear goals and constraints instead.
  • Test, don’t guess. Every technique helps on some tasks and hurts on others. Your test set decides.

Why long contexts fail

FailureWhat happensTypical fix
Poisoninga hallucination or error enters context and gets repeatedvalidate tool results; let the agent re-check facts
Distractionlong history makes the model repeat past actionscompaction; fresh sub-agent windows
Confusionirrelevant tools or documents get usedfewer tools; better retrieval; filter results
Clashcontradictory information in contextremove outdated facts; mark sources and dates
Rotaccuracy falls as length grows, even on easy taskskeep context short; just-in-time retrieval

Managing context over a long run

Three tools cover most cases:

  1. Compaction. When history grows past a threshold, summarise it, keeping decisions, unresolved issues and exact identifiers (file paths, IDs). Drop raw tool output first.
  2. Notes. Let the agent write progress to a file or memory store (NOTES.md, a TODO list) and read it back. This survives compaction and even new sessions.
  3. Sub-agents. Send a focused sub-task to a fresh window. The sub-agent may read 50k tokens; the parent receives 500.

Optimising prompts automatically

Once you have a reliable eval, you can let software search for better prompts. DSPy expresses a pipeline as typed modules and uses optimisers (including GEPA) to choose instructions and examples. The risk is the same as in ML: overfitting to your dev set. Keep a held-out set, compare across several runs, and re-check when you switch models.

How this track connects

References

Original sources first: arXiv, official docs, university courses and lab blogs. Every link was checked on 7 Nov 2026.

Foundational & seminal papers(10)

  1. Chain-of-Thought Prompting Elicits Reasoning in Large Language Models

    Wei et al. · 2022 · arxiv.org

    The foundational reasoning prompt.

  2. Self-Consistency Improves Chain of Thought Reasoning in Language Models

    Wang et al. · 2022 · arxiv.org

    Sample several reasoning paths and take a majority vote.

  3. Large Language Models Are Human-Level Prompt Engineers (APE)

    Zhou et al. · 2022 · arxiv.org

    Letting a model search for better instructions.

  4. Large Language Models as Optimizers (OPRO)

    Yang et al. · 2023 · arxiv.org

    Using an LLM as the optimiser for prompts.

  5. Lost in the Middle: How Language Models Use Long Contexts

    Liu et al. · 2023 · arxiv.org

    Position matters: information in the middle is used less well.

  6. DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines

    Khattab et al. · 2023 · arxiv.org

    Write LLM pipelines as programs and let an optimiser tune the prompts.

  7. MemGPT: Towards LLMs as Operating Systems

    Packer et al. · 2023 · arxiv.org

    Paging information in and out of a limited context, like virtual memory.

  8. The Prompt Report: A Systematic Survey of Prompt Engineering Techniques

    Schulhoff et al. · 2024 · arxiv.org

    A taxonomy of prompting techniques and terminology.

  9. GEPA: Reflective Prompt Evolution Can Outperform Reinforcement Learning

    Agrawal et al. · 2025 · arxiv.org

    Prompt optimisation by reflection and evolution.

  10. Agentic Context Engineering: Evolving Contexts for Self-Improving Language Models

    Zhang et al. · 2025 · arxiv.org

    Contexts that grow and curate themselves as playbooks.

Courses & videos(1)

  1. DeepLearning.AI short courses

    DeepLearning.AI · deeplearning.ai

    Short, free courses on prompting, RAG and agents.

Books(1)

  1. Prompt Engineering (whitepaper)

    Lee Boonstra, Google · 2025 · kaggle.com

    A practical 68-page guide to prompting techniques and settings.

Articles, blogs & official docs(13)

  1. Effective context engineering for AI agents

    Anthropic · 2025 · anthropic.com

    Compaction, note-taking, sub-agents and just-in-time context — start here.

  2. Context engineering (post on X)

    Tobi Lütke · 2025 · x.com

    The post that popularised the term.

  3. +1 for context engineering (post on X)

    Andrej Karpathy · 2025 · x.com

    A widely quoted definition of the craft.

  4. Context engineering

    Simon Willison · 2025 · simonwillison.net

    Why the new term fits better than prompt engineering.

  5. The rise of context engineering

    LangChain · 2025 · langchain.com

    Context engineering as a systems problem for agents.

  6. How Long Contexts Fail

    Drew Breunig · 2025 · dbreunig.com

    Names the failure modes: poisoning, distraction, confusion, clash.

  7. Context Rot: How Increasing Input Tokens Impacts LLM Performance

    Chroma (Hong, Troynikov & Huber) · 2025 · trychroma.com

    Experiments showing quality falls as input grows.

  8. Context Engineering for AI Agents: Lessons from Building Manus

    Yichao 'Peak' Ji · 2025 · manus.im

    KV-cache-aware layout, masking tools, and using the file system as memory.

  9. Prompt engineering overview

    Anthropic · platform.claude.com

    Official guidance for Claude models.

  10. Prompt engineering guide

    OpenAI · developers.openai.com

    Official guidance for OpenAI models.

  11. GPT-4.1 Prompting Guide

    OpenAI · 2025 · developers.openai.com

    Prompting literal-minded, agentic models.

  12. GPT-5 prompting guide

    OpenAI · 2025 · developers.openai.com

    Controlling reasoning effort and agentic eagerness.

  13. DSPy documentation

    Stanford NLP · dspy.ai

    The framework for programming (not prompting) language models.