YUNOVA · AI Agents
Module 2: Tools and function calling
What function calling is
Key points
- Function calling में model खुद function नहीं चलाता; वह बताता है कि कौन-सा function किन arguments के साथ चलाना है।
- यह जवाब structured रूप (आमतौर पर JSON) में आता है, जिसे आपका code पढ़कर असली function चलाता है।
- इससे model को ताज़ा data, calculation या बाहरी systems तक पहुँच मिलती है जो उसकी training में नहीं थे।
Describing a tool to the model
Key points
- हर tool के लिए model को तीन चीज़ें दी जाती हैं: name, description और parameters का schema (आमतौर पर JSON Schema)।
- Description साफ़ लिखें कि tool क्या करता है और कब इस्तेमाल करना है; model इसी को पढ़कर tool चुनता है।
- हर parameter का type, मतलब और required है या नहीं, यह बताएँ ताकि model सही arguments भरे।
- मिलते-जुलते नाम या धुँधले descriptions से model गलत tool चुन सकता है।
- MCP (Model Context Protocol) एक open standard है जिसे Anthropic ने AI applications को tools और data से जोड़ने के लिए शुरू किया।
- इसमें MCP server tools, resources और prompts देता है, और MCP client (AI app) उनसे जुड़ता है।
- एक बार बना MCP server कई AI apps में इस्तेमाल हो सकता है; हर app के लिए अलग integration नहीं लिखना पड़ता।
- सिर्फ़ भरोसेमंद MCP servers जोड़ें, क्योंकि वे agent को असली systems पर काम करने की पहुँच देते हैं।
Reading the model's tool call and running it
Key points
- Model के response में tool call का नाम और arguments आते हैं; आपका code इन्हें पढ़ता है।
- Arguments को चलाने से पहले validate करें: type सही है या नहीं, ज़रूरी fields हैं या नहीं।
- नाम के आधार पर सही function चलाएँ और error आने पर उसे पकड़ें, ताकि पूरा agent न रुके।
Returning the result to the model
Key points
- Tool चलाने के बाद उसका result बातचीत में वापस model को भेजा जाता है, उसी tool call से जोड़कर।
- Model इस result को पढ़कर या तो अंतिम जवाब देता है या अगला tool call माँगता है।
- Error हो तो भी साफ़ error message लौटाएँ, ताकि model समझ सके और दूसरा रास्ता अपना सके।
- बहुत बड़ा result छोटा करके भेजें, ताकि context ज़रूरत से ज़्यादा न भरे।
Web search, calculators and APIs as tools
Key points
- Web search tool agent को ताज़ा जानकारी देता है जो model की training के बाद की हो सकती है।
- Calculator tool गणित सही करवाता है, क्योंकि language models बड़ी calculations में गलती कर सकते हैं।
- कोई भी API, जैसे मौसम, database या CRM, एक function के रूप में लपेटकर tool बनाई जा सकती है।
- Search results गलत या पुराने भी हो सकते हैं, इसलिए source देखना ज़रूरी है।