Lesson 71 — Beginner

Agent Reliability, UX & Failure Recovery

Agents fail honge — galat tool, galat arguments, tool hi unavailable, repeat hota action, infinite loop. Asli sawaal yeh hai ki failure kaise aaye: predictable budget ke andar, ya bina kisi guard ke. Is lesson mein budgets, idempotency, persistence, fallbacks/escalation aur user ko informed rakhne wale UX patterns cover honge.

⏱ 20 min• Beginner• Sandboxed Execution for AI Agents

Common agent failures

WHAT

Failures ke standard patterns hain: galat tool selection, galat arguments, unavailable tool, repeated actions, incomplete plan, infinite loop aur context growth. Har ek ka apna guard hai.

WHEN

Har run mein kuch na kuch hota hi hai — production ka sawaal failure rokna nahi, failure ko chhota, visible aur recoverable banana hai.

WHERE

Tool selection logs, budget guards, idempotency keys, state persistence, escalation queue aur progress events — yeh sab reliability ka nirmaan hai.

Yaad rakho: Har failure type ka apna instrument chahiye. Ek hi "try-catch" sab jagah lagana reliability nahi — visibility aur recovery chahiye.

Budgets — steps, time, retries, cost

class BudgetExceeded(Exception):
    pass

class Budget:
    def __init__(self, max_steps=10, max_minutes=120,
                 max_retries=2, max_tokens=200000):
        self.steps = 0
        self.retries = 0
        self.spent = 0
        self.limits = {"steps": max_steps, "minutes": max_minutes,
                       "retries": max_retries, "tokens": max_tokens}

    def step(self):
        self.steps += 1
        if self.steps > self.limits["steps"]:
            raise BudgetExceeded("max steps hit — stop karo, user ko batao")

    def charge(self, n):
        self.spent += n
        if self.spent > self.limits["tokens"]:
            raise BudgetExceeded("token budget khatam — resume plan banao")

# budget.step() loop ke andar har turn, budget.charge() har model call par
Rule of thumb: Har agent run ek budget ke andar chale. Budget chhoda matlab wo ghanton chalega, tokens khaayega, aur kisi ko pata bhi nahi chalega.

Idempotency aur persistence

def place_order(cart_id, idem_key):
    existing = idem_store.get(idem_key)   # pehle hi ho chuka?
    if existing:
        return existing                    # dobara side effect mat karo
    result = payments.charge(cart_id)
    idem_store.put(idem_key, result)       # aage kabhi retry ho toh safe
    return result

# idem_key = order_id + action ka stable hash
# retry tab safe hai jab operation idempotent ho — nahi toh refund dobara!

Retries se pehle socho: kya dobara chalana safe hai? Read-only — hamesha safe. Refund/send/delete — idempotency key ke bina kabhi nahi. Yahi hai "idempotent operations" ka asli matlab.

Fallbacks aur human escalation

def escalate(reason, thread_id, attempted, suggestion):
    queue.push({
        "reason": reason,                    # kyun ruke
        "transcript_ref": thread_id,         # kahan tak pahuncha
        "attempted": attempted,              # kya-kya try kiya
        "suggested_action": suggestion,      # aage kya kar sakte ho
        "state_snapshot": save_state(),      # resume ke liye
    })
    return "Ek specialist jaldi se humari taraf — progress save hai."
Yaad rakho: Escalation wohi jagah hai jahan agent ki limitations honesty se dikhti hain. Ache payload ke saath human 2 minute mein pick kar leta hai — bura payload ghanta lagata hai.

Progress, control aur understandable execution

UX rule: User ko hamesha pata hona chahiye: abhi kya ho raha hai, agla kya hoga, aur kya wo rok/sakti hai. Yeh teen sawaal har agent UI ke bottom par hone chahiye.

Exercise

Question: Retries ko safe banane ke liye har real-world operation ko kya banana padta hai? (ek shabd, English)

Question: Steps, minutes, retries aur tokens — ye sab kis cheez ke examples hain? (ek shabd)

Question: Agent jab safely continue na kar sake toh kise escalate karna chahiye? (ek shabd)

Question: Crash ke baad run ko wahi jagah se chalane ke liye state ko kya karna padta hai? (persist / save, ek shabd)

Common mistakes

Desi example: Cab ride ke controls

Production agent cab ride jaisa hai: driver ko max distance pata hai (budget), alternate route ready hai (fallback), live location dikhti hai (progress), aur cancel button tumhare paas hai (control):

text
budget:     max distance / max fare — uske baad ride rukti hai
fallback:   road band -> alternate route ya pickup point shift
progress:   live location + ETA + driver ka naam (tool calls dikhao)
control:    cancel / change destination / share trip (cancel, redirect)
Interview angle — yahan se sawaal aate hain
  • Q: Ek agent ke liye chaar tarah ke budgets batao — har ek ka example ke saath.
  • Q: Idempotency key order placement ke liye kaise design karoge — aur kyun?
  • Q: Human escalation ke payload mein kya hona chahiye — list banao.
  • Q: Agent UX mein user ko kab kya dikhana chahiye — progress vs approval vs result?
Lesson complete?

Reliability ke guards lag gaye. Agla lesson — Agent Frameworks & Libraries — mein dekhenge LangGraph, ADK, CrewAI aur lightweight SDKs mein farak aur kaise chunna hai.

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