नमस्ते दोस्तों!
स्वागत है The Easy Master पर!
Series का आख़िरी post! अब तक AI एक सवाल पर एक-दो काम करता था। आज हम बनाएंगे एक agent – जिसे एक बड़ा काम दो, और वो ख़ुद तय करे कि कौन सी जानकारी चाहिए, tools चलाए, और काम पूरा होने पर ही रुके।
और फिर वो सवाल जो ज़्यादातर tutorials छोड़ देते हैं: "Kaise pata ki agent har baar sahi kaam karta hai?" जवाब है evals। आज आप एक असली bug पकड़ते और ठीक करते देखेंगे।
Is AI agent in Hindi post mein aap seekhenge:
✅ Agent kya hai – एक loop, बस
✅ MAX_STEPS – agent को अटकने से रोकना
✅ Project: study planner agent
✅ Evals – code से जाँचना कि जवाब सही है
✅ Ek asli bug – पकड़ना, ठीक करना, साबित करना
1. Agent = Loop
Part 9 का tool calling code याद है? उसमें while (reply.tool_calls) था। Agent बस यही है – एक loop जो तब तक चलता है जब तक AI tools माँगता रहे, बस:
- AI को बड़ा काम दिया जाता है, एक सवाल नहीं
- AI कई steps में अलग-अलग tools चलवाता है
- एक limit होती है ताकि agent हमेशा के लिए न चलता रहे
2. Study Planner Agent
काम: "Mere bache hue topics ke liye exam tak ka study plan bana do।" इसके लिए agent को तीन बातें पता करनी होंगी – syllabus क्या है, क्या पूरा हो चुका है, और exam में कितने दिन बचे हैं।
यह पहला version है:
const functions = {
getSyllabus: () => data.syllabus,
getCompletedTopics: () => data.done,
getDaysUntilExam: () => { ... },
};चलाया, तो agent ने तीनों tools ख़ुद चलाए:
step 1: getDaysUntilExam() -> {"examDate":"2026-12-15","daysLeft":29}
step 2: getSyllabus() -> ["HTML/CSS","JavaScript","React","Node.js","MongoDB","Final project"]
step 3: getCompletedTopics() -> ["HTML/CSS","JavaScript"]बहुत अच्छा! लेकिन plan देखिए:
### Week 1
- **Monday**: HTML/CSS
- **Tuesday**: HTML/CSS
- **Wednesday**: JavaScript
...HTML/CSS और JavaScript तो पूरे हो चुके थे! Agent को data मिला, फिर भी उसने हिसाब ग़लत लगाया। ऐसी ग़लती हाथ से check करने पर miss हो जाती है – plan देखने में बढ़िया लगता है।
3. Evals – Code Se Jaanchna
Eval मतलब: AI के जवाब पर code से checks चलाना, कई बार। Normal tests की तरह (जैसे Express API Testing – Supertest) – बस AI हर बार थोड़ा अलग जवाब दे सकता है, इसलिए एक ही test कई बार चलाते हैं।
हमारे plan के लिए तीन नियम, जो code से जाँचे जा सकते हैं:
// evals.js — agent ka jawab har baar sahi hai ya nahi, code se check karo
import { runAgent } from './agent.js';
const DONE = ['HTML/CSS', 'JavaScript'];
const LEFT = ['React', 'Node.js', 'MongoDB', 'Final project'];
const RUNS = 3; // AI har baar alag jawab de sakta hai, isliye kai baar chalao
const checks = [
{ name: 'bache hue saare topics plan mein hain', test: (plan) => LEFT.every((t) => plan.toLowerCase().includes(t.toLowerCase())) },
{ name: 'pure ho chuke topics plan mein NAHI hain', test: (plan) => DONE.every((t) => !plan.includes(t)) },
{ name: 'exam date ke baad ka koi hafta nahi (max 5 weeks)', test: (plan) => !/weeks*6|haftas*6/i.test(plan) },
];
let passed = 0, total = 0;
for (let run = 1; run <= RUNS; run++) {
const plan = await runAgent('Mere bache hue topics ke liye exam tak ka study plan bana do.');
for (const c of checks) {
const ok = c.test(plan);
total++; if (ok) passed++;
console.log(`run ${run} ${ok ? 'PASS' : 'FAIL'} ${c.name}`);
}
}
console.log(`nScore: ${passed}/${total}`);पहले version पर:
run 1 PASS bache hue saare topics plan mein hain
run 1 FAIL pure ho chuke topics plan mein NAHI hain
run 1 PASS exam date ke baad ka koi hafta nahi (max 5 weeks)
run 2 PASS bache hue saare topics plan mein hain
run 2 FAIL pure ho chuke topics plan mein NAHI hain
...
Score: 6/9तीनों बार वही ग़लती। अब यह "शायद" नहीं – साबित है।
4. Fix – Hisaab Code Kare, AI Nahi
"Syllabus में से पूरे हुए topics हटाओ" – यह हिसाब है, और हिसाब code AI से बेहतर करता है। तो दो tools की जगह एक tool दिया जो सीधे बचे हुए topics दे:
getRemainingTopics: () => data.syllabus.filter((t) => !data.done.includes(t)),और system prompt में जोड़ा: "Plan only the remaining topics"। यह रहा पूरा agent:
// agent.js — ek chhota agent: study plan banane ke liye khud data dhoondta hai
const MODEL = 'qwen2.5:7b';
const MAX_STEPS = 6; // agent kabhi atak jaye toh bhi ruk jaye
// Asli app mein yeh database / APIs se aayega
const data = {
syllabus: ['HTML/CSS', 'JavaScript', 'React', 'Node.js', 'MongoDB', 'Final project'],
done: ['HTML/CSS', 'JavaScript'],
examDate: new Date(Date.now() + 29 * 86400000).toISOString().slice(0, 10), // aaj se 29 din baad
};
const functions = {
// Hisaab code karega, AI nahi: bache hue topics yahin nikal do
getRemainingTopics: () => data.syllabus.filter((t) => !data.done.includes(t)),
getDaysUntilExam: () => {
const days = Math.ceil((new Date(data.examDate) - new Date()) / 86400000);
return { examDate: data.examDate, daysLeft: days };
},
};
const tool = (name, description) => ({
type: 'function',
function: { name, description, parameters: { type: 'object', properties: {} } },
});
const tools = [
tool('getRemainingTopics', 'Woh topics jo student ko abhi padhne hain, order mein'),
tool('getDaysUntilExam', 'Exam ki date aur kitne din bache hain'),
];
async function chat(messages) {
const res = await fetch('http://localhost:11434/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ model: MODEL, messages, tools, stream: false, options: { temperature: 0 } }),
});
return (await res.json()).message;
}
export async function runAgent(task) {
const messages = [
{ role: 'system', content: 'You are a study planner. Before planning, get every fact you need from the tools; never make up data. Plan only the remaining topics, and fit the plan before the exam date. Write the final plan week by week, in Hinglish.' },
{ role: 'user', content: task },
];
for (let step = 1; step <= MAX_STEPS; step++) {
const reply = await chat(messages);
messages.push(reply);
if (!reply.tool_calls?.length) return reply.content; // kaam pura: final jawab
for (const call of reply.tool_calls) {
const result = functions[call.function.name]();
if (process.env.VERBOSE) console.log(` step ${step}: ${call.function.name}() ->`, JSON.stringify(result));
messages.push({ role: 'tool', tool_name: call.function.name, content: JSON.stringify(result) });
}
}
return 'Agent ne bahut zyada steps le liye, ruk gaya.';
}
// seedha chalane par (node agent.js) hi chale; evals.js import karega
if (import.meta.url === `file://${process.argv[1]}`) {
console.log(await runAgent('Mere bache hue topics ke liye exam tak ka study plan bana do.'));
}वही evals दोबारा:
run 1 PASS bache hue saare topics plan mein hain
run 1 PASS pure ho chuke topics plan mein NAHI hain
run 1 PASS exam date ke baad ka koi hafta nahi (max 5 weeks)
...
Score: 9/96/9 से 9/9। और अब agent ने दोनों tools एक ही step में माँगे – काम भी तेज़ हुआ:
step 1: getDaysUntilExam() -> {"examDate":"2026-12-15","daysLeft":29}
step 1: getRemainingTopics() -> ["React","Node.js","MongoDB","Final project"]VERBOSE=1 node agent.js से आप steps ख़ुद देख सकते हैं।
5. Agent Ke Teen Suraksha Niyam
- MAX_STEPS – हमारा agent 6 steps के बाद रुक जाएगा। बिना limit के, ग़लती में फँसा agent हमेशा चलता रहेगा – और hosted API पर हर step का पैसा लगता है।
- "Never make up data" – system prompt में साफ़ लिखा कि data tools से ही लेना है।
- Hisaab code mein – जो काम code पक्का कर सकता है (filter, गिनती, तारीख़ का फ़र्क), वो AI को मत दीजिए।
6. Agent Kab Banayein, Kab Nahi?
Agent powerful है, लेकिन महंगा, धीमा, और कम predictable भी:
| Kaam | Sahi tarika |
|---|---|
| Ek sawal ka jawab | सीधी AI call (Part 2-3) |
| Apne documents se jawab | RAG (Part 7-8) |
| Ek kaam, pata hai kaunsa tool | Tool calling (Part 9) |
| Bada kaam, steps pehle se pata nahi | Agent |
Niyam: सबसे simple तरीका जो काम करे, वही चुनिए। Agent तभी जब सच में ज़रूरत हो।
बड़े agents – जिनमें कई agents मिलकर काम करें – के लिए LangGraph जैसे frameworks हैं। आपने loop ख़ुद लिखकर देखा है, तो अब वो frameworks आसानी से समझ आएंगे: FastAPI Multi-Agent AI – LangGraph।
7. Achhe Evals Kaise Likhein
- Asli sawal – users जो सच में पूछते हैं, वही test cases
- Code se check hone wale niyam – "topic X plan में है?", "जवाब में source number है?", "JSON valid है?"
- Kai baar chalaiye – एक बार pass होना काफ़ी नहीं
- Har badlaav ke baad – prompt, model या code बदला? Evals चलाइए। Part 10 में prompt बदलने से AI ने tools use करना बंद कर दिया था – eval होता तो तुरंत पकड़ा जाता।
- Check bhi galat ho sakta hai – जैसे plan कहे "HTML/CSS aap kar chuke ho", तो हमारा दूसरा check उसे भी fail कर देगा। Checks को भी समय-समय पर पढ़िए।
8. Series Ka Final Project – Aapki Baari
अब आपके पास सब कुछ है। इन्हें जोड़कर एक "Ask My Notes" bot बनाइए:
- Part 8 का index – अपने college notes या किसी library के docs से
- Part 5 का Express + streaming web page
- Part 3 के prompt नियम – sources के साथ जवाब
- इस post के evals – 10 असली सवाल, हर बदलाव पर चलाइए
- Frontend React में चाहिए? React API Integration – Fetch और Axios
- Online डालना है? Docker से Node.js App Deploy
इसे GitHub पर डालिए, README में बताइए कि क्या बनाया और evals का score क्या है। Interview में यह "मैंने ChatGPT use किया" से कहीं ज़्यादा बोलता है – internship के लिए इसे कैसे दिखाएं, AI से Internship कैसे पाएं में बताया है।
📌 Cheat sheets: इस post की theory – AI Agents & MCP Cheat Sheet। Series का सारा code एक जगह – AI Engineering Code Cheat Sheet।
Conclusion
Agent = tools के साथ एक loop, और एक limit। Evals = AI के जवाब पर code के checks, कई बार। आज आपने एक agent बनाया, evals से उसकी ग़लती पकड़ी, उसे ठीक किया, और 9/9 से साबित किया – यही असली AI Engineering है।
Poori series ek nazar mein: पहली API call → prompts → tokens → streaming → embeddings → RAG → RAG part 2 → tool calling → MCP → agents और evals।
Kuch banaya? Comments में GitHub link share कीजिए! 🚀
Views: 1