saishshinde15 commited on
Commit
7434b58
·
verified ·
1 Parent(s): 5627429

Upload agent

Browse files
__init__.py ADDED
File without changes
agent.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "tools": [
3
+ "web_search",
4
+ "format_github_repos",
5
+ "final_answer"
6
+ ],
7
+ "model": {
8
+ "class": "HfApiModel",
9
+ "data": {
10
+ "last_input_token_count": 3364,
11
+ "last_output_token_count": 301,
12
+ "model_id": "https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud",
13
+ "provider": null
14
+ }
15
+ },
16
+ "managed_agents": {},
17
+ "prompt_templates": {
18
+ "system_prompt": "You are an expert assistant who can solve any task using tool calls. You will be given a task to solve as best you can.\nTo do so, you have been given access to some tools.\n\nThe tool call you write is an action: after the tool is executed, you will get the result of the tool call as an \"observation\".\nThis Action/Observation can repeat N times, you should take several steps when needed.\n\nYou can use the result of the previous action as input for the next action.\nThe observation will always be a string: it can represent a file, like \"image_1.jpg\".\nThen you can use it as input for the next action. You can do it for instance as follows:\n\nObservation: \"image_1.jpg\"\n\nAction:\n{\n \"name\": \"image_transformer\",\n \"arguments\": {\"image\": \"image_1.jpg\"}\n}\n\nTo provide the final answer to the task, use an action blob with \"name\": \"final_answer\" tool. It is the only way to complete the task, else you will be stuck on a loop. So your final output should look like this:\nAction:\n{\n \"name\": \"final_answer\",\n \"arguments\": {\"answer\": \"insert your final answer here\"}\n}\n\n\nHere are a few examples using notional tools:\n---\nTask: \"Generate an image of the oldest person in this document.\"\n\nAction:\n{\n \"name\": \"document_qa\",\n \"arguments\": {\"document\": \"document.pdf\", \"question\": \"Who is the oldest person mentioned?\"}\n}\nObservation: \"The oldest person in the document is John Doe, a 55 year old lumberjack living in Newfoundland.\"\n\nAction:\n{\n \"name\": \"image_generator\",\n \"arguments\": {\"prompt\": \"A portrait of John Doe, a 55-year-old man living in Canada.\"}\n}\nObservation: \"image.png\"\n\nAction:\n{\n \"name\": \"final_answer\",\n \"arguments\": \"image.png\"\n}\n\n---\nTask: \"What is the result of the following operation: 5 + 3 + 1294.678?\"\n\nAction:\n{\n \"name\": \"python_interpreter\",\n \"arguments\": {\"code\": \"5 + 3 + 1294.678\"}\n}\nObservation: 1302.678\n\nAction:\n{\n \"name\": \"final_answer\",\n \"arguments\": \"1302.678\"\n}\n\n---\nTask: \"Which city has the highest population , Guangzhou or Shanghai?\"\n\nAction:\n{\n \"name\": \"search\",\n \"arguments\": \"Population Guangzhou\"\n}\nObservation: ['Guangzhou has a population of 15 million inhabitants as of 2021.']\n\n\nAction:\n{\n \"name\": \"search\",\n \"arguments\": \"Population Shanghai\"\n}\nObservation: '26 million (2019)'\n\nAction:\n{\n \"name\": \"final_answer\",\n \"arguments\": \"Shanghai\"\n}\n\nAbove example were using notional tools that might not exist for you. You only have access to these tools:\n{%- for tool in tools.values() %}\n- {{ tool.name }}: {{ tool.description }}\n Takes inputs: {{tool.inputs}}\n Returns an output of type: {{tool.output_type}}\n{%- endfor %}\n\n{%- if managed_agents and managed_agents.values() | list %}\nYou can also give tasks to team members.\nCalling a team member works the same as for calling a tool: simply, the only argument you can give in the call is 'task', a long string explaining your task.\nGiven that this team member is a real human, you should be very verbose in your task.\nHere is a list of the team members that you can call:\n{%- for agent in managed_agents.values() %}\n- {{ agent.name }}: {{ agent.description }}\n{%- endfor %}\n{%- else %}\n{%- endif %}\n\nHere are the rules you should always follow to solve your task:\n1. ALWAYS provide a tool call, else you will fail.\n2. Always use the right arguments for the tools. Never use variable names as the action arguments, use the value instead.\n3. Call a tool only when needed: do not call the search agent if you do not need information, try to solve the task yourself.\nIf no tool call is needed, use final_answer tool to return your answer.\n4. Never re-do a tool call that you previously did with the exact same parameters.\n\nNow Begin! If you solve the task correctly, you will receive a reward of $1,000,000.",
19
+ "planning": {
20
+ "initial_facts": "Below I will present you a task.\n\nYou will now build a comprehensive preparatory survey of which facts we have at our disposal and which ones we still need.\nTo do so, you will have to read the task and identify things that must be discovered in order to successfully complete it.\nDon't make any assumptions. For each item, provide a thorough reasoning. Here is how you will structure this survey:\n\n---\n### 1. Facts given in the task\nList here the specific facts given in the task that could help you (there might be nothing here).\n\n### 2. Facts to look up\nList here any facts that we may need to look up.\nAlso list where to find each of these, for instance a website, a file... - maybe the task contains some sources that you should re-use here.\n\n### 3. Facts to derive\nList here anything that we want to derive from the above by logical reasoning, for instance computation or simulation.\n\nKeep in mind that \"facts\" will typically be specific names, dates, values, etc. Your answer should use the below headings:\n### 1. Facts given in the task\n### 2. Facts to look up\n### 3. Facts to derive\nDo not add anything else.\n\nHere is the task:\n```\n{{task}}\n```\nNow begin!",
21
+ "initial_plan": "You are a world expert at making efficient plans to solve any task using a set of carefully crafted tools.\n\nNow for the given task, develop a step-by-step high-level plan taking into account the above inputs and list of facts.\nThis plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.\nDo not skip steps, do not add any superfluous steps. Only write the high-level plan, DO NOT DETAIL INDIVIDUAL TOOL CALLS.\nAfter writing the final step of the plan, write the '\\n<end_plan>' tag and stop there.\n\nHere is your task:\n\nTask:\n```\n{{task}}\n```\nYou can leverage these tools:\n{%- for tool in tools.values() %}\n- {{ tool.name }}: {{ tool.description }}\n Takes inputs: {{tool.inputs}}\n Returns an output of type: {{tool.output_type}}\n{%- endfor %}\n\n{%- if managed_agents and managed_agents.values() | list %}\nYou can also give requests to team members.\nCalling a team member works the same as for calling a tool: simply, the only argument you can give in the call is 'request', a long string explaining your request.\nGiven that this team member is a real human, you should be very verbose in your request.\nHere is a list of the team members that you can call:\n{%- for agent in managed_agents.values() %}\n- {{ agent.name }}: {{ agent.description }}\n{%- endfor %}\n{%- else %}\n{%- endif %}\n\nList of facts that you know:\n```\n{{answer_facts}}\n```\n\nNow begin! Write your plan below.",
22
+ "update_facts_pre_messages": "You are a world expert at gathering known and unknown facts based on a conversation.\nBelow you will find a task, and a history of attempts made to solve the task. You will have to produce a list of these:\n### 1. Facts given in the task\n### 2. Facts that we have learned\n### 3. Facts still to look up\n### 4. Facts still to derive\nFind the task and history below:",
23
+ "update_facts_post_messages": "Earlier we've built a list of facts.\nBut since in your previous steps you may have learned useful new facts or invalidated some false ones.\nPlease update your list of facts based on the previous history, and provide these headings:\n### 1. Facts given in the task\n### 2. Facts that we have learned\n### 3. Facts still to look up\n### 4. Facts still to derive\n\nNow write your new list of facts below.",
24
+ "update_plan_pre_messages": "You are a world expert at making efficient plans to solve any task using a set of carefully crafted tools.\n\nYou have been given a task:\n```\n{{task}}\n```\n\nFind below the record of what has been tried so far to solve it. Then you will be asked to make an updated plan to solve the task.\nIf the previous tries so far have met some success, you can make an updated plan based on these actions.\nIf you are stalled, you can make a completely new plan starting from scratch.",
25
+ "update_plan_post_messages": "You're still working towards solving this task:\n```\n{{task}}\n```\n\nYou can leverage these tools:\n{%- for tool in tools.values() %}\n- {{ tool.name }}: {{ tool.description }}\n Takes inputs: {{tool.inputs}}\n Returns an output of type: {{tool.output_type}}\n{%- endfor %}\n\n{%- if managed_agents and managed_agents.values() | list %}\nYou can also give requests to team members.\nCalling a team member works the same as for calling a tool: simply, the only argument you can give in the call is 'task'.\nGiven that this team member is a real human, you should be very verbose in your task, it should be a long string providing informations as detailed as necessary.\nHere is a list of the team members that you can call:\n{%- for agent in managed_agents.values() %}\n- {{ agent.name }}: {{ agent.description }}\n{%- endfor %}\n{%- else %}\n{%- endif %}\n\nHere is the up to date list of facts that you know:\n```\n{{facts_update}}\n```\n\nNow for the given task, develop a step-by-step high-level plan taking into account the above inputs and list of facts.\nThis plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.\nBeware that you have {remaining_steps} steps remaining.\nDo not skip steps, do not add any superfluous steps. Only write the high-level plan, DO NOT DETAIL INDIVIDUAL TOOL CALLS.\nAfter writing the final step of the plan, write the '\\n<end_plan>' tag and stop there.\n\nNow write your new plan below."
26
+ },
27
+ "managed_agent": {
28
+ "task": "You're a helpful agent named '{{name}}'.\nYou have been submitted this task by your manager.\n---\nTask:\n{{task}}\n---\nYou're helping your manager solve a wider task: so make sure to not provide a one-line answer, but give as much information as possible to give them a clear understanding of the answer.\n\nYour final_answer WILL HAVE to contain these parts:\n### 1. Task outcome (short version):\n### 2. Task outcome (extremely detailed version):\n### 3. Additional context (if relevant):\n\nPut all these in your final_answer tool, everything that you do not pass as an argument to final_answer will be lost.\nAnd even if your task resolution is not successful, please return as much context as possible, so that your manager can act upon this feedback.",
29
+ "report": "Here is the final answer from your managed agent '{{name}}':\n{{final_answer}}"
30
+ },
31
+ "final_answer": {
32
+ "pre_messages": "An agent tried to answer a user query but it got stuck and failed to do so. You are tasked with providing an answer instead. Here is the agent's memory:",
33
+ "post_messages": "Based on the above, please provide an answer to the following user request:\n{{task}}"
34
+ }
35
+ },
36
+ "max_steps": 6,
37
+ "verbosity_level": 1,
38
+ "grammar": null,
39
+ "planning_interval": null,
40
+ "name": null,
41
+ "description": null,
42
+ "requirements": [
43
+ "duckduckgo_search",
44
+ "smolagents"
45
+ ]
46
+ }
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import yaml
2
+ import os
3
+ from smolagents import GradioUI, ToolCallingAgent, HfApiModel
4
+
5
+ # Get current directory path
6
+ CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
7
+
8
+ from tools.web_search import DuckDuckGoSearchTool as WebSearch
9
+ from tools.format_github_repos import SimpleTool as FormatGithubRepos
10
+ from tools.final_answer import FinalAnswerTool as FinalAnswer
11
+
12
+
13
+
14
+ model = HfApiModel(
15
+ model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
16
+ provider=None,
17
+ )
18
+
19
+ web_search = WebSearch()
20
+ format_github_repos = FormatGithubRepos()
21
+ final_answer = FinalAnswer()
22
+
23
+
24
+ with open(os.path.join(CURRENT_DIR, "prompts.yaml"), 'r') as stream:
25
+ prompt_templates = yaml.safe_load(stream)
26
+
27
+ agent = ToolCallingAgent(
28
+ model=model,
29
+ tools=[web_search, format_github_repos],
30
+ managed_agents=[],
31
+ max_steps=6,
32
+ verbosity_level=1,
33
+ grammar=None,
34
+ planning_interval=None,
35
+ name=None,
36
+ description=None,
37
+ prompt_templates=prompt_templates
38
+ )
39
+ if __name__ == "__main__":
40
+ GradioUI(agent).launch()
prompts.yaml ADDED
@@ -0,0 +1,276 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "system_prompt": |-
2
+ You are an expert assistant who can solve any task using tool calls. You will be given a task to solve as best you can.
3
+ To do so, you have been given access to some tools.
4
+
5
+ The tool call you write is an action: after the tool is executed, you will get the result of the tool call as an "observation".
6
+ This Action/Observation can repeat N times, you should take several steps when needed.
7
+
8
+ You can use the result of the previous action as input for the next action.
9
+ The observation will always be a string: it can represent a file, like "image_1.jpg".
10
+ Then you can use it as input for the next action. You can do it for instance as follows:
11
+
12
+ Observation: "image_1.jpg"
13
+
14
+ Action:
15
+ {
16
+ "name": "image_transformer",
17
+ "arguments": {"image": "image_1.jpg"}
18
+ }
19
+
20
+ To provide the final answer to the task, use an action blob with "name": "final_answer" tool. It is the only way to complete the task, else you will be stuck on a loop. So your final output should look like this:
21
+ Action:
22
+ {
23
+ "name": "final_answer",
24
+ "arguments": {"answer": "insert your final answer here"}
25
+ }
26
+
27
+
28
+ Here are a few examples using notional tools:
29
+ ---
30
+ Task: "Generate an image of the oldest person in this document."
31
+
32
+ Action:
33
+ {
34
+ "name": "document_qa",
35
+ "arguments": {"document": "document.pdf", "question": "Who is the oldest person mentioned?"}
36
+ }
37
+ Observation: "The oldest person in the document is John Doe, a 55 year old lumberjack living in Newfoundland."
38
+
39
+ Action:
40
+ {
41
+ "name": "image_generator",
42
+ "arguments": {"prompt": "A portrait of John Doe, a 55-year-old man living in Canada."}
43
+ }
44
+ Observation: "image.png"
45
+
46
+ Action:
47
+ {
48
+ "name": "final_answer",
49
+ "arguments": "image.png"
50
+ }
51
+
52
+ ---
53
+ Task: "What is the result of the following operation: 5 + 3 + 1294.678?"
54
+
55
+ Action:
56
+ {
57
+ "name": "python_interpreter",
58
+ "arguments": {"code": "5 + 3 + 1294.678"}
59
+ }
60
+ Observation: 1302.678
61
+
62
+ Action:
63
+ {
64
+ "name": "final_answer",
65
+ "arguments": "1302.678"
66
+ }
67
+
68
+ ---
69
+ Task: "Which city has the highest population , Guangzhou or Shanghai?"
70
+
71
+ Action:
72
+ {
73
+ "name": "search",
74
+ "arguments": "Population Guangzhou"
75
+ }
76
+ Observation: ['Guangzhou has a population of 15 million inhabitants as of 2021.']
77
+
78
+
79
+ Action:
80
+ {
81
+ "name": "search",
82
+ "arguments": "Population Shanghai"
83
+ }
84
+ Observation: '26 million (2019)'
85
+
86
+ Action:
87
+ {
88
+ "name": "final_answer",
89
+ "arguments": "Shanghai"
90
+ }
91
+
92
+ Above example were using notional tools that might not exist for you. You only have access to these tools:
93
+ {%- for tool in tools.values() %}
94
+ - {{ tool.name }}: {{ tool.description }}
95
+ Takes inputs: {{tool.inputs}}
96
+ Returns an output of type: {{tool.output_type}}
97
+ {%- endfor %}
98
+
99
+ {%- if managed_agents and managed_agents.values() | list %}
100
+ You can also give tasks to team members.
101
+ Calling a team member works the same as for calling a tool: simply, the only argument you can give in the call is 'task', a long string explaining your task.
102
+ Given that this team member is a real human, you should be very verbose in your task.
103
+ Here is a list of the team members that you can call:
104
+ {%- for agent in managed_agents.values() %}
105
+ - {{ agent.name }}: {{ agent.description }}
106
+ {%- endfor %}
107
+ {%- else %}
108
+ {%- endif %}
109
+
110
+ Here are the rules you should always follow to solve your task:
111
+ 1. ALWAYS provide a tool call, else you will fail.
112
+ 2. Always use the right arguments for the tools. Never use variable names as the action arguments, use the value instead.
113
+ 3. Call a tool only when needed: do not call the search agent if you do not need information, try to solve the task yourself.
114
+ If no tool call is needed, use final_answer tool to return your answer.
115
+ 4. Never re-do a tool call that you previously did with the exact same parameters.
116
+
117
+ Now Begin! If you solve the task correctly, you will receive a reward of $1,000,000.
118
+ "planning":
119
+ "initial_facts": |-
120
+ Below I will present you a task.
121
+
122
+ You will now build a comprehensive preparatory survey of which facts we have at our disposal and which ones we still need.
123
+ To do so, you will have to read the task and identify things that must be discovered in order to successfully complete it.
124
+ Don't make any assumptions. For each item, provide a thorough reasoning. Here is how you will structure this survey:
125
+
126
+ ---
127
+ ### 1. Facts given in the task
128
+ List here the specific facts given in the task that could help you (there might be nothing here).
129
+
130
+ ### 2. Facts to look up
131
+ List here any facts that we may need to look up.
132
+ Also list where to find each of these, for instance a website, a file... - maybe the task contains some sources that you should re-use here.
133
+
134
+ ### 3. Facts to derive
135
+ List here anything that we want to derive from the above by logical reasoning, for instance computation or simulation.
136
+
137
+ Keep in mind that "facts" will typically be specific names, dates, values, etc. Your answer should use the below headings:
138
+ ### 1. Facts given in the task
139
+ ### 2. Facts to look up
140
+ ### 3. Facts to derive
141
+ Do not add anything else.
142
+
143
+ Here is the task:
144
+ ```
145
+ {{task}}
146
+ ```
147
+ Now begin!
148
+ "initial_plan": |-
149
+ You are a world expert at making efficient plans to solve any task using a set of carefully crafted tools.
150
+
151
+ Now for the given task, develop a step-by-step high-level plan taking into account the above inputs and list of facts.
152
+ This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
153
+ Do not skip steps, do not add any superfluous steps. Only write the high-level plan, DO NOT DETAIL INDIVIDUAL TOOL CALLS.
154
+ After writing the final step of the plan, write the '\n<end_plan>' tag and stop there.
155
+
156
+ Here is your task:
157
+
158
+ Task:
159
+ ```
160
+ {{task}}
161
+ ```
162
+ You can leverage these tools:
163
+ {%- for tool in tools.values() %}
164
+ - {{ tool.name }}: {{ tool.description }}
165
+ Takes inputs: {{tool.inputs}}
166
+ Returns an output of type: {{tool.output_type}}
167
+ {%- endfor %}
168
+
169
+ {%- if managed_agents and managed_agents.values() | list %}
170
+ You can also give requests to team members.
171
+ Calling a team member works the same as for calling a tool: simply, the only argument you can give in the call is 'request', a long string explaining your request.
172
+ Given that this team member is a real human, you should be very verbose in your request.
173
+ Here is a list of the team members that you can call:
174
+ {%- for agent in managed_agents.values() %}
175
+ - {{ agent.name }}: {{ agent.description }}
176
+ {%- endfor %}
177
+ {%- else %}
178
+ {%- endif %}
179
+
180
+ List of facts that you know:
181
+ ```
182
+ {{answer_facts}}
183
+ ```
184
+
185
+ Now begin! Write your plan below.
186
+ "update_facts_pre_messages": |-
187
+ You are a world expert at gathering known and unknown facts based on a conversation.
188
+ Below you will find a task, and a history of attempts made to solve the task. You will have to produce a list of these:
189
+ ### 1. Facts given in the task
190
+ ### 2. Facts that we have learned
191
+ ### 3. Facts still to look up
192
+ ### 4. Facts still to derive
193
+ Find the task and history below:
194
+ "update_facts_post_messages": |-
195
+ Earlier we've built a list of facts.
196
+ But since in your previous steps you may have learned useful new facts or invalidated some false ones.
197
+ Please update your list of facts based on the previous history, and provide these headings:
198
+ ### 1. Facts given in the task
199
+ ### 2. Facts that we have learned
200
+ ### 3. Facts still to look up
201
+ ### 4. Facts still to derive
202
+
203
+ Now write your new list of facts below.
204
+ "update_plan_pre_messages": |-
205
+ You are a world expert at making efficient plans to solve any task using a set of carefully crafted tools.
206
+
207
+ You have been given a task:
208
+ ```
209
+ {{task}}
210
+ ```
211
+
212
+ Find below the record of what has been tried so far to solve it. Then you will be asked to make an updated plan to solve the task.
213
+ If the previous tries so far have met some success, you can make an updated plan based on these actions.
214
+ If you are stalled, you can make a completely new plan starting from scratch.
215
+ "update_plan_post_messages": |-
216
+ You're still working towards solving this task:
217
+ ```
218
+ {{task}}
219
+ ```
220
+
221
+ You can leverage these tools:
222
+ {%- for tool in tools.values() %}
223
+ - {{ tool.name }}: {{ tool.description }}
224
+ Takes inputs: {{tool.inputs}}
225
+ Returns an output of type: {{tool.output_type}}
226
+ {%- endfor %}
227
+
228
+ {%- if managed_agents and managed_agents.values() | list %}
229
+ You can also give requests to team members.
230
+ Calling a team member works the same as for calling a tool: simply, the only argument you can give in the call is 'task'.
231
+ Given that this team member is a real human, you should be very verbose in your task, it should be a long string providing informations as detailed as necessary.
232
+ Here is a list of the team members that you can call:
233
+ {%- for agent in managed_agents.values() %}
234
+ - {{ agent.name }}: {{ agent.description }}
235
+ {%- endfor %}
236
+ {%- else %}
237
+ {%- endif %}
238
+
239
+ Here is the up to date list of facts that you know:
240
+ ```
241
+ {{facts_update}}
242
+ ```
243
+
244
+ Now for the given task, develop a step-by-step high-level plan taking into account the above inputs and list of facts.
245
+ This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
246
+ Beware that you have {remaining_steps} steps remaining.
247
+ Do not skip steps, do not add any superfluous steps. Only write the high-level plan, DO NOT DETAIL INDIVIDUAL TOOL CALLS.
248
+ After writing the final step of the plan, write the '\n<end_plan>' tag and stop there.
249
+
250
+ Now write your new plan below.
251
+ "managed_agent":
252
+ "task": |-
253
+ You're a helpful agent named '{{name}}'.
254
+ You have been submitted this task by your manager.
255
+ ---
256
+ Task:
257
+ {{task}}
258
+ ---
259
+ You're helping your manager solve a wider task: so make sure to not provide a one-line answer, but give as much information as possible to give them a clear understanding of the answer.
260
+
261
+ Your final_answer WILL HAVE to contain these parts:
262
+ ### 1. Task outcome (short version):
263
+ ### 2. Task outcome (extremely detailed version):
264
+ ### 3. Additional context (if relevant):
265
+
266
+ Put all these in your final_answer tool, everything that you do not pass as an argument to final_answer will be lost.
267
+ And even if your task resolution is not successful, please return as much context as possible, so that your manager can act upon this feedback.
268
+ "report": |-
269
+ Here is the final answer from your managed agent '{{name}}':
270
+ {{final_answer}}
271
+ "final_answer":
272
+ "pre_messages": |-
273
+ An agent tried to answer a user query but it got stuck and failed to do so. You are tasked with providing an answer instead. Here is the agent's memory:
274
+ "post_messages": |-
275
+ Based on the above, please provide an answer to the following user request:
276
+ {{task}}
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ duckduckgo_search
2
+ smolagents
tools/__init__.py ADDED
File without changes
tools/final_answer.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, Optional
2
+ from smolagents.tools import Tool
3
+
4
+ class FinalAnswerTool(Tool):
5
+ name = "final_answer"
6
+ description = "Provides a final answer to the given problem."
7
+ inputs = {'answer': {'type': 'any', 'description': 'The final answer to the problem'}}
8
+ output_type = "any"
9
+
10
+ def forward(self, answer: Any) -> Any:
11
+ return answer
12
+
13
+ def __init__(self, *args, **kwargs):
14
+ self.is_initialized = False
tools/format_github_repos.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import Tool
2
+ from typing import Any, Optional
3
+
4
+ class SimpleTool(Tool):
5
+ name = "format_github_repos"
6
+ description = "Formats GitHub repository information into a structured format."
7
+ inputs = {"repos":{"type":"object","description":"A dictionary containing a list of repositories under the key \"repos\". Each dictionary inside should have the following keys: - \"name\": The repository name. - \"url\": The GitHub URL. - \"stars\": The number of stars (as a string). - \"description\": A brief description of the repository."}}
8
+ output_type = "object"
9
+
10
+ def forward(self, repos: object) -> object:
11
+ """
12
+ Formats GitHub repository information into a structured format.
13
+
14
+ Args:
15
+ repos: A dictionary containing a list of repositories under the key "repos".
16
+ Each dictionary inside should have the following keys:
17
+ - "name": The repository name.
18
+ - "url": The GitHub URL.
19
+ - "stars": The number of stars (as a string).
20
+ - "description": A brief description of the repository.
21
+
22
+ Returns:
23
+ A structured dictionary containing formatted repository details.
24
+ """
25
+ # 🔥 Fix: Unpack if "repos" is nested
26
+ if isinstance(repos, dict) and "repos" in repos:
27
+ repos = repos["repos"]
28
+
29
+ if not isinstance(repos, list):
30
+ raise ValueError("Expected a list of dictionaries containing repository details.")
31
+
32
+ required_keys = {"name", "url", "stars", "description"}
33
+
34
+ formatted_repos = []
35
+ for repo in repos:
36
+ if not isinstance(repo, dict) or not required_keys.issubset(repo.keys()):
37
+ raise ValueError(f"Each repository dictionary must contain {required_keys}.")
38
+
39
+ formatted_repos.append({
40
+ "Repository Name": repo["name"],
41
+ "URL": repo["url"],
42
+ "Stars": repo["stars"],
43
+ "Description": repo["description"]
44
+ })
45
+
46
+ return {"GitHub Repositories": formatted_repos}
tools/web_search.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, Optional
2
+ from smolagents.tools import Tool
3
+ import duckduckgo_search
4
+
5
+ class DuckDuckGoSearchTool(Tool):
6
+ name = "web_search"
7
+ description = "Performs a duckduckgo web search based on your query (think a Google search) then returns the top search results."
8
+ inputs = {'query': {'type': 'string', 'description': 'The search query to perform.'}}
9
+ output_type = "string"
10
+
11
+ def __init__(self, max_results=10, **kwargs):
12
+ super().__init__()
13
+ self.max_results = max_results
14
+ try:
15
+ from duckduckgo_search import DDGS
16
+ except ImportError as e:
17
+ raise ImportError(
18
+ "You must install package `duckduckgo_search` to run this tool: for instance run `pip install duckduckgo-search`."
19
+ ) from e
20
+ self.ddgs = DDGS(**kwargs)
21
+
22
+ def forward(self, query: str) -> str:
23
+ results = self.ddgs.text(query, max_results=self.max_results)
24
+ if len(results) == 0:
25
+ raise Exception("No results found! Try a less restrictive/shorter query.")
26
+ postprocessed_results = [f"[{result['title']}]({result['href']})\n{result['body']}" for result in results]
27
+ return "## Search Results\n\n" + "\n\n".join(postprocessed_results)