Spaces:
Sleeping
Sleeping
PCBZ commited on
Commit ·
bea2908
1
Parent(s): 4a5866f
Add final_answer key to prompt_templates for handling agent failures
Browse files
app.py
CHANGED
|
@@ -60,7 +60,14 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
|
|
| 60 |
|
| 61 |
with open("prompts.yaml", 'r') as stream:
|
| 62 |
prompt_templates = yaml.safe_load(stream)
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
agent = CodeAgent(
|
| 65 |
model=model,
|
| 66 |
tools=[final_answer, get_current_time_in_timezone, web_search_tool, image_generation_tool], ## add your tools here (don't remove final answer)
|
|
|
|
| 60 |
|
| 61 |
with open("prompts.yaml", 'r') as stream:
|
| 62 |
prompt_templates = yaml.safe_load(stream)
|
| 63 |
+
|
| 64 |
+
# smolagents==1.13.0 requires this key when max_steps is reached without a final_answer call,
|
| 65 |
+
# but the course template's prompts.yaml doesn't define it.
|
| 66 |
+
prompt_templates.setdefault("final_answer", {
|
| 67 |
+
"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:",
|
| 68 |
+
"post_messages": "Based on the above, please provide an answer to the following user task:\n{{task}}",
|
| 69 |
+
})
|
| 70 |
+
|
| 71 |
agent = CodeAgent(
|
| 72 |
model=model,
|
| 73 |
tools=[final_answer, get_current_time_in_timezone, web_search_tool, image_generation_tool], ## add your tools here (don't remove final answer)
|