Loop Engineering · Lesson 3 · Lever 02 — Context
🌐 English version →

The Context Lever

Lever 02: har turn, aap wo exact tokens assemble karte ho jo model dekhta hai. Us payload ko curate karna agent ki performance ka sabse bada single factor hai.

Six-move turn ka Step 1 tha “context assemble karo.” Sunne mein plumbing lagta hai. Hai nahi — Anthropic context engineering ko “the natural progression of prompt engineering” aur agent reliability par dominant lever kehta hai.1 Prompt engineering ek message tune karta hai; context engineering poore state ko govern karta hai — system instructions, tools, external data, aur poori message history — aur usse har single turn par dobara decide karta hai.1

The one principle Wo “the smallest possible set of high-signal tokens that maximize the likelihood of some desired outcome” dhoondho. Models ke paas ek finite attention budget hota hai; tokens pile karte jaao toh context rot milta hai — window bharte hi accuracy decay hone lagti hai.1 Context ko ek precious, finite resource samjho, koi bucket nahi.

Us principle ka ek non-obvious consequence hai: zyada context safer nahi hota. Yeh instinct ki “zaroorat pad gayi toh? sab kuch ghusa do” — yahi wo cheez hai jisse yeh lever sabse zyada ladta hai. Neeche wo chaar jagahein hain jahan aap budget kharch karte ho — aur yeh rahi ek hi function mein:

build_context — har turn, wo chaar jagahein jahan budget kharch hota hai
def build_context(state):
    return [
        system_prompt,                     # 1 · right altitude — na brittle, na vague
        *tool_defs(minimal=True),          # 2 · kam, non-overlapping tools
        *retrieve_just_in_time(state),     # 3 · data on demand kheencho, pehle se nahi
        *compact(state.history),           # 4 · summarise; redundant tool output drop karo
    ]                                      # goal: smallest high-signal set

1 · System prompt — right altitude dhoondho

Ek extreme par failure mode hai brittle if-this-then-that logic hardcode karna; doosre par, vague guidance jo model ko koi concrete signal hi nahi deti.1 “Right altitude” pakdo: itna specific ki behaviour guide ho, itna flexible ki model ke paas strong heuristics bachi rahein. Use clear sections mein organise karo (XML tags ya Markdown headers) taaki guidance ka har region legible rahe.1

2 · Tools — minimal aur non-overlapping

Tools bhi context hain: unki definitions har turn window mein baithi rehti hain. Set ko chhota, self-contained, aur unambiguous rakho, aur token-efficient results return karwao.1 Litmus test sharp hai:

If a human engineer can’t definitively say which tool should be used in a given situation, an AI agent can’t be expected to do better. — Anthropic, Effective Context Engineering

Yeh wahi ACI (Lever 03) hai Lesson 1 se, context budget ke through dekha hua: bloated, overlapping tool sets ambiguous decision points banate hain aur tokens jala dete hain. Is idea ko pakdo ki tool definitions spent budget hain — yeh rahi concretely:

Ambiguous vs. clear tool surface — kis ko aap defend kar paaoge?
# ✗ overlapping — na aap na agent confidently pick kar paaye
search(q) · find(q) · lookup(q) · query_db(q)

# ✓ har job ke liye ek obvious tool; ids return karta hai, poore files nahi
search_docs(q) -> [{path, snippet}]

3 · Retrieval — just-in-time, pre-loaded nahi

Saara data pehle se mat thoonso. Agent ko lightweight identifiers hold karne do — file paths, queries, links — aur actual content tools se tab kheencho jab usse zaroorat ho.1 Yeh human cognition ko mirror karta hai: hum corpus memorise nahi karte, hum ek index rakhte hain aur cheezein look up karte hain. Agent layer-by-layer understanding assemble karta hai, working memory mein sirf utna rakhta hai jitna zaroori ho. Trade-off honest hai — runtime exploration pre-computed data se slow hai — toh ek hybrid (thoda upfront load karo, baaki explore karo) aksar best hota hai.1

4 · Long horizons — window ko beat karne ke teen tareeke

Jab ek task ek single context window se aage nikal jaata hai, toh aapko bada bucket nahi milta — aapke paas jo hai usi ko manage karte ho. Teen techniques, har ek alag shape ke kaam ke liye suited:1

Long-horizon techniques
TechniqueYeh kya karta haiBest kab
CompactionLimit ke paas conversation summarise karo; window ko summary se restart karo. Decisions & open bugs rakho; redundant tool output drop karo.Lamba back-and-forth jise behte rehna hai
Structured notesAgent window ke bahar memory mein notes likhta hai, relevant hone par wapas kheench leta hai. Persistent memory, minimal overhead.Clear milestones wala iterative kaam
Sub-agentsEk clean-context sub-agent deep kaam karta hai, sirf ~1–2k-token distilled summary return karta hai.Parallel research; detail ko isolate karna

Through-line gaur karo: teeno usi scarce resource ko protect karte hain — high-signal tokens andar rakh kar, aur raw detail ko bahar push kar ke jahan se usse on demand recall kiya ja sake.

Aaj ki aapki win

Ab aap kisi bhi turn ke context ko ek principle ke against audit kar sakte ho — smallest high-signal set — aur waste ko chaar jagah locate kar sakte ho: ek off-altitude system prompt, overlapping tools, eager pre-loading, aur woh history jise aapko compact kar dena chahiye tha. Wahi audit hi context lever hai.

Recall check

Memory se retrieve karo. (Ek question Lesson 2 tak wapas pahuncha hai — yeh deliberate hai.)

Primary source — yeh aage padho

Anthropic — Effective Context Engineering for AI Agents. Is lever ka definitive treatment: attention budget, right-altitude prompts, just-in-time retrieval, aur teen long-horizon techniques. ~20 minute, aur yeh seedha is lesson ke saath pair hota hai.

Main aapka teacher hoon — use karo. Apne kisi agent ke ek real turn ko audit karna chahte ho? Assembled context paste karo aur main lowest-signal tokens ki taraf ishara karunga aur batau ki chaar spots mein se kaunsa budget leak kar raha hai. Curious ho ki compaction vs. sub-agents aapke TradingAgents loop mein kaise play out hote? Bina jhijhak pucho.
Lesson 2: The Dial 📖 Glossary (English) Aage → Lesson 4: Stop conditions & budgets

Sources

  1. Anthropic — Effective Context Engineering for AI Agents. Smallest high-signal set; attention budget & context rot; right-altitude system prompts; minimal non-overlapping tools; just-in-time retrieval; compaction, structured note-taking, sub-agents.
  2. HumanLayer — 12-Factor Agents. Factor 3: own your context window.