Skip to content
AgenticAIWiki
  1. Learn
  2. Part 11
  3. 58. Context engineering
  4. 58.1

Lesson 58.1 · 1 of 7 · 5 min read · Reviewed 24 Nov 2026

Context engineering as a discipline

By the end, you can

  • Define context engineering.
  • Explain why more context isn't always better.

Prompt engineeringPrompt engineering: Designing the instructions, context and examples you give a model so it reliably produces the output you need. asks how to word the instructions. Context engineeringContext engineering: Deciding what goes into the model’s context on each call: instructions, retrieved facts, tool results, memory and history. asks a wider question: what should be in the window right now?

Everything competes

On each turn the model sees the system prompt, tool definitionsTool definition: The name, description and input schema that tell the model what a tool does and how to call it., documents, the conversation so far and every tool result. All of it competes for attentionAttention: The mechanism that lets each token weigh every other token in the context when building its representation.. A large window doesn’t make that free: as context grows, models get worse at finding and using the key facts. Think of it as a budget, not a bucket.

The aim

The smallest set of high-signal tokensToken: The unit a model reads and writes: a word, part of a word, a space or a symbol, mapped to an integer id. that lets the model take the next step well.

The toolbox

This chapter covers the main techniques:

Technique Lesson
Pull in data only when it’s needed 58.2
Remove old tool results 58.3
Give side work to subagents with their own context 58.4
Keep state in notes outside the context 58.5
Claude features that help: context editing and the memory tool 58.6

Chapters 59 to 62 go deeper on budgets, summarising, sessions and big inputs.

Key points

  • Context engineering is choosing what goes into the model's context on each turn: instructions, tools, data, history.
  • The context window is a limited budget, and attention spreads thinner as it fills.
  • The goal is the smallest set of high-signal tokens that lets the model do the next step well.
Hands-on labRuns in the Playground

Audit what fills an agent's context

Measure which parts of an agent's context are high-signal for the next step, and pick a context engineering technique for each low-signal part.

You will have: An audit table with tokens, share and a recommended technique per part, plus the high-signal share before and after.

Steps

  1. Read the PARTS list: name, tokens, kind and whether the next step needs it.
  2. Compute each part's share of the total and the overall high-signal share.
  3. Map each low-signal part to a technique: clear tool results, fetch just in time, delegate to a subagent, or move to notes.
  4. Estimate the context after applying the techniques (each handled part shrinks to 100 tokens) and print the new high-signal share.

Done when

  • The audit prints a row for every part.
  • Every low-signal part has a technique.
  • The high-signal share rises above 70% after the changes.

Open in the Playground No API key needed.

Starter code (Python)
PARTS = [
    ("system prompt", 2500, "instructions", True),
    ("tool definitions", 3000, "tools", True),
    ("current plan", 400, "notes", True),
    ("old search results", 18000, "tool_result", False),
    ("full API docs pasted at start", 22000, "document", False),
    ("exploration of 12 files", 15000, "exploration", False),
    ("last 3 turns", 2400, "history", True),
]
TECHNIQUE = {
    # TODO: map kinds of low-signal parts to a technique name
}

total = sum(t for _, t, _, _ in PARTS)
for name, t, kind, needed in PARTS:
    print("%-30s %6d %5.1f%% %s" % (name, t, 100 * t / total, "needed" if needed else TECHNIQUE.get(kind, "TODO")))
# TODO: print the high-signal share now, and after each handled part shrinks to 100 tokens
Show a solution
PARTS = [
    ("system prompt", 2500, "instructions", True),
    ("tool definitions", 3000, "tools", True),
    ("current plan", 400, "notes", True),
    ("old search results", 18000, "tool_result", False),
    ("full API docs pasted at start", 22000, "document", False),
    ("exploration of 12 files", 15000, "exploration", False),
    ("last 3 turns", 2400, "history", True),
]
TECHNIQUE = {
    "tool_result": "clear old tool results",
    "document": "fetch just in time",
    "exploration": "delegate to a subagent",
    "history": "summarise into notes",
}

total = sum(t for _, t, _, _ in PARTS)
for name, t, kind, needed in PARTS:
    print("%-30s %6d %5.1f%% %s" % (name, t, 100 * t / total, "needed" if needed else TECHNIQUE.get(kind, "move to notes")))
signal = sum(t for _, t, _, n in PARTS if n)
after = signal + sum(100 for _, _, _, n in PARTS if not n)
print("high-signal share before: %.0f%%" % (100 * signal / total))
print("high-signal share after: %.0f%% of %d tokens" % (100 * signal / after, after))
Quick checkAn agent's answers get worse as a long task goes on, though nothing is cut off. What's the most likely cause?
How sure are you?
Pick an answer and how sure you are