Spaces:
Runtime error
Runtime error
Scott Cogan commited on
Commit ·
40dd326
1
Parent(s): 79907e0
Fix: Replace YAML loading with direct Python dictionary for prompt templates
Browse files
app.py
CHANGED
|
@@ -68,15 +68,117 @@ model = OpenAIModel(
|
|
| 68 |
# Import tool from Hub
|
| 69 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
agent = CodeAgent(
|
| 82 |
model=model,
|
|
|
|
| 68 |
# Import tool from Hub
|
| 69 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 70 |
|
| 71 |
+
# Define prompt templates directly as a Python dictionary
|
| 72 |
+
prompt_templates = {
|
| 73 |
+
"system_prompt": """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.
|
| 74 |
+
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.
|
| 75 |
+
To solve the task, you must plan forward to proceed in a series of steps, in a cycle of 'Thought:', 'Code:', and 'Observation:' sequences.
|
| 76 |
+
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.
|
| 77 |
+
Then in the 'Code:' sequence, you should write the code in simple Python. The code sequence must end with '<end_code>' sequence.
|
| 78 |
+
During each intermediate step, you can use 'print()' to save whatever important information you will then need.
|
| 79 |
+
These print outputs will then appear in the 'Observation:' field, which will be available as input for the next step.
|
| 80 |
+
|
| 81 |
+
IMPORTANT RULES:
|
| 82 |
+
1. You MUST use the final_answer tool to submit your answer. Never return a default answer.
|
| 83 |
+
2. If you're unsure about an answer, use the search tool to find information.
|
| 84 |
+
3. Always try to find the answer rather than returning a default response.
|
| 85 |
+
4. If you can't find a definitive answer, provide your best reasoning based on available information.
|
| 86 |
+
5. Never return "This is a default answer" - always provide your best attempt at answering the question.
|
| 87 |
+
6. For each question, you must:
|
| 88 |
+
a. Analyze what information is needed
|
| 89 |
+
b. Use appropriate tools to gather that information
|
| 90 |
+
c. Process the information to form an answer
|
| 91 |
+
d. Use final_answer to submit your response""",
|
| 92 |
+
|
| 93 |
+
"final_answer": """You have reached the final step of your task. Use the final_answer tool to submit your answer.
|
| 94 |
+
The answer should be clear, concise, and directly address the original question.
|
| 95 |
+
Format: final_answer(your_answer)""",
|
| 96 |
+
|
| 97 |
+
"planning": {
|
| 98 |
+
"initial_facts": """Below I will present you a task.
|
| 99 |
+
You will now build a comprehensive preparatory survey of which facts we have at our disposal and which ones we still need.
|
| 100 |
+
To do so, you will have to read the task and identify things that must be discovered in order to successfully complete it.
|
| 101 |
+
Don't make any assumptions. For each item, provide a thorough reasoning. Here is how you will structure this survey:
|
| 102 |
+
|
| 103 |
+
---
|
| 104 |
+
### 1. Facts given in the task
|
| 105 |
+
List here the specific facts given in the task that could help you (there might be nothing here).
|
| 106 |
+
|
| 107 |
+
### 2. Facts to look up
|
| 108 |
+
List here any facts that we may need to look up.
|
| 109 |
+
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.
|
| 110 |
+
|
| 111 |
+
### 3. Facts to derive
|
| 112 |
+
List here anything that we want to derive from the above by logical reasoning, for instance computation or simulation.""",
|
| 113 |
+
|
| 114 |
+
"initial_plan": """You are a world expert at making efficient plans to solve any task using a set of carefully crafted tools.
|
| 115 |
+
Now for the given task, develop a step-by-step high-level plan taking into account the above inputs and list of facts.
|
| 116 |
+
This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
|
| 117 |
+
Do not skip steps, do not add any superfluous steps. Only write the high-level plan, DO NOT DETAIL INDIVIDUAL TOOL CALLS.
|
| 118 |
+
After writing the final step of the plan, write the '\n<end_plan>' tag and stop there.""",
|
| 119 |
+
|
| 120 |
+
"update_facts_pre_messages": """You are a world expert at gathering known and unknown facts based on a conversation.
|
| 121 |
+
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:
|
| 122 |
+
### 1. Facts given in the task
|
| 123 |
+
### 2. Facts that we have learned
|
| 124 |
+
### 3. Facts still to look up
|
| 125 |
+
### 4. Facts still to derive
|
| 126 |
+
Find the task and history below:""",
|
| 127 |
+
|
| 128 |
+
"update_facts_post_messages": """Earlier we've built a list of facts.
|
| 129 |
+
But since in your previous steps you may have learned useful new facts or invalidated some false ones.
|
| 130 |
+
Please update your list of facts based on the previous history, and provide these headings:
|
| 131 |
+
### 1. Facts given in the task
|
| 132 |
+
### 2. Facts that we have learned
|
| 133 |
+
### 3. Facts still to look up
|
| 134 |
+
### 4. Facts still to derive
|
| 135 |
+
|
| 136 |
+
Now write your new list of facts below.""",
|
| 137 |
+
|
| 138 |
+
"update_plan_pre_messages": """You are a world expert at making efficient plans to solve any task using a set of carefully crafted tools.
|
| 139 |
+
You have been given a task:
|
| 140 |
+
```
|
| 141 |
+
{{task}}
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
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.
|
| 145 |
+
If the previous tries so far have met some success, you can make an updated plan based on these actions.
|
| 146 |
+
If you are stalled, you can make a completely new plan starting from scratch.""",
|
| 147 |
+
|
| 148 |
+
"update_plan_post_messages": """You're still working towards solving this task:
|
| 149 |
+
```
|
| 150 |
+
{{task}}
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
Now for the given task, develop a step-by-step high-level plan taking into account the above inputs and list of facts.
|
| 154 |
+
This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
|
| 155 |
+
Beware that you have {remaining_steps} steps remaining.
|
| 156 |
+
Do not skip steps, do not add any superfluous steps. Only write the high-level plan, DO NOT DETAIL INDIVIDUAL TOOL CALLS.
|
| 157 |
+
After writing the final step of the plan, write the '\n<end_plan>' tag and stop there.
|
| 158 |
+
|
| 159 |
+
Now write your new plan below."""
|
| 160 |
+
},
|
| 161 |
+
|
| 162 |
+
"managed_agent": {
|
| 163 |
+
"task": """You're a helpful agent named '{{name}}'.
|
| 164 |
+
You have been submitted this task by your manager.
|
| 165 |
+
---
|
| 166 |
+
Task:
|
| 167 |
+
{{task}}
|
| 168 |
+
---
|
| 169 |
+
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.
|
| 170 |
+
Your final_answer WILL HAVE to contain these parts:
|
| 171 |
+
### 1. Task outcome (short version):
|
| 172 |
+
### 2. Task outcome (extremely detailed version):
|
| 173 |
+
### 3. Additional context (if relevant):
|
| 174 |
+
|
| 175 |
+
Put all these in your final_answer tool, everything that you do not pass as an argument to final_answer will be lost.
|
| 176 |
+
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.""",
|
| 177 |
+
|
| 178 |
+
"report": """Here is the final answer from your managed agent '{{name}}':
|
| 179 |
+
{{final_answer}}"""
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
|
| 183 |
agent = CodeAgent(
|
| 184 |
model=model,
|