NeuralNotwork commited on
Commit
c6c3859
·
verified ·
1 Parent(s): 44e19c7

Upload agent

Browse files
Files changed (7) hide show
  1. __init__.py +0 -0
  2. agent.json +43 -0
  3. app.py +36 -0
  4. prompts.yaml +159 -0
  5. requirements.txt +1 -0
  6. tools/__init__.py +0 -0
  7. tools/final_answer.py +14 -0
__init__.py ADDED
File without changes
agent.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "tools": [
3
+ "final_answer"
4
+ ],
5
+ "model": {
6
+ "class": "LiteLLMModel",
7
+ "data": {
8
+ "last_input_token_count": null,
9
+ "last_output_token_count": null,
10
+ "model_id": "openai/gpt-4o-mini",
11
+ "api_base": null
12
+ }
13
+ },
14
+ "managed_agents": {},
15
+ "prompt_templates": {
16
+ "system_prompt": "You are a helpful assistant.",
17
+ "planning": {
18
+ "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!",
19
+ "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 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{%- endif %}\n\nList of facts that you know:\n```\n{{answer_facts}}\n```\n\nNow begin! Write your plan below.",
20
+ "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:",
21
+ "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.",
22
+ "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.",
23
+ "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 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'.\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{%- 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."
24
+ },
25
+ "managed_agent": {
26
+ "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.",
27
+ "report": "Here is the final answer from your managed agent '{{name}}':\n{{final_answer}}"
28
+ },
29
+ "final_answer": {
30
+ "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:",
31
+ "post_messages": "Based on the above, please provide an answer to the following user task:\n{{task}}"
32
+ }
33
+ },
34
+ "max_steps": 20,
35
+ "verbosity_level": 1,
36
+ "grammar": null,
37
+ "planning_interval": null,
38
+ "name": null,
39
+ "description": null,
40
+ "requirements": [
41
+ "smolagents"
42
+ ]
43
+ }
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import yaml
2
+ import os
3
+ from smolagents import GradioUI, ToolCallingAgent, LiteLLMModel
4
+
5
+ # Get current directory path
6
+ CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
7
+
8
+ from tools.final_answer import FinalAnswerTool as FinalAnswer
9
+
10
+
11
+
12
+ model = LiteLLMModel(
13
+ model_id='openai/gpt-4o-mini',
14
+ api_base=None,
15
+ )
16
+
17
+ final_answer = FinalAnswer()
18
+
19
+
20
+ with open(os.path.join(CURRENT_DIR, "prompts.yaml"), 'r') as stream:
21
+ prompt_templates = yaml.safe_load(stream)
22
+
23
+ agent = ToolCallingAgent(
24
+ model=model,
25
+ tools=[],
26
+ managed_agents=[],
27
+ max_steps=20,
28
+ verbosity_level=1,
29
+ grammar=None,
30
+ planning_interval=None,
31
+ name=None,
32
+ description=None,
33
+ prompt_templates=prompt_templates
34
+ )
35
+ if __name__ == "__main__":
36
+ GradioUI(agent).launch()
prompts.yaml ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "system_prompt": |-
2
+ You are a helpful assistant.
3
+ "planning":
4
+ "initial_facts": |-
5
+ Below I will present you a task.
6
+
7
+ You will now build a comprehensive preparatory survey of which facts we have at our disposal and which ones we still need.
8
+ To do so, you will have to read the task and identify things that must be discovered in order to successfully complete it.
9
+ Don't make any assumptions. For each item, provide a thorough reasoning. Here is how you will structure this survey:
10
+
11
+ ---
12
+ ### 1. Facts given in the task
13
+ List here the specific facts given in the task that could help you (there might be nothing here).
14
+
15
+ ### 2. Facts to look up
16
+ List here any facts that we may need to look up.
17
+ 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.
18
+
19
+ ### 3. Facts to derive
20
+ List here anything that we want to derive from the above by logical reasoning, for instance computation or simulation.
21
+
22
+ Keep in mind that "facts" will typically be specific names, dates, values, etc. Your answer should use the below headings:
23
+ ### 1. Facts given in the task
24
+ ### 2. Facts to look up
25
+ ### 3. Facts to derive
26
+ Do not add anything else.
27
+
28
+ Here is the task:
29
+ ```
30
+ {{task}}
31
+ ```
32
+ Now begin!
33
+ "initial_plan": |-
34
+ You are a world expert at making efficient plans to solve any task using a set of carefully crafted tools.
35
+
36
+ Now for the given task, develop a step-by-step high-level plan taking into account the above inputs and list of facts.
37
+ This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
38
+ Do not skip steps, do not add any superfluous steps. Only write the high-level plan, DO NOT DETAIL INDIVIDUAL TOOL CALLS.
39
+ After writing the final step of the plan, write the '\n<end_plan>' tag and stop there.
40
+
41
+ Here is your task:
42
+
43
+ Task:
44
+ ```
45
+ {{task}}
46
+ ```
47
+ You can leverage these tools:
48
+ {%- for tool in tools.values() %}
49
+ - {{ tool.name }}: {{ tool.description }}
50
+ Takes inputs: {{tool.inputs}}
51
+ Returns an output of type: {{tool.output_type}}
52
+ {%- endfor %}
53
+
54
+ {%- if managed_agents and managed_agents.values() | list %}
55
+ You can also give tasks to team members.
56
+ 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.
57
+ Given that this team member is a real human, you should be very verbose in your task.
58
+ Here is a list of the team members that you can call:
59
+ {%- for agent in managed_agents.values() %}
60
+ - {{ agent.name }}: {{ agent.description }}
61
+ {%- endfor %}
62
+ {%- endif %}
63
+
64
+ List of facts that you know:
65
+ ```
66
+ {{answer_facts}}
67
+ ```
68
+
69
+ Now begin! Write your plan below.
70
+ "update_facts_pre_messages": |-
71
+ You are a world expert at gathering known and unknown facts based on a conversation.
72
+ 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:
73
+ ### 1. Facts given in the task
74
+ ### 2. Facts that we have learned
75
+ ### 3. Facts still to look up
76
+ ### 4. Facts still to derive
77
+ Find the task and history below:
78
+ "update_facts_post_messages": |-
79
+ Earlier we've built a list of facts.
80
+ But since in your previous steps you may have learned useful new facts or invalidated some false ones.
81
+ Please update your list of facts based on the previous history, and provide these headings:
82
+ ### 1. Facts given in the task
83
+ ### 2. Facts that we have learned
84
+ ### 3. Facts still to look up
85
+ ### 4. Facts still to derive
86
+
87
+ Now write your new list of facts below.
88
+ "update_plan_pre_messages": |-
89
+ You are a world expert at making efficient plans to solve any task using a set of carefully crafted tools.
90
+
91
+ You have been given a task:
92
+ ```
93
+ {{task}}
94
+ ```
95
+
96
+ 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.
97
+ If the previous tries so far have met some success, you can make an updated plan based on these actions.
98
+ If you are stalled, you can make a completely new plan starting from scratch.
99
+ "update_plan_post_messages": |-
100
+ You're still working towards solving this task:
101
+ ```
102
+ {{task}}
103
+ ```
104
+
105
+ You can leverage these tools:
106
+ {%- for tool in tools.values() %}
107
+ - {{ tool.name }}: {{ tool.description }}
108
+ Takes inputs: {{tool.inputs}}
109
+ Returns an output of type: {{tool.output_type}}
110
+ {%- endfor %}
111
+
112
+ {%- if managed_agents and managed_agents.values() | list %}
113
+ You can also give tasks to team members.
114
+ Calling a team member works the same as for calling a tool: simply, the only argument you can give in the call is 'task'.
115
+ 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.
116
+ Here is a list of the team members that you can call:
117
+ {%- for agent in managed_agents.values() %}
118
+ - {{ agent.name }}: {{ agent.description }}
119
+ {%- endfor %}
120
+ {%- endif %}
121
+
122
+ Here is the up to date list of facts that you know:
123
+ ```
124
+ {{facts_update}}
125
+ ```
126
+
127
+ Now for the given task, develop a step-by-step high-level plan taking into account the above inputs and list of facts.
128
+ This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
129
+ Beware that you have {remaining_steps} steps remaining.
130
+ Do not skip steps, do not add any superfluous steps. Only write the high-level plan, DO NOT DETAIL INDIVIDUAL TOOL CALLS.
131
+ After writing the final step of the plan, write the '\n<end_plan>' tag and stop there.
132
+
133
+ Now write your new plan below.
134
+ "managed_agent":
135
+ "task": |-
136
+ You're a helpful agent named '{{name}}'.
137
+ You have been submitted this task by your manager.
138
+ ---
139
+ Task:
140
+ {{task}}
141
+ ---
142
+ 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.
143
+
144
+ Your final_answer WILL HAVE to contain these parts:
145
+ ### 1. Task outcome (short version):
146
+ ### 2. Task outcome (extremely detailed version):
147
+ ### 3. Additional context (if relevant):
148
+
149
+ Put all these in your final_answer tool, everything that you do not pass as an argument to final_answer will be lost.
150
+ 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.
151
+ "report": |-
152
+ Here is the final answer from your managed agent '{{name}}':
153
+ {{final_answer}}
154
+ "final_answer":
155
+ "pre_messages": |-
156
+ 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:
157
+ "post_messages": |-
158
+ Based on the above, please provide an answer to the following user task:
159
+ {{task}}
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ 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