Loop Engineering · Lesson 2 · Lever 01 — Control flow
🌐 English version →

The Dial, aur paanch Patterns

Lever 01 ko paas se: har point par decide karna ki aapka code drive karta hai ya model — aur workflow side jin paanch shapes mein aata hai unhe name dena.

Lesson 1 ne aapko map diya aur uska master lever: control flow — agla step kaun decide karta hai, aapka code (ek workflow) ya model (ek agent). Apne intuition mein karne waali sabse zaroori correction yeh hai: yeh choice ek baar poore system ke liye nahi hoti. Yeh ek dial hai jo aap har decision point par set karte ho.

Ek production “agent” aam taur par ek mostly-deterministic program hota hai jisme model kuch high-leverage spots par dial-in kiya hota hai, aur jahaan reliability code se sasti milti hai wahaan dial out kiya hota hai.2 Is lesson mein aapka kaam: dial ko deliberately set karna seekhna, aur workflow end jin paanch named shapes mein aata hai unhe pehchaanna.1

Wo default jo cleverness ko harata hai

Anthropic ki headline finding, dozens production deployments survey karne ke baad, lagbhag anticlimactic hai:

Consistently, the most successful implementations weren't using complex frameworks… they were building with simple, composable patterns. Find the simplest solution possible, and only increase complexity when needed… add complexity only when it demonstrably improves outcomes. — Anthropic, Building Effective Agents

Toh dial ki ek default position hai, aur default hai “code ki taraf.” Model end ki taraf har click aap tab earn karte ho jab dikhaate ho ki wo aisa kuch deta hai jo ek deterministic path nahi de sakta tha. Kisi autonomous agent tak haath badhaane se pehle, do sawaal poochho:

Do-sawaal waala gate 1. Kya main steps predict kar sakta hoon? Agar haan, toh unhe code ki tarah likho — ek workflow.
2. Kya control model ko dena us se demonstrably behtar hai? Agar aap dikha nahi sakte ki haan, toh mat do. Single model call < workflow < autonomous agent — tabhi chadho jab neeche wala rung fail kare.1
capability ↑ · risk ↑ Autonomous agent — model route decide karta hai Workflow — aapka code route decide karta hai Single model call ← start
The complexity ladder. Sabse neeche wale rung par shuru karo; tabhi chadho jab neeche wala provably underperform kare.

Paanch workflow patterns

Dial ke workflow side par jo bhi hai wo in paanch patterns ka composition hai. Inhe ek vocabulary ki tarah seekho: jab koi problem aaye, toh aap shape ko name dena chaahte ho, usse invent nahi karna.1

PATTERN 01

Prompt chaining

Fixed sequential steps; har call pichhle ke output par kaam karta hai, beech mein optional code checks (“gates”) ke saath.

PATTERN 02

Routing

Input classify karo, phir ek specialised path par dispatch karo. Har category ko optimise karne deta hai — aur cheap vs. capable models chunne.

PATTERN 03

Parallelization

Calls ek saath chalao. Sectioning independent subtasks ko split karta hai; voting ek hi task ko kai baar chalata hai confidence ke liye.

PATTERN 04

Orchestrator–workers

Ek lead model task ko runtime par subtasks mein todta hai, workers ko delegate karta hai, aur synthesise karta hai. Tab ke liye jab aap subtasks pehle se list na kar pao.

PATTERN 05

Evaluator–optimizer

Ek generator banata hai; ek alag critic score karke feedback deta hai; achha hone tak loop. Converge karne ke liye clear evaluation criteria chahiye.

Kab haath badhao
Jab task…Iske liye jaao
saaf-saaf fixed, ordered subtasks mein bant jaayePrompt chaining
alag-alag categories mein aaye jo alag handle hoti hainRouting
independent parts ho, ya confidence ke liye kai looks chahiye hoParallelization
aise subtasks chahiye jo shuru hone tak predict na ho sakeinOrchestrator–workers
ek clear quality bar ho aur critique se behtar hoEvaluator–optimizer
Orchestrator–workers vs. ek true agent Ye ek jaise lagte hain — dono runtime par subtasks decide karte hain. Pehchaan: orchestrator–workers ek fixed delegate-then-synthesise structure rakhta hai jise aapka code own karta hai; ek full agent model ko poore loop par open control de deta hai, including kab rukna hai.1

Inme se do, code mein

Routing aur evaluator–optimizer wo do hain jinke liye aap sabse zyada haath badhaoge. Dono structure ko code mein rakhte hain aur model ko leash par — bilkul wahi discipline jise Lesson 1 ne kaha tha “own your control flow”:

Routing — model ek label chunta hai; AAPKA switch dispatch karta hai
route = model(classify_prompt(query)).label    # model sirf ek label return karta hai
handler = {                                     # switch aapka hai, model ka nahi
    "refund":    handle_refund,
    "technical": handle_technical,
    "general":   handle_general,
}[route]
return handler(query)                           # har category ke liye specialised path
Evaluator–optimizer — generate, critique, bar milne tak repeat
draft = model(generate_prompt(task))
for _ in range(MAX_ROUNDS):                     # bounded loop — dekho Lesson 4
    verdict = model(critique_prompt(draft))     # ek doosra call draft ko grade karta hai
    if verdict.passes:
        return draft
    draft = model(revise_prompt(task, draft, verdict.feedback))
return draft                                    # budget ke andar best effort

Agents apni keemat kahaan vasoolte hain

Aap poora dial agent tak tab le jaate ho jab “open-ended problems where it’s difficult or impossible to predict the required number of steps.”1 Wo flexibility cost, latency, aur galtiyon ke liye ek zyada bade blast radius se khareedi jaati hai — aur isiliye baad ke levers (context, budgets, error recovery) hain: wahi guard-rails hain jo dial ke agent end ko use karne layak safe banaate hain.

Aaj ki aapki win

Ek task diya jaaye, ab aap (1) “agent banao” par default karne ki bajaye do-sawaal waale gate se dial set kar sakte ho, aur (2) name de sakte ho ki paanch patterns mein se kaun fit hota hai — chaining, routing, parallelization, orchestrator–workers, evaluator–optimizer — aur bata sakte ho kyun. Yeh Lever 01 ki core design skill hai.

Recall check

Retrieve karo, dobara mat padho. Har scenario ko memory se uske pattern par map karo.

Primary source — yeh aage padho

Anthropic — Building Effective Agents. “Workflows” section dobara padho: paanch mein se har pattern ka ek diagram aur ek worked example hai. ~15 minute. Dhyaan do ki har example structure ko code mein aur model ko leash par kaise rakhta hai.

Main aapka teacher hoon — use karo. Apne kisi agent ka ek real decision point mere paas lao aur hum saath mein dial set karenge: yeh ek workflow hai ya model ko sach mein control chahiye? Chaahte ho main aapke TradingAgents pipeline ke stages ko in paanch patterns mein classify kar doon? Bas chat mein poochho.
Lesson 1: The Map 📖 Glossary (English) Aage → Lesson 3: The Context lever

Sources

  1. Anthropic — Building Effective Agents. Workflow vs. agent; the five patterns and when to use each; “add complexity only when it demonstrably improves outcomes.”
  2. HumanLayer — 12-Factor Agents. Factor 8: own your control flow — most of a reliable agent is ordinary code with the model at key points.