Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"अच्छे Agents का निर्माण","local":"अचछ-agents-क-नरमण","sections":[{"title":"सर्वश्रेष्ठ एजेंटिक सिस्टम सबसे सरल होते हैं: वर्कफ़्लो को जितना हो सके उतना सरल बनाएं","local":"सरवशरषठ-एजटक-ससटम-सबस-सरल-हत-ह-वरकफल-क-जतन-ह-सक-उतन-सरल-बनए","sections":[],"depth":3},{"title":"LLM इंजन को जानकारी के प्रवाह में सुधार करें","local":"llm-इजन-क-जनकर-क-परवह-म-सधर-कर","sections":[],"depth":3}],"depth":1}"> | |
| <link href="/docs/smolagents/pr_2321/hi/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/entry/start.4c7058f2.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/scheduler.00b97157.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/singletons.6a07976b.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/index.78ea7f15.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/paths.373154d9.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/entry/app.3b65213b.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/preload-helper.05e26143.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/index.a7c1a7a1.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/nodes/0.579dadcd.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/each.e59479a4.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/nodes/11.f900ff68.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.d080d42c.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/CodeBlock.f041f5e5.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/hi/_app/immutable/chunks/DocNotebookDropdown.be7b60e3.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{"title":"अच्छे Agents का निर्माण","local":"अचछ-agents-क-नरमण","sections":[{"title":"सर्वश्रेष्ठ एजेंटिक सिस्टम सबसे सरल होते हैं: वर्कफ़्लो को जितना हो सके उतना सरल बनाएं","local":"सरवशरषठ-एजटक-ससटम-सबस-सरल-हत-ह-वरकफल-क-जतन-ह-सक-उतन-सरल-बनए","sections":[],"depth":3},{"title":"LLM इंजन को जानकारी के प्रवाह में सुधार करें","local":"llm-इजन-क-जनकर-क-परवह-म-सधर-कर","sections":[],"depth":3}],"depth":1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg></button></div> </div> <div class="flex space-x-1 " style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"> <div class="relative colab-dropdown "> <button class=" " type="button"> <img alt="Open In Colab" class="!m-0" src="https://colab.research.google.com/assets/colab-badge.svg"> </button> </div> <div class="relative colab-dropdown "> <button class=" " type="button"> <img alt="Open In Studio Lab" class="!m-0" src="https://studiolab.sagemaker.aws/studiolab.svg"> </button> </div></div> <h1 class="relative group"><a id="अचछ-agents-क-नरमण" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#अचछ-agents-क-नरमण"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>अच्छे Agents का निर्माण</span></h1> <p data-svelte-h="svelte-1o8lw50">एक ऐसा एजेंट बनाने में जो काम करता है और जो काम नहीं करता है, इसमें ज़मीन-आसमान का अंतर है। | |
| हम कैसे ऐसे एजेंट्स बना सकते हैं जो बाद वाली श्रेणी में आते हैं? | |
| इस गाइड में, हम एजेंट्स बनाने के लिए सर्वोत्तम प्रक्रियाएँ के बारे में बात करेंगे।</p> <blockquote class="tip" data-svelte-h="svelte-1qkef8g"><p>यदि आप एजेंट्स बनाने में नए हैं, तो पहले <a href="../conceptual_guides/intro_agents">एजेंट्स का परिचय</a> और <a href="../guided_tour">smolagents की गाइडेड टूर</a> पढ़ना सुनिश्चित करें।</p></blockquote> <h3 class="relative group"><a id="सरवशरषठ-एजटक-ससटम-सबस-सरल-हत-ह-वरकफल-क-जतन-ह-सक-उतन-सरल-बनए" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#सरवशरषठ-एजटक-ससटम-सबस-सरल-हत-ह-वरकफल-क-जतन-ह-सक-उतन-सरल-बनए"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>सर्वश्रेष्ठ एजेंटिक सिस्टम सबसे सरल होते हैं: वर्कफ़्लो को जितना हो सके उतना सरल बनाएं</span></h3> <p data-svelte-h="svelte-177orsq">अपने वर्कफ़्लो में एक LLM को कुछ एजेंसी देने से त्रुटियों का जोखिम होता है।</p> <p data-svelte-h="svelte-kax6zy">अच्छी तरह से प्रोग्राम किए गए एजेंटिक सिस्टम में वैसे भी अच्छी एरर लॉगिंग और रीट्राई मैकेनिज्म होते हैं, जिससे LLM इंजन अपनी गलतियों को सुधारने का मौका मिलता है। लेकिन LLM त्रुटि के जोखिम को अधिकतम कम करने के लिए, आपको अपना वर्कफ़्लो सरल बनाना चाहिए!</p> <p data-svelte-h="svelte-t67zje">आइए <a href="../conceptual_guides/intro_agents">एजेंट्स का परिचय</a> से उदाहरण पर फिर से विचार करें: एक सर्फ ट्रिप कंपनी के लिए उपयोगकर्ता प्रश्नों का उत्तर देने वाला बॉट। | |
| एजेंट को हर बार जब एक नए सर्फ स्पॉट के बारे में पूछा जाता है तो “travel distance API” और “weather API” के लिए 2 अलग-अलग कॉल करने देने के बजाय, आप केवल एक एकीकृत टूल “return_spot_information” बना सकते हैं, एक फंक्शन जो दोनों APIs को एक साथ कॉल करता है और उनके संयोजित आउटपुट को उपयोगकर्ता को वापस करता है।</p> <p data-svelte-h="svelte-2iut2j">यह लागत, देरी और त्रुटि जोखिम को कम करेगा!</p> <p data-svelte-h="svelte-1a48b8q">मुख्य दिशानिर्देश है: LLM कॉल्स की संख्या को जितना हो सके उतना कम करें।</p> <p data-svelte-h="svelte-11htjar">इससे कुछ निष्कर्ष निकलते हैं:</p> <ul data-svelte-h="svelte-jyuw55"><li>जब भी संभव हो, दो APIs के हमारे उदाहरण की तरह 2 टूल्स को एक में समूहित करें।</li> <li>जब भी संभव हो, लॉजिक एजेंटिक निर्णयों के बजाय डिटरमिनिस्टिक फंक्शंस पर आधारित होनी चाहिए।</li></ul> <h3 class="relative group"><a id="llm-इजन-क-जनकर-क-परवह-म-सधर-कर" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#llm-इजन-क-जनकर-क-परवह-म-सधर-कर"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>LLM इंजन को जानकारी के प्रवाह में सुधार करें</span></h3> <p data-svelte-h="svelte-8o8rci">याद रखें कि आपका LLM इंजन एक <em>बुद्धिमान</em> रोबोट की तरह है, जो एक कमरे में बंद है, और बाहरी दुनिया के साथ इसका एकमात्र संचार दरवाजे के नीचे से नोट्स पास करना है।</p> <p data-svelte-h="svelte-t07eax">यह किसी भी ऐसी चीज के बारे में नहीं जानेगा जिसे आप स्पष्ट रूप से अपने प्रॉम्प्ट में नहीं डालते हैं।</p> <p data-svelte-h="svelte-15m6rux">इसलिए पहले अपने कार्य को बहुत स्पष्ट बनाने से शुरू करें! | |
| चूंकि एक एजेंट LLM द्वारा संचालित होता है, आपके कार्य के निर्माण में छोटे बदलाव भी पूरी तरह से अलग परिणाम दे सकते हैं।</p> <p data-svelte-h="svelte-1brjvda">फिर, टूल के उपयोग में अपने एजेंट की ओर जानकारी के प्रवाह में सुधार करें।</p> <p data-svelte-h="svelte-2n3td0">पालन करने के लिए विशेष दिशानिर्देश:</p> <ul data-svelte-h="svelte-2a08dc"><li>प्रत्येक टूल को वह सब कुछ लॉग करना चाहिए (टूल की <code>forward</code> मेथड के अंदर केवल <code>print</code> स्टेटमेंट्स का उपयोग करके) जो LLM इंजन के लिए उपयोगी हो सकता है। | |
| <ul><li>विशेष रूप से, टूल एक्जीक्यूशन गलतियों पर विस्तृत लॉगिंग बहुत मदद करेगी!</li></ul></li></ul> <p data-svelte-h="svelte-19r5v40">उदाहरण के लिए, यहाँ एक टूल है जो लोकेशन और डेट-टाइम के आधार पर मौसम डेटा प्राप्त करता है:</p> <p data-svelte-h="svelte-nd84y2">पहले, यहाँ एक खराब रूप है:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-python "><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> datetime | |
| <span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> tool | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_weather_report_at_coordinates</span>(<span class="hljs-params">coordinates, date_time</span>): | |
| <span class="hljs-comment"># Dummy function, returns a list of [temperature in °C, risk of rain on a scale 0-1, wave height in m]</span> | |
| <span class="hljs-keyword">return</span> [<span class="hljs-number">28.0</span>, <span class="hljs-number">0.35</span>, <span class="hljs-number">0.85</span>] | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">convert_location_to_coordinates</span>(<span class="hljs-params">location</span>): | |
| <span class="hljs-comment"># Returns dummy coordinates</span> | |
| <span class="hljs-keyword">return</span> [<span class="hljs-number">3.3</span>, -<span class="hljs-number">42.0</span>] | |
| <span class="hljs-meta">@tool</span> | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_weather_api</span>(<span class="hljs-params">location: <span class="hljs-built_in">str</span>, date_time: <span class="hljs-built_in">str</span></span>) -> <span class="hljs-built_in">str</span>: | |
| <span class="hljs-string">""" | |
| Returns the weather report. | |
| Args: | |
| location: the name of the place that you want the weather for. | |
| date_time: the date and time for which you want the report. | |
| """</span> | |
| lon, lat = convert_location_to_coordinates(location) | |
| date_time = datetime.strptime(date_time) | |
| <span class="hljs-keyword">return</span> <span class="hljs-built_in">str</span>(get_weather_report_at_coordinates((lon, lat), date_time))<!-- HTML_TAG_END --></pre></div> <h1 class="relative group"><a id="यह-खरब-कय-ह" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#यह-खरब-कय-ह"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>यह खराब क्यों है?</span></h1> <ul data-svelte-h="svelte-1a1bm2n"><li><code>date_time</code> के लिए उपयोग किए जाने वाले फॉर्मेट की सटीकता का कोई उल्लेख नहीं है।</li> <li>यह स्पष्ट नहीं है कि स्थान (location) को किस प्रकार निर्दिष्ट किया जाना चाहिए।</li> <li>त्रुटियों को स्पष्ट रूप से इंगित करने के लिए कोई लॉगिंग मेकैनिज्म मौजूद नहीं है, जैसे कि स्थान गलत फॉर्मेट में होना या <code>date_time</code> का सही ढंग से फॉर्मेट न होना।</li> <li>आउटपुट फॉर्मेट समझने में कठिन है।</li></ul> <p data-svelte-h="svelte-qohr6v">यदि टूल कॉल विफल हो जाती है, तो मेमोरी में लॉग की गई एरर ट्रेस LLM को टूल की समस्याओं को ठीक करने के लिए रिवर्स इंजीनियरिंग में मदद कर सकती है। लेकिन इतना सारा काम LLM को ही क्यों करने देना?</p> <p data-svelte-h="svelte-hqnuk9">इस टूल को बेहतर तरीके से बनाने का एक उदाहरण इस प्रकार हो सकता है:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-python "><!-- HTML_TAG_START --><span class="hljs-meta">@tool</span> | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_weather_api</span>(<span class="hljs-params">location: <span class="hljs-built_in">str</span>, date_time: <span class="hljs-built_in">str</span></span>) -> <span class="hljs-built_in">str</span>: | |
| <span class="hljs-string">""" | |
| Returns the weather report. | |
| Args: | |
| location: the name of the place that you want the weather for. Should be a place name, followed by possibly a city name, then a country, like "Anchor Point, Taghazout, Morocco". | |
| date_time: the date and time for which you want the report, formatted as '%m/%d/%y %H:%M:%S'. | |
| """</span> | |
| lon, lat = convert_location_to_coordinates(location) | |
| <span class="hljs-keyword">try</span>: | |
| date_time = datetime.strptime(date_time) | |
| <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e: | |
| <span class="hljs-keyword">raise</span> ValueError(<span class="hljs-string">"Conversion of `date_time` to datetime format failed, make sure to provide a string in format '%m/%d/%y %H:%M:%S'. Full trace:"</span> + <span class="hljs-built_in">str</span>(e)) | |
| temperature_celsius, risk_of_rain, wave_height = get_weather_report_at_coordinates((lon, lat), date_time) | |
| <span class="hljs-keyword">return</span> <span class="hljs-string">f"Weather report for <span class="hljs-subst">{location}</span>, <span class="hljs-subst">{date_time}</span>: Temperature will be <span class="hljs-subst">{temperature_celsius}</span>°C, risk of rain is <span class="hljs-subst">{risk_of_rain*<span class="hljs-number">100</span>:<span class="hljs-number">.0</span>f}</span>%, wave height is <span class="hljs-subst">{wave_height}</span>m."</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1wb2jbo">सामान्य तौर पर, अपने LLM का बोझ को कम करने के लिए, खुद से यह अच्छा सवाल पूछें: “यदि मैं नया और अनुभवहीन हूं और इस टूल का पहली बार उपयोग कर रहा हूं, तो इस टूल के साथ प्रोग्रामिंग करना और अपनी गलतियों को ठीक करना मेरे लिए कितना आसान होगा?”</p> <h3 class="relative group"><a id="एजट-क-अधक-तरक-arguments-द" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#एजट-क-अधक-तरक-arguments-द"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>एजेंट को अधिक तर्क (arguments) दें</span></h3> <p data-svelte-h="svelte-11a18w6">अपने एजेंट को कार्य का वर्णन करने वाले साधारण स्ट्रिंग से आगे बढ़कर कुछ अतिरिक्त ऑब्जेक्ट्स देने के लिए, आप <code>additional_args</code> का उपयोग कर सकते हैं। यह आपको किसी भी प्रकार का ऑब्जेक्ट पास करने की सुविधा देता है:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-py "><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> CodeAgent, InferenceClientModel | |
| model_id = <span class="hljs-string">"meta-llama/Llama-3.3-70B-Instruct"</span> | |
| agent = CodeAgent(tools=[], model=InferenceClientModel(model_id=model_id), add_base_tools=<span class="hljs-literal">True</span>) | |
| agent.run( | |
| <span class="hljs-string">"Why does Mike not know many people in New York?"</span>, | |
| additional_args={<span class="hljs-string">"mp3_sound_file_url"</span>:<span class="hljs-string">'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/recording.mp3'</span>} | |
| )<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-go2vfj">उदाहरण के लिए, आप इस <code>additional_args</code> आर्ग्यूमेंट का उपयोग उन इमेजेज़ या स्ट्रिंग्स को पास करने के लिए कर सकते हैं जिन्हें आप चाहते हैं कि आपका एजेंट उपयोग करे।</p> <h2 class="relative group"><a id="अपन-एजट-क-डबग-कस-कर" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#अपन-एजट-क-डबग-कस-कर"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>अपने एजेंट को डिबग कैसे करें</span></h2> <h3 class="relative group"><a id="1-एक-अधक-शकतशल-llm-क-उपयग-कर" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#1-एक-अधक-शकतशल-llm-क-उपयग-कर"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>1. एक अधिक शक्तिशाली LLM का उपयोग करें</span></h3> <p data-svelte-h="svelte-jhbaty">एजेंटिक वर्कफ़्लो में, कुछ त्रुटियां वास्तविक होती हैं, जबकि कुछ अन्य त्रुटियां आपके LLM इंजन के सही तरीके से तर्क न कर पाने की वजह से होती हैं।<br> | |
| उदाहरण के लिए, इस ट्रेस को देखें, जहां मैंने एक <code>CodeAgent</code> से एक कार की तस्वीर बनाने के लिए कहा:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=" "><!-- HTML_TAG_START -->==================================================================================================== <span class="hljs-keyword">New</span> <span class="hljs-keyword">task</span> ==================================================================================================== | |
| Make me a cool car picture | |
| ──────────────────────────────────────────────────────────────────────────────────────────────────── <span class="hljs-keyword">New</span> <span class="hljs-keyword">step</span> ──────────────────────────────────────────────────────────────────────────────────────────────────── | |
| Agent is executing the code below: ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── | |
| image_generator(prompt=<span class="hljs-string">"A cool, futuristic sports car with LED headlights, aerodynamic design, and vibrant color, high-res, photorealistic"</span>) | |
| ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── | |
| Last output <span class="hljs-keyword">from</span> code snippet: ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── | |
| <span class="hljs-regexp">/var/</span>folders<span class="hljs-regexp">/6m/</span><span class="hljs-number">9</span>b1tts6d5w960j80wbw9tx3m0000gn<span class="hljs-regexp">/T/</span>tmpx09qfsdd/<span class="hljs-number">652</span>f0007-<span class="hljs-number">3</span>ee9-<span class="hljs-number">44</span>e2-<span class="hljs-number">94</span>ac-<span class="hljs-number">90</span>dae6bb89a4.png | |
| <span class="hljs-keyword">Step</span> <span class="hljs-number">1</span>: | |
| - Time taken: <span class="hljs-number">16.35</span> seconds | |
| - Input tokens: <span class="hljs-number">1</span>,<span class="hljs-number">383</span> | |
| - Output tokens: <span class="hljs-number">77</span> | |
| ──────────────────────────────────────────────────────────────────────────────────────────────────── <span class="hljs-keyword">New</span> <span class="hljs-keyword">step</span> ──────────────────────────────────────────────────────────────────────────────────────────────────── | |
| Agent is executing the code below: ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── | |
| final_answer(<span class="hljs-string">"/var/folders/6m/9b1tts6d5w960j80wbw9tx3m0000gn/T/tmpx09qfsdd/652f0007-3ee9-44e2-94ac-90dae6bb89a4.png"</span>) | |
| ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── | |
| <span class="hljs-keyword">Print</span> outputs: | |
| Last output <span class="hljs-keyword">from</span> code snippet: ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── | |
| <span class="hljs-regexp">/var/</span>folders<span class="hljs-regexp">/6m/</span><span class="hljs-number">9</span>b1tts6d5w960j80wbw9tx3m0000gn<span class="hljs-regexp">/T/</span>tmpx09qfsdd/<span class="hljs-number">652</span>f0007-<span class="hljs-number">3</span>ee9-<span class="hljs-number">44</span>e2-<span class="hljs-number">94</span>ac-<span class="hljs-number">90</span>dae6bb89a4.png | |
| <span class="hljs-keyword">Final</span> answer: | |
| <span class="hljs-regexp">/var/</span>folders<span class="hljs-regexp">/6m/</span><span class="hljs-number">9</span>b1tts6d5w960j80wbw9tx3m0000gn<span class="hljs-regexp">/T/</span>tmpx09qfsdd/<span class="hljs-number">652</span>f0007-<span class="hljs-number">3</span>ee9-<span class="hljs-number">44</span>e2-<span class="hljs-number">94</span>ac-<span class="hljs-number">90</span>dae6bb89a4.png<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-hktzw4">उपयोगकर्ता को, एक इमेज लौटाए जाने के बजाय, उन्हें एक पाथ लौटाया जाता है। | |
| यह सिस्टम से एक बग की तरह दिख सकता है, लेकिन वास्तव में एजेंटिक सिस्टम ने त्रुटि नहीं की: यह केवल इसलिए है कि LLM ब्रेन ने इमेज आउटपुट को एक वेरिएबल में सेव करने की गलती की। | |
| इस प्रकार यह इमेज को फिर से एक्सेस नहीं कर सकता है सिवाय इमेज को सेव करते समय लॉग किए गए पाथ का उपयोग करके, इसलिए यह इमेज के बजाय पाथ लौटाता है।</p> <p data-svelte-h="svelte-1esv8fe">अपने एजेंट को डीबग करने का पहला कदम इस प्रकार है “एक अधिक शक्तिशाली LLM का उपयोग करें”। <code>Qwen2/5-72B-Instruct</code> जैसे विकल्प वह गलती नहीं करते।</p> <h3 class="relative group"><a id="2-अधक-मरगदरशन--अधक-जनकर-परदन-कर" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#2-अधक-मरगदरशन--अधक-जनकर-परदन-कर"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>2. अधिक मार्गदर्शन / अधिक जानकारी प्रदान करें</span></h3> <p data-svelte-h="svelte-1g282fx">आप कम शक्तिशाली मॉडल्स का भी उपयोग कर सकते हैं, बशर्ते आप उन्हें अधिक प्रभावी ढंग से मार्गदर्शन करें।</p> <p data-svelte-h="svelte-rqjg3t">अपने आप को अपने मॉडल की जगह रखें: यदि आप कार्य को हल करने वाला मॉडल होते, तो क्या आप उपलब्ध जानकारी (सिस्टम प्रॉम्प्ट + कार्य निर्माण + टूल विवरण से) के साथ संघर्ष करते?</p> <p data-svelte-h="svelte-2oi4h1">क्या आपको कुछ अतिरिक्त स्पष्टीकरण की आवश्यकता होती?</p> <p data-svelte-h="svelte-168zzx0">अतिरिक्त जानकारी प्रदान करने के लिए, हम तुरंत सिस्टम प्रॉम्प्ट को बदलने की सलाह नहीं देते हैं: डिफ़ॉल्ट सिस्टम प्रॉम्प्ट में कई समायोजन हैं जिन्हें आप तब तक नहीं बिगाड़ना चाहते जब तक आप प्रॉम्प्ट को बहुत अच्छी तरह से नहीं समझते। | |
| अपने LLM इंजन को मार्गदर्शन करने के बेहतर तरीके हैं:</p> <ul data-svelte-h="svelte-12qphxy"><li>यदि यह कार्य को हल करने के बारे में है: इन सभी विवरणों को कार्य में जोड़ें। यह कार्य 100 पेज लंबा हो सकता है</li> <li>यदि यह टूल्स के उपयोग के बारे में है: आपके टूल्स की विवरण विशेषता।</li></ul> <h3 class="relative group"><a id="3-ससटम-परमपट-बदल-आमतर-पर-यह-सलह-नह-द-जत" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#3-ससटम-परमपट-बदल-आमतर-पर-यह-सलह-नह-द-जत"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>3. सिस्टम प्रॉम्प्ट बदलें (आमतौर पर यह सलाह नहीं दी जाती)</span></h3> <p data-svelte-h="svelte-1cdrg1f">यदि उपरोक्त स्पष्टीकरण पर्याप्त नहीं हैं, तो आप सिस्टम प्रॉम्प्ट बदल सकते हैं।</p> <p data-svelte-h="svelte-gjpnlb">आइए देखें कि यह कैसे काम करता है। उदाहरण के लिए, आइए <a href="/docs/smolagents/pr_2321/hi/reference/agents#smolagents.CodeAgent">CodeAgent</a> के लिए डिफ़ॉल्ट सिस्टम प्रॉम्प्ट की जाँच करें (नीचे दिया गया वर्जन जीरो-शॉट उदाहरणों को छोड़कर छोटा किया गया है)।</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-python "><!-- HTML_TAG_START --><span class="hljs-built_in">print</span>(agent.prompt_templates[<span class="hljs-string">"system_prompt"</span>])<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-174l3zr">Here is what you get:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-text "><!-- HTML_TAG_START -->You are an expert assistant who can solve any task using code blobs. You will be given a task to solve as best you can. | |
| To do so, you have been given access to a list of tools: these tools are basically Python functions which you can call with code. | |
| To solve the task, you must plan forward to proceed in a series of steps, in a cycle of 'Thought:', 'Code:', and 'Observation:' sequences. | |
| At each step, in the 'Thought:' sequence, you should first explain your reasoning towards solving the task and the tools that you want to use. | |
| Then in the 'Code:' sequence, you should write the code in simple Python. The code sequence must end with '<end_code>' sequence. | |
| During each intermediate step, you can use 'print()' to save whatever important information you will then need. | |
| These print outputs will then appear in the 'Observation:' field, which will be available as input for the next step. | |
| In the end you have to return a final answer using the `final_answer` tool. | |
| Here are a few examples using notional tools: | |
| --- | |
| Task: "Generate an image of the oldest person in this document." | |
| Thought: I will proceed step by step and use the following tools: `document_qa` to find the oldest person in the document, then `image_generator` to generate an image according to the answer. | |
| Code: | |
| ```py | |
| answer = document_qa(document=document, question="Who is the oldest person mentioned?") | |
| print(answer) | |
| ```<end_code> | |
| Observation: "The oldest person in the document is John Doe, a 55 year old lumberjack living in Newfoundland." | |
| Thought: I will now generate an image showcasing the oldest person. | |
| Code: | |
| ```py | |
| image = image_generator("A portrait of John Doe, a 55-year-old man living in Canada.") | |
| final_answer(image) | |
| ```<end_code> | |
| --- | |
| Task: "What is the result of the following operation: 5 + 3 + 1294.678?" | |
| Thought: I will use python code to compute the result of the operation and then return the final answer using the `final_answer` tool | |
| Code: | |
| ```py | |
| result = 5 + 3 + 1294.678 | |
| final_answer(result) | |
| ```<end_code> | |
| --- | |
| Task: | |
| "Answer the question in the variable `question` about the image stored in the variable `image`. The question is in French. | |
| You have been provided with these additional arguments, that you can access using the keys as variables in your python code: | |
| {'question': 'Quel est l'animal sur l'image?', 'image': 'path/to/image.jpg'}" | |
| Thought: I will use the following tools: `translator` to translate the question into English and then `image_qa` to answer the question on the input image. | |
| Code: | |
| ```py | |
| translated_question = translator(question=question, src_lang="French", tgt_lang="English") | |
| print(f"The translated question is {translated_question}.") | |
| answer = image_qa(image=image, question=translated_question) | |
| final_answer(f"The answer is {answer}") | |
| ```<end_code> | |
| --- | |
| Task: | |
| In a 1979 interview, Stanislaus Ulam discusses with Martin Sherwin about other great physicists of his time, including Oppenheimer. | |
| What does he say was the consequence of Einstein learning too much math on his creativity, in one word? | |
| Thought: I need to find and read the 1979 interview of Stanislaus Ulam with Martin Sherwin. | |
| Code: | |
| ```py | |
| pages = search(query="1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein") | |
| print(pages) | |
| ```<end_code> | |
| Observation: | |
| No result found for query "1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein". | |
| Thought: The query was maybe too restrictive and did not find any results. Let's try again with a broader query. | |
| Code: | |
| ```py | |
| pages = search(query="1979 interview Stanislaus Ulam") | |
| print(pages) | |
| ```<end_code> | |
| Observation: | |
| Found 6 pages: | |
| [Stanislaus Ulam 1979 interview](https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/) | |
| [Ulam discusses Manhattan Project](https://ahf.nuclearmuseum.org/manhattan-project/ulam-manhattan-project/) | |
| (truncated) | |
| Thought: I will read the first 2 pages to know more. | |
| Code: | |
| ```py | |
| for url in ["https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/", "https://ahf.nuclearmuseum.org/manhattan-project/ulam-manhattan-project/"]: | |
| whole_page = visit_webpage(url) | |
| print(whole_page) | |
| print("\n" + "="*80 + "\n") # Print separator between pages | |
| ```<end_code> | |
| Observation: | |
| Manhattan Project Locations: | |
| Los Alamos, NM | |
| Stanislaus Ulam was a Polish-American mathematician. He worked on the Manhattan Project at Los Alamos and later helped design the hydrogen bomb. In this interview, he discusses his work at | |
| (truncated) | |
| Thought: I now have the final answer: from the webpages visited, Stanislaus Ulam says of Einstein: "He learned too much mathematics and sort of diminished, it seems to me personally, it seems to me his purely physics creativity." Let's answer in one word. | |
| Code: | |
| ```py | |
| final_answer("diminished") | |
| ```<end_code> | |
| --- | |
| Task: "Which city has the highest population: Guangzhou or Shanghai?" | |
| Thought: I need to get the populations for both cities and compare them: I will use the tool `search` to get the population of both cities. | |
| Code: | |
| ```py | |
| for city in ["Guangzhou", "Shanghai"]: | |
| print(f"Population {city}:", search(f"{city} population") | |
| ```<end_code> | |
| Observation: | |
| Population Guangzhou: ['Guangzhou has a population of 15 million inhabitants as of 2021.'] | |
| Population Shanghai: '26 million (2019)' | |
| Thought: Now I know that Shanghai has the highest population. | |
| Code: | |
| ```py | |
| final_answer("Shanghai") | |
| ```<end_code> | |
| --- | |
| Task: "What is the current age of the pope, raised to the power 0.36?" | |
| Thought: I will use the tool `wiki` to get the age of the pope, and confirm that with a web search. | |
| Code: | |
| ```py | |
| pope_age_wiki = wiki(query="current pope age") | |
| print("Pope age as per wikipedia:", pope_age_wiki) | |
| pope_age_search = web_search(query="current pope age") | |
| print("Pope age as per google search:", pope_age_search) | |
| ```<end_code> | |
| Observation: | |
| Pope age: "The pope Francis is currently 88 years old." | |
| Thought: I know that the pope is 88 years old. Let's compute the result using python code. | |
| Code: | |
| ```py | |
| pope_current_age = 88 ** 0.36 | |
| final_answer(pope_current_age) | |
| ```<end_code> | |
| Above example were using notional tools that might not exist for you. On top of performing computations in the Python code snippets that you create, you only have access to these tools: | |
| {%- for tool in tools.values() %} | |
| - {{ tool.to_tool_calling_prompt() }} | |
| {%- endfor %} | |
| {%- if managed_agents and managed_agents.values() | list %} | |
| You can also give tasks to team members. | |
| Calling a team member works similarly to calling a tool: provide the task description as the 'task' argument. Since this team member is a real human, be as detailed and verbose as necessary in your task description. | |
| You can also include any relevant variables or context using the 'additional_args' argument. | |
| Here is a list of the team members that you can call: | |
| {%- for agent in managed_agents.values() %} | |
| - {{ agent.name }}: {{ agent.description }} | |
| {%- endfor %} | |
| {%- endif %} | |
| Here are the rules you should always follow to solve your task: | |
| 1. Always provide a 'Thought:' sequence, and a 'Code:\n```py' sequence ending with '```<end_code>' sequence, else you will fail. | |
| 2. Use only variables that you have defined! | |
| 3. Always use the right arguments for the tools. DO NOT pass the arguments as a dict as in 'answer = wiki({'query': "What is the place where James Bond lives?"})', but use the arguments directly as in 'answer = wiki(query="What is the place where James Bond lives?")'. | |
| 4. Take care to not chain too many sequential tool calls in the same code block, especially when the output format is unpredictable. For instance, a call to search has an unpredictable return format, so do not have another tool call that depends on its output in the same block: rather output results with print() to use them in the next block. | |
| 5. Call a tool only when needed, and never re-do a tool call that you previously did with the exact same parameters. | |
| 6. Don't name any new variable with the same name as a tool: for instance don't name a variable 'final_answer'. | |
| 7. Never create any notional variables in our code, as having these in your logs will derail you from the true variables. | |
| 8. You can use imports in your code, but only from the following list of modules: {{authorized_imports}} | |
| 9. The state persists between code executions: so if in one step you've created variables or imported modules, these will all persist. | |
| 10. Don't give up! You're in charge of solving the task, not providing directions to solve it. | |
| Now Begin! If you solve the task correctly, you will receive a reward of $1,000,000.<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-zzikjs">जैसा कि आप देख सकते हैं, <code>"{{ tool.description }}"</code> जैसे प्लेसहोल्डर्स हैं: इनका उपयोग एजेंट इनिशियलाइजेशन के समय टूल्स या मैनेज्ड एजेंट्स के कुछ स्वचालित रूप से जनरेट किए गए विवरणों को डालने के लिए किया जाएगा।</p> <p data-svelte-h="svelte-e52uwm">इसलिए जबकि आप <code>system_prompt</code> पैरामीटर में अपने कस्टम प्रॉम्प्ट को आर्गुमेंट के रूप में पास करके इस सिस्टम प्रॉम्प्ट टेम्पलेट को ओवरराइट कर सकते हैं, आपके नए सिस्टम प्रॉम्प्ट में निम्नलिखित प्लेसहोल्डर्स होने चाहिए:</p> <ul><li>टूल विवरण डालने के लिए। | |
| <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=" "><!-- HTML_TAG_START --><span class="hljs-template-tag">{%- <span class="hljs-name"><span class="hljs-name">for</span></span> tool <span class="hljs-keyword">in</span> tools.values() %}</span><span class="language-xml"> | |
| - </span><span class="hljs-template-variable">{{ tool.to_tool_calling_prompt() }}</span><span class="language-xml"> | |
| </span><span class="hljs-template-tag">{%- <span class="hljs-name"><span class="hljs-name">endfor</span></span> %}</span><!-- HTML_TAG_END --></pre></div></li> <li>यदि कोई मैनेज्ड एजेंट्स हैं तो उनके लिए विवरण डालने के लिए। | |
| <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=" "><!-- HTML_TAG_START -->{%- <span class="hljs-keyword">if</span> managed_agents <span class="hljs-built_in">and</span> managed_agents.<span class="hljs-built_in">values</span>() | <span class="hljs-keyword">list</span> %} | |
| You can also give tasks <span class="hljs-keyword">to</span> team members. | |
| Calling <span class="hljs-keyword">a</span> team member works similarly <span class="hljs-keyword">to</span> calling <span class="hljs-keyword">a</span> tool: provide the task description <span class="hljs-keyword">as</span> the <span class="hljs-string">'task'</span> <span class="hljs-keyword">argument</span>. Since this team member <span class="hljs-keyword">is</span> <span class="hljs-keyword">a</span> real human, <span class="hljs-keyword">be</span> <span class="hljs-keyword">as</span> detailed <span class="hljs-built_in">and</span> <span class="hljs-keyword">verbose</span> <span class="hljs-keyword">as</span> necessary in your task description. | |
| You can also include any relevant variables <span class="hljs-built_in">or</span> context using the <span class="hljs-string">'additional_args'</span> <span class="hljs-keyword">argument</span>. | |
| Here <span class="hljs-keyword">is</span> <span class="hljs-keyword">a</span> <span class="hljs-keyword">list</span> of the team members that you can <span class="hljs-keyword">call</span>: | |
| {%- <span class="hljs-keyword">for</span> agent in managed_agents.<span class="hljs-built_in">values</span>() %} | |
| - {{ agent.name }}: {{ agent.description }} | |
| {%- <span class="hljs-keyword">endfor</span> %} | |
| {%- <span class="hljs-keyword">endif</span> %}<!-- HTML_TAG_END --></pre></div></li> <li data-svelte-h="svelte-1ykdced">केवल <code>CodeAgent</code> के लिए: अधिकृत इम्पोर्ट्स की सूची डालने के लिए <code>"{{authorized_imports}}"</code>।</li></ul> <p data-svelte-h="svelte-9jtmts">फिर आप सिस्टम प्रॉम्प्ट को निम्नानुसार बदल सकते हैं:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-py "><!-- HTML_TAG_START -->agent.prompt_templates[<span class="hljs-string">"system_prompt"</span>] = agent.prompt_templates[<span class="hljs-string">"system_prompt"</span>] + <span class="hljs-string">"\nHere you go!"</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-chyd2k">This also works with the <a href="/docs/smolagents/pr_2321/hi/reference/agents#smolagents.ToolCallingAgent">ToolCallingAgent</a>.</p> <h3 class="relative group"><a id="4-अतरकत-यजन" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#4-अतरकत-यजन"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>4. अतिरिक्त योजना</span></h3> <p data-svelte-h="svelte-1fs431j">हम पूरक योजना चरण के लिए एक मॉडल प्रदान करते हैं, जिसे एजेंट सामान्य क्रियाओं के चरणों के बीच नियमित रूप से चला सकता है। इस चरण में कोई टूल कॉल नहीं होती है, LLM से केवल उन तथ्यों की सूची को अपडेट करने के लिए कहा जाता है जो उसे ज्ञात हैं और इन तथ्यों के आधार पर उसे अगले कदमों के बारे में विचार करना होता है।</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-py "><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> load_tool, CodeAgent, InferenceClientModel, WebSearchTool | |
| <span class="hljs-keyword">from</span> dotenv <span class="hljs-keyword">import</span> load_dotenv | |
| load_dotenv() | |
| <span class="hljs-comment"># Import tool from Hub</span> | |
| image_generation_tool = load_tool(<span class="hljs-string">"m-ric/text-to-image"</span>, trust_remote_code=<span class="hljs-literal">True</span>) | |
| search_tool = WebSearchTool() | |
| agent = CodeAgent( | |
| tools=[search_tool], | |
| model=InferenceClientModel(model_id=<span class="hljs-string">"Qwen/Qwen2.5-72B-Instruct"</span>), | |
| planning_interval=<span class="hljs-number">3</span> <span class="hljs-comment"># This is where you activate planning!</span> | |
| ) | |
| <span class="hljs-comment"># Run it!</span> | |
| result = agent.run( | |
| <span class="hljs-string">"How long would a cheetah at full speed take to run the length of Pont Alexandre III?"</span>, | |
| )<!-- HTML_TAG_END --></pre></div> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/smolagents/blob/main/docs/source/hi/tutorials/building_good_agents.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg> <span data-svelte-h="svelte-zjs2n5"><span class="underline">Update</span> on GitHub</span></a> <p></p> | |
| <script> | |
| { | |
| __sveltekit_ehst33 = { | |
| assets: "/docs/smolagents/pr_2321/hi", | |
| base: "/docs/smolagents/pr_2321/hi", | |
| env: {} | |
| }; | |
| const element = document.currentScript.parentElement; | |
| const data = [null,null]; | |
| Promise.all([ | |
| import("/docs/smolagents/pr_2321/hi/_app/immutable/entry/start.4c7058f2.js"), | |
| import("/docs/smolagents/pr_2321/hi/_app/immutable/entry/app.3b65213b.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 11], | |
| data, | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 74.2 kB
- Xet hash:
- 13cb6f17ed882654f3590e451ced9fec12a5096746a24307bdf9a83fb6ea579d
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.