Lesson 68 — Beginner

Multi-Agent Architectures

Ek strong agent + tools aksar sabse sahi jawab hota hai — multi-agent sirf tab justify hota hai jab alag hisson ko alag tools, instructions, permissions ya models chahiye. Is lesson mein common patterns (orchestrator→workers, sequential handoffs, parallel specialists, hierarchical), orchestration code, state passing, worker failure handling aur A2A vs MCP ka farak cover honge.

⏱ 30 min• Beginner• Agent Memory Basics

Ek se zyada agents kyun

WHAT

Multi-agent matlab kaam ko decomposition ke hisaab se tod kar alag-alag agents ko dena — har agent ke paas apni instructions, tools, permissions aur focus. Ek coordinator sab ko jodta hai.

WHEN

Jab subtasks ko alag capabilities chahiye — billing wale ko payments API, policy wale ko documents, alag permissions ya alag model ki zarurat ho. Parallelism ya isolation chahiye ho.

WHERE

Research pipelines, support triage, complex code generation — bade tasks jahan "ek agent sab" wali approach context aur instructions dono ko overload kar de.

Pehla sawaal: Kya ek agent, achhe tools aur bade context se kaam chala lega? Zyada tar haan. Decomposition ka burden tabhi uthao jab alag boundary genuinely chahiye.

Common patterns

1. Orchestrator -> workers
   planner ek (task todta hai) -> workers N (specialist agents) -> results merge

2. Sequential handoffs
   agent A (apna step poora) -> B -> C   — pipeline, har agent ek stage

3. Parallel specialists
   goal -> [agent1, agent2, agent3] ek saath -> merge / vote / compare

4. Hierarchical supervisor/worker
   supervisor -> team leads -> workers   — 2+ levels, har level apne scope mein

Pattern chunne ka rule: kaam ki stages fixed hain toh handoff, alag lens chahiye toh parallel, todna khud mushkil hai toh orchestrator, aur scope ke levels alag hain toh hierarchy. Ek hi system mein do bhi mil sakte hain — orchestrator ke workers parallel chalein.

Yaad rakho: Har pattern ka apna kharcha hai — handoff mein context hand-to-hand transfer, parallel mein merge logic, hierarchy mein coordination layers. Shuruaat sabse simple (orchestrator + workers) se karo.

Orchestrator banana — decompose aur delegate

import asyncio

SPECIALISTS = {
    "billing": billing_agent,
    "shipping": shipping_agent,
    "policy": policy_agent,
}

async def orchestrator(task):
    plan = planner.decompose(task)   # [{"role": "billing", "task": "..."}, ...]

    async def run_one(item):
        agent = SPECIALISTS[item["role"]]
        out = await agent.run(item["task"], ctx=shared_slice(task, item))
        return item["role"], out

    pairs = await asyncio.gather(*[run_one(p) for p in plan],
                                 return_exceptions=True)

    results, failures = {}, []
    for item, out in zip(plan, pairs):
        if isinstance(out, Exception):
            failures.append(item)          # worker fail — dekho, chhupo mat
        else:
            results[item[0]] = out[1]
    return synthesizer.merge(task, results, failures)

State passing aur output aggregation

Sabse common design mistake: poora history sab agents ko dena. Worker ko sirf apna subtask + zaroori slice do, wapas aaye sirf result — context growth multi-agent ka silent killer hai (poora budget wahi kha jaati hai).

Budget check: N agents = N × (system prompt + context) + orchestrator overhead. Parallelism latency ghatati hai par total tokens barhte hain — har decomposition par yeh maths karo.

Worker failure, escalation aur A2A vs MCP

MCP  : agent (ya AI app) -> tools / resources    — capability expose karna
A2A  : agent -> agent                            — independently built
                                          agents ko ek doosre se baat karana

MCP se agent duniya se judta hai; A2A se agent doosre agent se.
Dono ek ecosystem mein saath chalte hain — replace nahi karte.
Interview line: MCP connects agents to tools; A2A connects agents to agents. Ek integration ka standard, doosra inter-agent communication ka approach.

Exercise

Question: Jo coordinator task ko decompose karke specialists ko delegate karta hai — uska naam? (ek shabd)

Question: MCP kya connect karta hai — agent to tools, ya agent to agent?

Question: A2A kis cheez ka standard hai? (do shabd)

Question: Ek hi goal ke liye N specialists ko ek saath chalane wale pattern ka naam? (do shabd)

Common mistakes

Desi example: Hospital ka OPD aur emergency

Receptionist (orchestrator) patient ko sahi specialist ke paas bhejta hai — sab kuch khud nahi dekhta. Emergency mein sab ek saath kaam karte hain (parallel), critical case senior doctor (supervisor) dekhte hain:

text
OPD:        patient -> receptionist -> specialist -> report -> doctor merge
parallel:   trauma + scans + bloodwork — ek saath -> treatment plan
escalation: case complex -> senior doctor (insaan wali line) pass on
Interview angle — yahan se sawaal aate hain
  • Q: Orchestrator-workers pattern kab justified hai — aur kab ek agent hi kaafi?
  • Q: Multi-agent system mein state kaise pass karoge bina context blow-up ke?
  • Q: MCP aur A2A ka farak do line mein batao — dono ka use-case ke saath.
  • Q: Multi-agent ke chaar common failures batao, har ek ka ek fix ke saath.
Lesson complete?

Architectures ke patterns clear. Agla lesson — LangGraph — mein graph-style control ek framework mein kaise likhte hain, woh dekhenge.

Popular courses: Data Science Course in Lucknow · AI Course in Lucknow · Python Course in Lucknow · Power BI Course · Data Analytics Course