Lesson 63 — Beginner

What is an AI Agent?

Agent ek aisa LLM system hai jo khud decide karta hai ki agla step kya hoga — tum sirf goal dete ho, raasta model chunta hai. Is lesson mein agent loop, call vs chain vs workflow vs agent ka farak, aur wo decision rule seekhoge jisse pata chalega ki problem ko agent chahiye ya ek simple workflow kaafi hai.

⏱ 10 min• Beginner• Basic computer usage

Agent loop — goal se finish tak

WHAT

Agent ek LLM + tools + loop hai jo goal se shuru hota hai, har turn par decide karta hai, act karta hai, observation dekhta hai, aur jab tak final answer na mile dohrata hai. Decide karne wala code nahi — model khud hota hai.

WHEN

Jab execution path pehle se likha na ja sake — user ka sawaal anjaan ho, data kahin chhupa ho, ya beech mein nayi information raasta badal de. Open-ended multi-step kaam ke liye.

WHERE

Support agents, research agents, coding agents, ops copilots — jagah jahan investigation ka har case alag ho. Simple pipelines mein workflow hi chalti hai.

Loop ka poora cycle ek line mein: goal → decide → act → observe → repeat → finish. Har iteration ek model call hai, har tool call ek action, aur har tool result ek observation jo agle decision ko shape deta hai.

def run_agent(goal, tools, llm):
    messages = [{"role": "user", "content": goal}]
    while True:  # loop chalta rahega jab tak finish na aaye
        reply = llm(messages, tools=tools)
        if not reply.tool_calls:  # action nahi chahiye = jawab final
            return reply.content
        messages.append(reply)    # decide kiya — ab act
        for call in reply.tool_calls:
            result = run_tool(call.name, call.args)
            messages.append(tool_msg(call.id, result))  # observe
Yaad rakho: Agent ka asli farak "kaun decide karta hai agla step" mein hai. Model tools aur observations dekh kar decide kare toh agent, warna tumhara hardcoded sequence hi rahega.

Call vs chain vs workflow vs agent

shaped          | agla step kaun tay karta hai
----------------+-------------------------------------------
call            | koi nahi — ek prompt, ek jawab
chain           | code jo tumne likha (A -> B -> C fixed)
workflow        | code-based branches/rules — path bhi tumhara
agent           | model khud — tools aur observations dekh kar

Ek hi spectrum hai: jitna zyada control tumhare code mein, utna kam model ke paas. Call sabse seedha hai, agent sabse aazaad. Beech ke forms (workflow + ek agent step) hi production mein sabse zyada chalte hain.

Agent ke components

agent = {
  model:        kaun sochta hai (LLM choice)
  instructions: kaise sochna hai (system prompt, rules, tone)
  tools:        kya kar sakta hai (search, db, api, sandbox code)
  state:        kya yaad rakhta hai (history, plan, memory)
  loop:         decide -> act -> observe -> repeat
  stopping:     kab rukna hai (final answer, max steps, budget)
}
Interview question: Q: "Agent ke core components?" A: model, instructions, tools, state/memory, control loop, stopping conditions — che items, seedha yaad rakho.

Kab workflow hi behtar hai

Decision rule: agar agla step tum apne code mein likh sakte ho, toh likh do. Deterministic workflow simpler, sasta aur zyada reliable hota hai — har decide-step ek extra LLM call hai jo latency aur token dono khaata hai.

Rule of thumb: Path ka 90% pehle se pata hai toh workflow lo, usme zaroorat par ek agent step daalo. Path ka 0% pata hai — tabhi pura agent banao.

Exercise

Question: Agent loop mein act karne ke baad aur agle decision se pehle aane wala step ka naam? (ek shabd, English)

Question: Call, chain, workflow aur agent — agent mein agla step kaun decide karta hai? (ek shabd)

Question: Deterministic execution path wale setup ko kya kehte hain? (ek shabd, English)

Question: Agent ke woh do components jo "yaad rakhne" ka kaam karte hain — ek ka naam batao. (state ya memory, ek)

Common mistakes

Desi example: Dhaba ka waiter vs fixed thali

Fixed thali mein menu pehle se tay hai — order aaya, wahi steps follow ho gaye. Wo workflow hai. Par customer bole "pet theek nahi, halka batao" — ab waiter khud decide karta hai kya poochhna hai aur kya laana hai. Wahi agent hai:

text
workflow: order -> fixed menu -> bill
agent:    order -> waiter sochta hai -> poochhta hai
          -> nayi jaankari -> rasta badla -> repeat -> serve
Interview angle — yahan se sawaal aate hain
  • Q: Agent aur workflow ka fundamental farak kya hai? (kaun decide karta hai agla step)
  • Q: Ek agent ke core components enumerate karo — ek-ek line mein explain ke saath.
  • Q: Call vs chain vs workflow vs agent — spectrum ko examples ke saath samjhao.
  • Q: Tumhe ek invoice approval pipeline banani hai — agent kyun ya kyun nahi chunoge?
Lesson complete?

Agent ka loop samajh aa gaya. Agla lesson — ReAct, Planning & Reflection — mein yehi loop haath se likh kar dekhenge aur loop protection lagayenge.

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