Duibonduil commited on
Commit
4feb387
·
verified ·
1 Parent(s): b5179e2

Upload building_good_agents.md

Browse files
docs/source/hi/building_good_agents.md ADDED
@@ -0,0 +1,420 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # अच्छे Agents का निर्माण
2
+
3
+ [[open-in-colab]]
4
+
5
+ एक ऐसा एजेंट बनाने में जो काम करता है और जो काम नहीं करता है, इसमें ज़मीन-आसमान का अंतर है।
6
+ हम कैसे ऐसे एजेंट्स बना सकते हैं जो बाद वाली श्रेणी में आते हैं?
7
+ इस गाइड में, हम एजेंट्स बनाने के लिए सर्वोत्तम प्रक्रियाएँ के बारे में बात करेंगे।
8
+
9
+ > [!TIP]
10
+ > यदि आप एजेंट्स बनाने में नए हैं, तो पहले [एजेंट्स का परिचय](../conceptual_guides/intro_agents) और [smolagents की गाइडेड टूर](../guided_tour) पढ़ना सुनिश्चित करें।
11
+
12
+ ### सर्वश्रेष्ठ एजेंटिक सिस्टम सबसे सरल होते हैं: वर्कफ़्लो को जितना हो सके उतना सरल बनाएं
13
+
14
+ अपने वर्कफ़्लो में एक LLM को कुछ एजेंसी देने से त्रुटियों का जोखिम होता है।
15
+
16
+ अच्छी तरह से प्रोग्राम किए गए एजेंटिक सिस्टम में वैसे भी अच्छी एरर लॉगिंग और रीट्राई मैकेनिज्म होते हैं, जिससे LLM इंजन अपनी गलतियों को सुधारने का मौका मिलता है। लेकिन LLM त्रुटि के जोखिम को अधिकतम कम करने के लिए, आपको अपना वर्कफ़्लो सरल बनाना चाहिए!
17
+
18
+ आइए [एजेंट्स का परिचय](../conceptual_guides/intro_agents) से उदाहरण पर फिर से विचार करें: एक सर्फ ट्रिप कंपनी के लिए उपयोगकर्ता प्रश्नों का उत्तर देने वाला बॉट।
19
+ एजेंट को हर बार जब एक नए सर्फ स्पॉट के बारे में पूछा जाता है तो "travel distance API" और "weather API" के लिए 2 अलग-अलग कॉल करने देने के बजाय, आप केवल एक एकीकृत टूल "return_spot_information" बना सकते हैं, एक फंक्शन जो दोनों APIs को एक साथ कॉल करता है और उनके संयोजित आउटपुट को उपयोगकर्ता को वापस करता है।
20
+
21
+ यह लागत, देरी और त्रुटि जोखिम को कम करेगा!
22
+
23
+ मुख्य दिशानिर्देश है: LLM कॉल्स की संख्या को जितना हो सके उतना कम करें।
24
+
25
+ इससे कुछ निष्कर्ष निकलते हैं:
26
+ - जब भी संभव हो, दो APIs के हमारे उदाहरण की तरह 2 टूल्स को एक में समूहित करें।
27
+ - जब भी संभव हो, लॉजिक एजेंटिक निर्णयों के बजाय डिटरमिनिस्टिक फंक्शंस पर आधारित होनी चाहिए।
28
+
29
+ ### LLM इंजन को जानकारी के प्रवाह में सुधार करें
30
+
31
+ याद रखें कि आपका LLM इंजन एक *बुद्धिमान* रोबोट की तरह है, जो एक कमरे में बंद है, और बाहरी दुनिया के साथ इसका एकमात्र संचार दरवाजे के नीचे से नोट्स पास करना है।
32
+
33
+ यह किसी भी ऐसी चीज के बारे में नहीं जानेगा जिसे आप स्पष्ट रूप से अपने प्रॉम्प्ट में नहीं डालते हैं।
34
+
35
+ इसलिए पहले अपने कार्य को बहुत स्पष्ट बनाने से शुरू करें!
36
+ चूंकि एक एजेंट LLM द्वारा संचालित होता है, आपके कार्य के निर्माण में छोटे बदलाव भी पूरी तरह से ���लग परिणाम दे सकते हैं।
37
+
38
+ फिर, टूल के उपयोग में अपने एजेंट की ओर जानकारी के प्रवाह में सुधार करें।
39
+
40
+ पालन करने के लिए विशेष दिशानिर्देश:
41
+ - प्रत्येक टूल को वह सब कुछ लॉग करना चाहिए (टूल की `forward` मेथड के अंदर केवल `print` स्टेटमेंट्स का उपयोग करके) जो LLM इंजन के लिए उपयोगी हो सकता है।
42
+ - विशेष रूप से, टूल एक्जीक्यूशन गलतियों पर विस्तृत लॉगिंग बहुत मदद करेगी!
43
+
44
+ उदाहरण के लिए, यहाँ एक टूल है जो लोकेशन और डेट-टाइम के आधार पर मौसम डेटा प्राप्त करता है:
45
+
46
+ पहले, यहाँ एक खराब रूप है:
47
+ ```python
48
+ import datetime
49
+ from smolagents import tool
50
+
51
+ def get_weather_report_at_coordinates(coordinates, date_time):
52
+ # Dummy function, returns a list of [temperature in °C, risk of rain on a scale 0-1, wave height in m]
53
+ return [28.0, 0.35, 0.85]
54
+
55
+ def convert_location_to_coordinates(location):
56
+ # Returns dummy coordinates
57
+ return [3.3, -42.0]
58
+
59
+ @tool
60
+ def get_weather_api(location: str, date_time: str) -> str:
61
+ """
62
+ Returns the weather report.
63
+
64
+ Args:
65
+ location: the name of the place that you want the weather for.
66
+ date_time: the date and time for which you want the report.
67
+ """
68
+ lon, lat = convert_location_to_coordinates(location)
69
+ date_time = datetime.strptime(date_time)
70
+ return str(get_weather_report_at_coordinates((lon, lat), date_time))
71
+ ```
72
+
73
+ # यह खराब क्यों है?
74
+ - `date_time` के लिए उपयोग किए जाने वाले फॉर्मेट की सटीकता का कोई उल्लेख नहीं है।
75
+ - यह स्पष्ट नहीं है कि स्थान (location) को किस प्रकार निर्दिष्ट किया जाना चाहिए।
76
+ - त्रुटियों को स्पष्ट रूप से इंगित करने के लिए कोई लॉगिंग मेकैनिज्म मौजूद नहीं है, जैसे कि स्थान गलत फॉर्मेट में होना या `date_time` का सही ढंग से फॉर्मेट न होना।
77
+ - आउटपुट फॉर्मेट समझने में कठिन है।
78
+
79
+ यदि टूल कॉल विफल हो जाती है, तो मेमोरी में लॉग की गई एरर ट्रेस LLM को टूल की समस्याओं को ठीक करने के लिए रिवर्स इंजीनियरिंग में मदद कर सकती है। लेकिन इतना सारा काम LLM को ही क्यों करने देना?
80
+
81
+ इस टूल को बेहतर तरीके से बनाने का एक उदाहरण इस प्रकार हो सकता है:
82
+
83
+ ```python
84
+ @tool
85
+ def get_weather_api(location: str, date_time: str) -> str:
86
+ """
87
+ Returns the weather report.
88
+
89
+ Args:
90
+ 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".
91
+ date_time: the date and time for which you want the report, formatted as '%m/%d/%y %H:%M:%S'.
92
+ """
93
+ lon, lat = convert_location_to_coordinates(location)
94
+ try:
95
+ date_time = datetime.strptime(date_time)
96
+ except Exception as e:
97
+ raise ValueError("Conversion of `date_time` to datetime format failed, make sure to provide a string in format '%m/%d/%y %H:%M:%S'. Full trace:" + str(e))
98
+ temperature_celsius, risk_of_rain, wave_height = get_weather_report_at_coordinates((lon, lat), date_time)
99
+ return f"Weather report for {location}, {date_time}: Temperature will be {temperature_celsius}°C, risk of rain is {risk_of_rain*100:.0f}%, wave height is {wave_height}m."
100
+ ```
101
+
102
+ सामान्य तौर पर, अपने LLM का बोझ को कम करने के लिए, खुद से यह अच्छा सवाल पूछें: "यदि मैं नया और अनुभवहीन हूं और इस टूल का पहली बार उपयोग कर रहा हूं, तो इस टूल के साथ प्रोग्रामिंग करना और अपनी गलति��ों को ठीक करना मेरे लिए कितना आसान होगा?"
103
+
104
+ ### एजेंट को अधिक तर्क (arguments) दें
105
+
106
+ अपने एजेंट को कार्य का वर्णन करने वाले साधारण स्ट्रिंग से आगे बढ़कर कुछ अतिरिक्त ऑब्जेक्ट्स देने के लिए, आप `additional_args` का उपयोग कर सकते हैं। यह आपको किसी भी प्रकार का ऑब्जेक्ट पास करने की सुविधा देता है:
107
+
108
+
109
+ ```py
110
+ from smolagents import CodeAgent, InferenceClientModel
111
+
112
+ model_id = "meta-llama/Llama-3.3-70B-Instruct"
113
+
114
+ agent = CodeAgent(tools=[], model=InferenceClientModel(model_id=model_id), add_base_tools=True)
115
+
116
+ agent.run(
117
+ "Why does Mike not know many people in New York?",
118
+ additional_args={"mp3_sound_file_url":'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/recording.mp3'}
119
+ )
120
+ ```
121
+ उदाहरण के लिए, आप इस `additional_args` आर्ग्यूमेंट का उपयोग उन इमेजेज़ या स्ट्रिंग्स को पास करने के लिए कर सकते हैं जिन्हें आप चाहते हैं कि आपका एजेंट उपयोग करे।
122
+
123
+
124
+
125
+ ## अपने एजेंट को डिबग कैसे करें
126
+
127
+ ### 1. एक अधिक शक्तिशाली LLM का उपयोग करें
128
+
129
+ एजेंटिक वर्कफ़्लो में, कुछ त्रुटियां वास्तविक होती हैं, जबकि कुछ अन्य त्रुटियां आपके LLM इंजन के सही तरीके से तर्क न कर पाने की वजह से होती हैं।
130
+ उदाहरण के लिए, इस ट्रेस को देखें, जहां मैंने एक `CodeAgent` से एक कार की तस्वीर बनाने के लिए कहा:
131
+ ```
132
+ ==================================================================================================== New task ====================================================================================================
133
+ Make me a cool car picture
134
+ ──────────────────────────────────────────────────────────────────────────────────────────────────── New step ────────────────────────────────────────────────────────────────────────────────────────────────────
135
+ Agent is executing the code below: ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
136
+ image_generator(prompt="A cool, futuristic sports car with LED headlights, aerodynamic design, and vibrant color, high-res, photorealistic")
137
+ ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
138
+
139
+ Last output from code snippet: ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
140
+ /var/folders/6m/9b1tts6d5w960j80wbw9tx3m0000gn/T/tmpx09qfsdd/652f0007-3ee9-44e2-94ac-90dae6bb89a4.png
141
+ Step 1:
142
+
143
+ - Time taken: 16.35 seconds
144
+ - Input tokens: 1,383
145
+ - Output tokens: 77
146
+ ──────────────────────────────────────────────────────────────────────────────────────────────────── New step ────────────────────────────────────────────────────────────────────────────────────────────────────
147
+ Agent is executing the code below: ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
148
+ final_answer("/var/folders/6m/9b1tts6d5w960j80wbw9tx3m0000gn/T/tmpx09qfsdd/652f0007-3ee9-44e2-94ac-90dae6bb89a4.png")
149
+ ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
150
+ Print outputs:
151
+
152
+ Last output from code snippet: ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
153
+ /var/folders/6m/9b1tts6d5w960j80wbw9tx3m0000gn/T/tmpx09qfsdd/652f0007-3ee9-44e2-94ac-90dae6bb89a4.png
154
+ Final answer:
155
+ /var/folders/6m/9b1tts6d5w960j80wbw9tx3m0000gn/T/tmpx09qfsdd/652f0007-3ee9-44e2-94ac-90dae6bb89a4.png
156
+ ```
157
+ उपयोगकर्ता को, एक इमेज लौटाए जाने के बजाय, उन्हें एक पाथ लौटाया जाता है।
158
+ यह सिस्टम से एक बग की तरह दिख सकता है, लेकिन वास्तव में एजेंटिक सिस्टम ने त्रुटि नहीं की: यह केवल इसलिए है कि LLM ब्रेन ने इमेज आउटपुट को एक वेरिएबल में सेव करने की गलती की।
159
+ इस प्रकार यह इमेज को फिर से एक्सेस नहीं कर सकता है सिवाय इमेज को सेव करते समय लॉग किए गए पाथ का उपयोग करके, इसलिए यह इमेज के बजाय पाथ लौटाता है।
160
+
161
+ अपने एजेंट को डीबग करने का पहला कदम इस प्रकार है "एक अधिक शक्तिशाली LLM का उपयोग करें"। `Qwen2/5-72B-Instruct` जैसे विकल्प वह गलती नहीं करते।
162
+
163
+ ### 2. अधिक मार्गदर्शन / अधिक जानकारी प्रदान करें
164
+
165
+ आप कम शक्तिशाली मॉडल्स का भी उपयोग कर सकते हैं, बशर्ते आप उन्हें अधिक प्रभावी ढंग से मार्गदर्शन करें।
166
+
167
+ अपने आप को अपने मॉडल की जगह रखें: यदि आप कार्य को हल करने वाला मॉडल होते, तो क्या आप उपलब्ध जानकारी (सिस्टम प्रॉम्प्ट + कार्य निर्माण + टूल विवरण से) के साथ संघर्ष करते?
168
+
169
+ क्या आपको कुछ अतिरिक्त स्पष्टी��रण की आवश्यकता होती?
170
+
171
+ अतिरिक्त जानकारी प्रदान करने के लिए, हम तुरंत सिस्टम प्रॉम्प्ट को बदलने की सलाह नहीं देते हैं: डिफ़ॉल्ट सिस्टम प्रॉम्प्ट में कई समायोजन हैं जिन्हें आप तब तक नहीं बिगाड़ना चाहते जब तक आप प्रॉम्प्ट को बहुत अच्छी तरह से नहीं समझते।
172
+ अपने LLM इंजन को मार्गदर्शन करने के बेहतर तरीके हैं:
173
+ - यदि यह कार्य को हल करने के बारे में है: इन सभी विवरणों को कार्य में जोड़ें। यह कार्य 100 पेज लंबा हो सकता है
174
+ - यदि यह टूल्स के उपयोग के बारे में है: आपके टूल्स की विवरण विशेषता।
175
+
176
+ ### 3. सिस्टम प्रॉम्प्ट बदलें (आमतौर पर यह सलाह नहीं दी जाती)
177
+
178
+ यदि उपरोक्त स्पष्टीकरण पर्याप्त नहीं हैं, तो आप सिस्टम प्रॉम्प्ट बदल सकते हैं।
179
+
180
+ आइए देखें कि यह कैसे काम करता है। उदाहरण के लिए, आइए [`CodeAgent`] के लिए डिफ़ॉल्ट सिस्टम प्रॉम्प्ट की जाँच करें (नीचे दिया गया वर्जन जीरो-शॉट उदाहरणों को छोड़कर छोटा किया गया है)।
181
+
182
+ ```python
183
+ print(agent.prompt_templates["system_prompt"])
184
+ ```
185
+ Here is what you get:
186
+ ```text
187
+ 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.
188
+ 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.
189
+ To solve the task, you must plan forward to proceed in a series of steps, in a cycle of 'Thought:', 'Code:', and 'Observation:' sequences.
190
+
191
+ 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.
192
+ Then in the 'Code:' sequence, you should write the code in simple Python. The code sequence must end with '<end_code>' sequence.
193
+ During each intermediate step, you can use 'print()' to save whatever important information you will then need.
194
+ These print outputs will then appear in the 'Observation:' field, which will be available as input for the next step.
195
+ In the end you have to return a final answer using the `final_answer` tool.
196
+
197
+ Here are a few examples using notional tools:
198
+ ---
199
+ Task: "Generate an image of the oldest person in this document."
200
+
201
+ 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.
202
+ Code:
203
+ ```py
204
+ answer = document_qa(document=document, question="Who is the oldest person mentioned?")
205
+ print(answer)
206
+ ```<end_code>
207
+ Observation: "The oldest person in the document is John Doe, a 55 year old lumberjack living in Newfoundland."
208
+
209
+ Thought: I will now generate an image showcasing the oldest person.
210
+ Code:
211
+ ```py
212
+ image = image_generator("A portrait of John Doe, a 55-year-old man living in Canada.")
213
+ final_answer(image)
214
+ ```<end_code>
215
+
216
+ ---
217
+ Task: "What is the result of the following operation: 5 + 3 + 1294.678?"
218
+
219
+ Thought: I will use python code to compute the result of the operation and then return the final answer using the `final_answer` tool
220
+ Code:
221
+ ```py
222
+ result = 5 + 3 + 1294.678
223
+ final_answer(result)
224
+ ```<end_code>
225
+
226
+ ---
227
+ Task:
228
+ "Answer the question in the variable `question` about the image stored in the variable `image`. The question is in French.
229
+ You have been provided with these additional arguments, that you can access using the keys as variables in your python code:
230
+ {'question': 'Quel est l'animal sur l'image?', 'image': 'path/to/image.jpg'}"
231
+
232
+ 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.
233
+ Code:
234
+ ```py
235
+ translated_question = translator(question=question, src_lang="French", tgt_lang="English")
236
+ print(f"The translated question is {translated_question}.")
237
+ answer = image_qa(image=image, question=translated_question)
238
+ final_answer(f"The answer is {answer}")
239
+ ```<end_code>
240
+
241
+ ---
242
+ Task:
243
+ In a 1979 interview, Stanislaus Ulam discusses with Martin Sherwin about other great physicists of his time, including Oppenheimer.
244
+ What does he say was the consequence of Einstein learning too much math on his creativity, in one word?
245
+
246
+ Thought: I need to find and read the 1979 interview of Stanislaus Ulam with Martin Sherwin.
247
+ Code:
248
+ ```py
249
+ pages = search(query="1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein")
250
+ print(pages)
251
+ ```<end_code>
252
+ Observation:
253
+ No result found for query "1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein".
254
+
255
+ Thought: The query was maybe too restrictive and did not find any results. Let's try again with a broader query.
256
+ Code:
257
+ ```py
258
+ pages = search(query="1979 interview Stanislaus Ulam")
259
+ print(pages)
260
+ ```<end_code>
261
+ Observation:
262
+ Found 6 pages:
263
+ [Stanislaus Ulam 1979 interview](https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/)
264
+
265
+ [Ulam discusses Manhattan Project](https://ahf.nuclearmuseum.org/manhattan-project/ulam-manhattan-project/)
266
+
267
+ (truncated)
268
+
269
+ Thought: I will read the first 2 pages to know more.
270
+ Code:
271
+ ```py
272
+ for url in ["https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/", "https://ahf.nuclearmuseum.org/manhattan-project/ulam-manhattan-project/"]:
273
+ whole_page = visit_webpage(url)
274
+ print(whole_page)
275
+ print("\n" + "="*80 + "\n") # Print separator between pages
276
+ ```<end_code>
277
+ Observation:
278
+ Manhattan Project Locations:
279
+ Los Alamos, NM
280
+ 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
281
+ (truncated)
282
+
283
+ 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.
284
+ Code:
285
+ ```py
286
+ final_answer("diminished")
287
+ ```<end_code>
288
+
289
+ ---
290
+ Task: "Which city has the highest population: Guangzhou or Shanghai?"
291
+
292
+ 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.
293
+ Code:
294
+ ```py
295
+ for city in ["Guangzhou", "Shanghai"]:
296
+ print(f"Population {city}:", search(f"{city} population")
297
+ ```<end_code>
298
+ Observation:
299
+ Population Guangzhou: ['Guangzhou has a population of 15 million inhabitants as of 2021.']
300
+ Population Shanghai: '26 million (2019)'
301
+
302
+ Thought: Now I know that Shanghai has the highest population.
303
+ Code:
304
+ ```py
305
+ final_answer("Shanghai")
306
+ ```<end_code>
307
+
308
+ ---
309
+ Task: "What is the current age of the pope, raised to the power 0.36?"
310
+
311
+ Thought: I will use the tool `wiki` to get the age of the pope, and confirm that with a web search.
312
+ Code:
313
+ ```py
314
+ pope_age_wiki = wiki(query="current pope age")
315
+ print("Pope age as per wikipedia:", pope_age_wiki)
316
+ pope_age_search = web_search(query="current pope age")
317
+ print("Pope age as per google search:", pope_age_search)
318
+ ```<end_code>
319
+ Observation:
320
+ Pope age: "The pope Francis is currently 88 years old."
321
+
322
+ Thought: I know that the pope is 88 years old. Let's compute the result using python code.
323
+ Code:
324
+ ```py
325
+ pope_current_age = 88 ** 0.36
326
+ final_answer(pope_current_age)
327
+ ```<end_code>
328
+
329
+ 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:
330
+ {%- for tool in tools.values() %}
331
+ - {{ tool.name }}: {{ tool.description }}
332
+ Takes inputs: {{tool.inputs}}
333
+ Returns an output of type: {{tool.output_type}}
334
+ {%- endfor %}
335
+
336
+ {%- if managed_agents and managed_agents.values() | list %}
337
+ You can also give tasks to team members.
338
+ 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.
339
+ You can also include any relevant variables or context using the 'additional_args' argument.
340
+ Here is a list of the team members that you can call:
341
+ {%- for agent in managed_agents.values() %}
342
+ - {{ agent.name }}: {{ agent.description }}
343
+ {%- endfor %}
344
+ {%- endif %}
345
+
346
+ Here are the rules you should always follow to solve your task:
347
+ 1. Always provide a 'Thought:' sequence, and a 'Code:\n```py' sequence ending with '```<end_code>' sequence, else you will fail.
348
+ 2. Use only variables that you have defined!
349
+ 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?")'.
350
+ 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.
351
+ 5. Call a tool only when needed, and never re-do a tool call that you previously did with the exact same parameters.
352
+ 6. Don't name any new variable with the same name as a tool: for instance don't name a variable 'final_answer'.
353
+ 7. Never create any notional variables in our code, as having these in your logs will derail you from the true variables.
354
+ 8. You can use imports in your code, but only from the following list of modules: {{authorized_imports}}
355
+ 9. The state persists between code executions: so if in one step you've created variables or imported modules, these will all persist.
356
+ 10. Don't give up! You're in charge of solving the task, not providing directions to solve it.
357
+
358
+ Now Begin! If you solve the task correctly, you will receive a reward of $1,000,000.
359
+ ```
360
+
361
+ जैसा कि आप देख सकते हैं, `"{{ tool.description }}"` जैसे प्लेसहोल्डर्स हैं: इनका उपयोग एजेंट इनिशियलाइजेशन के समय टूल्स या मैनेज्ड एजेंट्स के कुछ स्वचालित रूप से जनरेट किए गए विवरणों को डालने के लिए किया जाएगा।
362
+
363
+ इसलिए जबकि आप `system_prompt` पैरामीटर में अपने कस्टम प्रॉम्प्ट को आर्गुमेंट के रूप में पास करके इस सिस्टम प्रॉम्प्ट टेम्पलेट को ओवरराइट कर सकते हैं, आपके नए सिस्टम प्रॉम्प्ट में निम्नलिखित प्लेसहोल्डर्स होने चाहिए:
364
+ - टूल विवरण डालने के लिए।
365
+ ```
366
+ {%- for tool in tools.values() %}
367
+ - {{ tool.name }}: {{ tool.description }}
368
+ Takes inputs: {{tool.inputs}}
369
+ Returns an output of type: {{tool.output_type}}
370
+ {%- endfor %}
371
+ ```
372
+ - यदि कोई मैनेज्ड एजेंट्स हैं तो उनके लिए विवरण डालने के लिए।
373
+ ```
374
+ {%- if managed_agents and managed_agents.values() | list %}
375
+ You can also give tasks to team members.
376
+ 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.
377
+ You can also include any relevant variables or context using the 'additional_args' argument.
378
+ Here is a list of the team members that you can call:
379
+ {%- for agent in managed_agents.values() %}
380
+ - {{ agent.name }}: {{ agent.description }}
381
+ {%- endfor %}
382
+ {%- endif %}
383
+ ```
384
+ - केवल `CodeAgent` के लिए: अधिकृत इम्पोर्ट्स की सूची डालने के लिए `"{{authorized_imports}}"`।
385
+
386
+ फिर आप सिस्टम प्रॉम्प्ट को निम्नानुसार बदल सकते हैं:
387
+
388
+ ```py
389
+ agent.prompt_templates["system_prompt"] = agent.prompt_templates["system_prompt"] + "\nHere you go!"
390
+ ```
391
+
392
+ This also works with the [`ToolCallingAgent`].
393
+
394
+
395
+ ### 4. अतिरिक्त योजना
396
+
397
+ हम पूरक योजना चरण के लिए एक मॉडल प्रदान करते हैं, जिसे एजेंट सामान्य क्रियाओं के चरणों के बीच नियमित रूप से चला सकता है। इस चरण में कोई टूल कॉल नहीं होती है, LLM से केवल उन तथ्यों की सूची को अपडेट करने के लिए कहा जाता है जो उसे ज्ञात हैं और इन तथ्यों के आधार पर उसे अगले कदमों के बारे में विचार करना होता है।
398
+
399
+ ```py
400
+ from smolagents import load_tool, CodeAgent, InferenceClientModel, WebSearchTool
401
+ from dotenv import load_dotenv
402
+
403
+ load_dotenv()
404
+
405
+ # Import tool from Hub
406
+ image_generation_tool = load_tool("m-ric/text-to-image", trust_remote_code=True)
407
+
408
+ search_tool = WebSearchTool()
409
+
410
+ agent = CodeAgent(
411
+ tools=[search_tool],
412
+ model=InferenceClientModel(model_id="Qwen/Qwen2.5-72B-Instruct"),
413
+ planning_interval=3 # This is where you activate planning!
414
+ )
415
+
416
+ # Run it!
417
+ result = agent.run(
418
+ "How long would a cheetah at full speed take to run the length of Pont Alexandre III?",
419
+ )
420
+ ```