Spaces:
Sleeping
Sleeping
final update
Browse files- app.py +62 -46
- prompts.yaml → prompts/code_agent.yaml +191 -186
- prompts/structured_code_agent.yaml +277 -0
- prompts/toolcalling_agent.yaml +250 -0
- requirements.txt +6 -2
- tools.py +13 -6
- watch +0 -0
app.py
CHANGED
|
@@ -1,18 +1,13 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
-
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
import yaml
|
| 7 |
|
| 8 |
-
from smolagents import CodeAgent, WebSearchTool, InferenceClientModel,
|
| 9 |
-
from tools import
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
# This is also a possibility
|
| 13 |
-
#from langchain.agents import load_tools
|
| 14 |
-
|
| 15 |
-
#search_tool = Tool.from_langchain(load_tools(["serpapi"])[0])
|
| 16 |
|
| 17 |
# (Keep Constants as is)
|
| 18 |
# --- Constants ---
|
|
@@ -20,46 +15,56 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 20 |
|
| 21 |
# --- Agent Definition ---
|
| 22 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 23 |
-
|
| 24 |
-
|
|
|
|
| 25 |
def __init__(self):
|
| 26 |
-
model=InferenceClientModel(
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
self.agent =
|
| 29 |
tools=[
|
| 30 |
-
#visit_webpage,
|
| 31 |
VisitWebpageTool(),
|
| 32 |
-
WebSearchTool()
|
| 33 |
-
analyze_image
|
| 34 |
],
|
| 35 |
model=model,
|
|
|
|
|
|
|
| 36 |
max_steps=10,
|
| 37 |
-
name="
|
| 38 |
-
description="Uses
|
| 39 |
-
|
| 40 |
-
"geopandas",
|
| 41 |
-
"plotly",
|
| 42 |
-
"shapely",
|
| 43 |
-
"json",
|
| 44 |
-
"pandas",
|
| 45 |
-
"numpy",
|
| 46 |
-
],
|
| 47 |
)
|
| 48 |
-
print("ManagedAgent CoderAgent initialized.")
|
| 49 |
|
| 50 |
def __call__(self, prompt: str) -> str:
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
|
| 56 |
class MasterAgent:
|
| 57 |
def __init__(self):
|
| 58 |
-
|
| 59 |
-
model=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
try:
|
| 62 |
-
|
| 63 |
except Exception as e:
|
| 64 |
print(f"Error instantiating agent: {e}")
|
| 65 |
return f"Error initializing agent: {e}", None
|
|
@@ -68,23 +73,25 @@ class MasterAgent:
|
|
| 68 |
self.master_agent = CodeAgent(
|
| 69 |
tools=[
|
| 70 |
VisitWebpageTool(),
|
| 71 |
-
WebSearchTool(),
|
|
|
|
| 72 |
analyze_image,
|
|
|
|
|
|
|
| 73 |
],
|
| 74 |
model=model,
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
additional_authorized_imports=[
|
| 80 |
-
"geopandas",
|
| 81 |
-
"plotly",
|
| 82 |
-
"shapely",
|
| 83 |
"json",
|
| 84 |
"pandas",
|
| 85 |
"numpy",
|
| 86 |
],
|
|
|
|
| 87 |
)
|
|
|
|
| 88 |
print("MasterAgent initialized.")
|
| 89 |
|
| 90 |
def __call__(self, question: str, attached_file: str) -> str:
|
|
@@ -96,7 +103,7 @@ class MasterAgent:
|
|
| 96 |
additional_args = {
|
| 97 |
"attached_file": attached_file
|
| 98 |
}
|
| 99 |
-
question = question + f"
|
| 100 |
|
| 101 |
agent_answer = self.master_agent.run(question, additional_args=additional_args)
|
| 102 |
print(f"Agent answer: {agent_answer}")
|
|
@@ -119,8 +126,8 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 119 |
return "Please Login to Hugging Face with the button.", None
|
| 120 |
|
| 121 |
api_url = DEFAULT_API_URL
|
| 122 |
-
|
| 123 |
-
questions_url = f"{api_url}/random-question"
|
| 124 |
submit_url = f"{api_url}/submit"
|
| 125 |
|
| 126 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
|
@@ -138,7 +145,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 138 |
try:
|
| 139 |
response = requests.get(questions_url, timeout=15)
|
| 140 |
response.raise_for_status()
|
| 141 |
-
questions_data =
|
| 142 |
if not questions_data:
|
| 143 |
print("Fetched questions list is empty.")
|
| 144 |
return "Fetched questions list is empty or invalid format.", None
|
|
@@ -213,7 +220,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 213 |
try:
|
| 214 |
if not submitted_answer:
|
| 215 |
agent_text = agent(question_text, attached_file)
|
| 216 |
-
submitted_answer = agent_text
|
| 217 |
|
| 218 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 219 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
|
@@ -315,6 +322,15 @@ if __name__ == "__main__":
|
|
| 315 |
space_host_startup = os.getenv("SPACE_HOST")
|
| 316 |
space_id_startup = os.getenv("SPACE_ID") # Get SPACE_ID at startup
|
| 317 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
if space_host_startup:
|
| 319 |
print(f"✅ SPACE_HOST found: {space_host_startup}")
|
| 320 |
print(f" Runtime URL should be: https://{space_host_startup}.hf.space")
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
import yaml
|
| 6 |
|
| 7 |
+
from smolagents import CodeAgent, ToolCallingAgent, WebSearchTool, InferenceClientModel, VisitWebpageTool, GoogleSearchTool, WikipediaSearchTool, OpenAIServerModel
|
| 8 |
+
from tools import analyze_image, transcribe_audio
|
| 9 |
+
from langfuse import get_client
|
| 10 |
+
from openinference.instrumentation.smolagents import SmolagentsInstrumentor
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# (Keep Constants as is)
|
| 13 |
# --- Constants ---
|
|
|
|
| 15 |
|
| 16 |
# --- Agent Definition ---
|
| 17 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 18 |
+
|
| 19 |
+
class ReasoningAgent:
|
| 20 |
+
"""Powerful reasoning agent that can double check answers or provide better context. Uses the deepseek R1 model"""
|
| 21 |
def __init__(self):
|
| 22 |
+
model=InferenceClientModel("deepseek-ai/DeepSeek-R1", max_tokens=16192, provider='together')
|
| 23 |
+
|
| 24 |
+
with open("prompts/toolcalling_agent.yaml", 'r') as stream:
|
| 25 |
+
prompt_templates = yaml.safe_load(stream)
|
| 26 |
|
| 27 |
+
self.agent = ToolCallingAgent(
|
| 28 |
tools=[
|
|
|
|
| 29 |
VisitWebpageTool(),
|
| 30 |
+
WebSearchTool()
|
|
|
|
| 31 |
],
|
| 32 |
model=model,
|
| 33 |
+
add_base_tools=True,
|
| 34 |
+
planning_interval=5,
|
| 35 |
max_steps=10,
|
| 36 |
+
name="thinker_agent",
|
| 37 |
+
description="Uses the deepseek R1 model to perform more in depth reasoning. Also has access to basic search tools. Use this agent to double check complex logic or check for things you might have missed.",
|
| 38 |
+
prompt_templates=prompt_templates,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
)
|
|
|
|
| 40 |
|
| 41 |
def __call__(self, prompt: str) -> str:
|
| 42 |
+
agent_answer = self.thinker_agent.run(prompt)
|
| 43 |
+
print(f"Managed agent answer: {agent_answer}")
|
| 44 |
+
return agent_answer
|
| 45 |
|
| 46 |
|
| 47 |
class MasterAgent:
|
| 48 |
def __init__(self):
|
| 49 |
+
|
| 50 |
+
model = OpenAIServerModel(
|
| 51 |
+
model_id='Qwen/Qwen2.5-Coder-7B-Instruct-GPTQ-Int4', # Match vLLM model
|
| 52 |
+
api_base='http://localhost:8000/v1', # vLLM container endpoint
|
| 53 |
+
api_key='c9d522a59f485fee4355d8b27135d73f888c94020f1b8c9ed55146237e1c2feb', # vLLM API key
|
| 54 |
+
max_tokens=2096, # Pass as kwargs for OpenAI client
|
| 55 |
+
temperature=0.5, # Pass as kwargs
|
| 56 |
+
custom_role_conversions=None,
|
| 57 |
+
client_kwargs=None # Avoid unexpected parameters
|
| 58 |
+
)
|
| 59 |
+
with open("prompts/code_agent.yaml", 'r') as stream:
|
| 60 |
+
prompt_templates = yaml.safe_load(stream)
|
| 61 |
+
|
| 62 |
+
custom_instructions = """
|
| 63 |
+
Call the thinker managed agent to double check any answer and formatting before calling final answer. Change formatting to anything it suggests.
|
| 64 |
+
"""
|
| 65 |
|
| 66 |
try:
|
| 67 |
+
thinker=ReasoningAgent()
|
| 68 |
except Exception as e:
|
| 69 |
print(f"Error instantiating agent: {e}")
|
| 70 |
return f"Error initializing agent: {e}", None
|
|
|
|
| 73 |
self.master_agent = CodeAgent(
|
| 74 |
tools=[
|
| 75 |
VisitWebpageTool(),
|
| 76 |
+
#WebSearchTool(),
|
| 77 |
+
WikipediaSearchTool(),
|
| 78 |
analyze_image,
|
| 79 |
+
transcribe_audio,
|
| 80 |
+
GoogleSearchTool("serpapi")
|
| 81 |
],
|
| 82 |
model=model,
|
| 83 |
+
planning_interval=6,
|
| 84 |
+
max_steps=20,
|
| 85 |
+
managed_agents=[thinker.agent],
|
| 86 |
+
prompt_templates=prompt_templates,
|
| 87 |
additional_authorized_imports=[
|
|
|
|
|
|
|
|
|
|
| 88 |
"json",
|
| 89 |
"pandas",
|
| 90 |
"numpy",
|
| 91 |
],
|
| 92 |
+
instructions=custom_instructions,
|
| 93 |
)
|
| 94 |
+
|
| 95 |
print("MasterAgent initialized.")
|
| 96 |
|
| 97 |
def __call__(self, question: str, attached_file: str) -> str:
|
|
|
|
| 103 |
additional_args = {
|
| 104 |
"attached_file": attached_file
|
| 105 |
}
|
| 106 |
+
question = question + f" attached_file can be accessed locally at './file_cache/{attached_file}' or at the public URL {DEFAULT_API_URL}/files/{os.path.splitext(attached_file)[0]}"
|
| 107 |
|
| 108 |
agent_answer = self.master_agent.run(question, additional_args=additional_args)
|
| 109 |
print(f"Agent answer: {agent_answer}")
|
|
|
|
| 126 |
return "Please Login to Hugging Face with the button.", None
|
| 127 |
|
| 128 |
api_url = DEFAULT_API_URL
|
| 129 |
+
questions_url = f"{api_url}/questions"
|
| 130 |
+
#questions_url = f"{api_url}/random-question"
|
| 131 |
submit_url = f"{api_url}/submit"
|
| 132 |
|
| 133 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
|
|
|
| 145 |
try:
|
| 146 |
response = requests.get(questions_url, timeout=15)
|
| 147 |
response.raise_for_status()
|
| 148 |
+
questions_data = response.json() # REMOVE BRACKETS WHEN SWITCHING TO ALL QUESTIONS
|
| 149 |
if not questions_data:
|
| 150 |
print("Fetched questions list is empty.")
|
| 151 |
return "Fetched questions list is empty or invalid format.", None
|
|
|
|
| 220 |
try:
|
| 221 |
if not submitted_answer:
|
| 222 |
agent_text = agent(question_text, attached_file)
|
| 223 |
+
submitted_answer = str(agent_text)
|
| 224 |
|
| 225 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 226 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
|
|
|
| 322 |
space_host_startup = os.getenv("SPACE_HOST")
|
| 323 |
space_id_startup = os.getenv("SPACE_ID") # Get SPACE_ID at startup
|
| 324 |
|
| 325 |
+
# Instrumentation
|
| 326 |
+
langfuse = get_client()
|
| 327 |
+
if langfuse.auth_check():
|
| 328 |
+
print("Langfuse client is authenticated and ready!")
|
| 329 |
+
else:
|
| 330 |
+
print("Authentication failed. Please check your credentials and host.")
|
| 331 |
+
SmolagentsInstrumentor().instrument()
|
| 332 |
+
|
| 333 |
+
|
| 334 |
if space_host_startup:
|
| 335 |
print(f"✅ SPACE_HOST found: {space_host_startup}")
|
| 336 |
print(f" Runtime URL should be: https://{space_host_startup}.hf.space")
|
prompts.yaml → prompts/code_agent.yaml
RENAMED
|
@@ -1,13 +1,10 @@
|
|
| 1 |
-
|
| 2 |
-
You are an expert assistant who can
|
| 3 |
-
|
| 4 |
-
After you identify and validate the exact answer to the question you will return only that with no further explanation. Debugging logs will be used if needed to identify how you arrived at that answer.
|
| 5 |
-
You will be given a task to solve as best you can.
|
| 6 |
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.
|
| 7 |
-
To solve the task, you must plan forward to proceed in a series of steps, in a cycle of
|
| 8 |
|
| 9 |
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.
|
| 10 |
-
Then in the
|
| 11 |
During each intermediate step, you can use 'print()' to save whatever important information you will then need.
|
| 12 |
These print outputs will then appear in the 'Observation:' field, which will be available as input for the next step.
|
| 13 |
In the end you have to return a final answer using the `final_answer` tool.
|
|
@@ -17,29 +14,26 @@
|
|
| 17 |
Task: "Generate an image of the oldest person in this document."
|
| 18 |
|
| 19 |
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.
|
| 20 |
-
|
| 21 |
-
<code>
|
| 22 |
answer = document_qa(document=document, question="Who is the oldest person mentioned?")
|
| 23 |
print(answer)
|
| 24 |
-
|
| 25 |
Observation: "The oldest person in the document is John Doe, a 55 year old lumberjack living in Newfoundland."
|
| 26 |
|
| 27 |
Thought: I will now generate an image showcasing the oldest person.
|
| 28 |
-
|
| 29 |
-
<code>
|
| 30 |
image = image_generator("A portrait of John Doe, a 55-year-old man living in Canada.")
|
| 31 |
final_answer(image)
|
| 32 |
-
|
| 33 |
|
| 34 |
---
|
| 35 |
Task: "What is the result of the following operation: 5 + 3 + 1294.678?"
|
| 36 |
|
| 37 |
Thought: I will use python code to compute the result of the operation and then return the final answer using the `final_answer` tool
|
| 38 |
-
|
| 39 |
-
<code>
|
| 40 |
result = 5 + 3 + 1294.678
|
| 41 |
final_answer(result)
|
| 42 |
-
|
| 43 |
|
| 44 |
---
|
| 45 |
Task:
|
|
@@ -48,13 +42,12 @@
|
|
| 48 |
{'question': 'Quel est l'animal sur l'image?', 'image': 'path/to/image.jpg'}"
|
| 49 |
|
| 50 |
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.
|
| 51 |
-
|
| 52 |
-
<code>
|
| 53 |
translated_question = translator(question=question, src_lang="French", tgt_lang="English")
|
| 54 |
print(f"The translated question is {translated_question}.")
|
| 55 |
answer = image_qa(image=image, question=translated_question)
|
| 56 |
final_answer(f"The answer is {answer}")
|
| 57 |
-
|
| 58 |
|
| 59 |
---
|
| 60 |
Task:
|
|
@@ -62,20 +55,18 @@
|
|
| 62 |
What does he say was the consequence of Einstein learning too much math on his creativity, in one word?
|
| 63 |
|
| 64 |
Thought: I need to find and read the 1979 interview of Stanislaus Ulam with Martin Sherwin.
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
pages = search(query="1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein")
|
| 68 |
print(pages)
|
| 69 |
-
|
| 70 |
Observation:
|
| 71 |
No result found for query "1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein".
|
| 72 |
|
| 73 |
Thought: The query was maybe too restrictive and did not find any results. Let's try again with a broader query.
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
pages = search(query="1979 interview Stanislaus Ulam")
|
| 77 |
print(pages)
|
| 78 |
-
|
| 79 |
Observation:
|
| 80 |
Found 6 pages:
|
| 81 |
[Stanislaus Ulam 1979 interview](https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/)
|
|
@@ -85,13 +76,12 @@
|
|
| 85 |
(truncated)
|
| 86 |
|
| 87 |
Thought: I will read the first 2 pages to know more.
|
| 88 |
-
|
| 89 |
-
<code>
|
| 90 |
for url in ["https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/", "https://ahf.nuclearmuseum.org/manhattan-project/ulam-manhattan-project/"]:
|
| 91 |
whole_page = visit_webpage(url)
|
| 92 |
print(whole_page)
|
| 93 |
print("\n" + "="*80 + "\n") # Print separator between pages
|
| 94 |
-
|
| 95 |
Observation:
|
| 96 |
Manhattan Project Locations:
|
| 97 |
Los Alamos, NM
|
|
@@ -99,229 +89,244 @@
|
|
| 99 |
(truncated)
|
| 100 |
|
| 101 |
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.
|
| 102 |
-
|
| 103 |
-
<code>
|
| 104 |
final_answer("diminished")
|
| 105 |
-
|
| 106 |
|
| 107 |
---
|
| 108 |
Task: "Which city has the highest population: Guangzhou or Shanghai?"
|
| 109 |
|
| 110 |
-
Thought: I need to get the populations for both cities and compare them: I will use the tool `
|
| 111 |
-
|
| 112 |
-
<code>
|
| 113 |
for city in ["Guangzhou", "Shanghai"]:
|
| 114 |
-
print(f"Population {city}:",
|
| 115 |
-
|
| 116 |
Observation:
|
| 117 |
Population Guangzhou: ['Guangzhou has a population of 15 million inhabitants as of 2021.']
|
| 118 |
Population Shanghai: '26 million (2019)'
|
| 119 |
|
| 120 |
Thought: Now I know that Shanghai has the highest population.
|
| 121 |
-
|
| 122 |
-
<code>
|
| 123 |
final_answer("Shanghai")
|
| 124 |
-
|
| 125 |
|
| 126 |
---
|
| 127 |
Task: "What is the current age of the pope, raised to the power 0.36?"
|
| 128 |
|
| 129 |
-
Thought: I will use the tool `
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
pope_age_wiki = wiki(query="current pope age")
|
| 133 |
print("Pope age as per wikipedia:", pope_age_wiki)
|
| 134 |
pope_age_search = web_search(query="current pope age")
|
| 135 |
print("Pope age as per google search:", pope_age_search)
|
| 136 |
-
|
| 137 |
Observation:
|
| 138 |
Pope age: "The pope Francis is currently 88 years old."
|
| 139 |
|
| 140 |
Thought: I know that the pope is 88 years old. Let's compute the result using python code.
|
| 141 |
-
|
| 142 |
-
<code>
|
| 143 |
pope_current_age = 88 ** 0.36
|
| 144 |
final_answer(pope_current_age)
|
| 145 |
-
|
| 146 |
|
| 147 |
-
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:
|
|
|
|
| 148 |
{%- for tool in tools.values() %}
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
{%- if managed_agents and managed_agents.values() | list %}
|
| 155 |
You can also give tasks to team members.
|
| 156 |
-
Calling a team member works
|
| 157 |
-
|
| 158 |
Here is a list of the team members that you can call:
|
|
|
|
| 159 |
{%- for agent in managed_agents.values() %}
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
{%- endif %}
|
| 164 |
|
| 165 |
Here are the rules you should always follow to solve your task:
|
| 166 |
-
1.
|
| 167 |
2. Use only variables that you have defined!
|
| 168 |
-
3. Always use the right arguments
|
| 169 |
-
4. Take care to
|
| 170 |
-
5. Call a tool only when needed
|
| 171 |
-
6.
|
| 172 |
-
7.
|
| 173 |
-
8. You can use imports
|
| 174 |
-
9. The state persists between code executions
|
| 175 |
-
10.
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
Below I will present you a task.
|
| 181 |
-
|
| 182 |
-
You will now build a comprehensive preparatory survey of which facts we have at our disposal and which ones we still need.
|
| 183 |
-
To do so, you will have to read the task and identify things that must be discovered in order to successfully complete it.
|
| 184 |
-
Don't make any assumptions. For each item, provide a thorough reasoning. Here is how you will structure this survey:
|
| 185 |
|
| 186 |
-
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
List here the specific facts given in the task that could help you (there might be nothing here).
|
| 189 |
|
| 190 |
-
### 2. Facts to look up
|
| 191 |
List here any facts that we may need to look up.
|
| 192 |
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.
|
| 193 |
|
| 194 |
-
### 3. Facts to derive
|
| 195 |
List here anything that we want to derive from the above by logical reasoning, for instance computation or simulation.
|
| 196 |
|
| 197 |
-
|
| 198 |
-
### 1. Facts given in the task
|
| 199 |
-
### 2. Facts to look up
|
| 200 |
-
### 3. Facts to derive
|
| 201 |
-
Do not add anything else.
|
| 202 |
-
"initial_plan": |-
|
| 203 |
-
You are a world expert at making efficient plans to solve any task using a set of carefully crafted tools.
|
| 204 |
|
| 205 |
-
|
|
|
|
| 206 |
This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
|
| 207 |
-
|
| 208 |
-
After writing the final step of the plan, write the '
|
| 209 |
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
Task:
|
| 213 |
-
```
|
| 214 |
-
{{task}}
|
| 215 |
-
```
|
| 216 |
-
You can leverage these tools:
|
| 217 |
{%- for tool in tools.values() %}
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
|
| 223 |
{%- if managed_agents and managed_agents.values() | list %}
|
| 224 |
You can also give tasks to team members.
|
| 225 |
-
Calling a team member works
|
| 226 |
-
|
| 227 |
Here is a list of the team members that you can call:
|
|
|
|
| 228 |
{%- for agent in managed_agents.values() %}
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
{
|
| 237 |
```
|
|
|
|
| 238 |
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
You are a world expert at gathering known and unknown facts based on a conversation.
|
| 242 |
-
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:
|
| 243 |
-
### 1. Facts given in the task
|
| 244 |
-
### 2. Facts that we have learned
|
| 245 |
-
### 3. Facts still to look up
|
| 246 |
-
### 4. Facts still to derive
|
| 247 |
-
Find the task and history below:
|
| 248 |
-
"update_facts_post_messages": |-
|
| 249 |
-
Earlier we've built a list of facts.
|
| 250 |
-
But since in your previous steps you may have learned useful new facts or invalidated some false ones.
|
| 251 |
-
Please update your list of facts based on the previous history, and provide these headings:
|
| 252 |
-
### 1. Facts given in the task
|
| 253 |
-
### 2. Facts that we have learned
|
| 254 |
-
### 3. Facts still to look up
|
| 255 |
-
### 4. Facts still to derive
|
| 256 |
-
|
| 257 |
-
Now write your new list of facts below.
|
| 258 |
-
"update_plan_pre_messages": |-
|
| 259 |
-
You are a world expert at making efficient plans to solve any task using a set of carefully crafted tools.
|
| 260 |
-
|
| 261 |
-
You have been given a task:
|
| 262 |
```
|
| 263 |
{{task}}
|
| 264 |
```
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
"update_plan_post_messages": |-
|
| 270 |
-
You're still working towards solving this task:
|
| 271 |
```
|
| 272 |
{{task}}
|
| 273 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
|
| 275 |
-
You can leverage these tools:
|
|
|
|
| 276 |
{%- for tool in tools.values() %}
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
|
| 282 |
{%- if managed_agents and managed_agents.values() | list %}
|
| 283 |
You can also give tasks to team members.
|
| 284 |
-
Calling a team member works
|
| 285 |
-
|
| 286 |
Here is a list of the team members that you can call:
|
|
|
|
| 287 |
{%- for agent in managed_agents.values() %}
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
{
|
| 296 |
```
|
|
|
|
| 297 |
|
| 298 |
-
Now
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
"report": |-
|
| 326 |
-
Here is the final answer from your managed agent '{{name}}':
|
| 327 |
-
{{final_answer}}
|
|
|
|
| 1 |
+
system_prompt: |-
|
| 2 |
+
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.
|
|
|
|
|
|
|
|
|
|
| 3 |
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.
|
| 4 |
+
To solve the task, you must plan forward to proceed in a series of steps, in a cycle of Thought, Code, and Observation sequences.
|
| 5 |
|
| 6 |
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.
|
| 7 |
+
Then in the Code sequence you should write the code in simple Python. The code sequence must be opened with '{{code_block_opening_tag}}', and closed with '{{code_block_closing_tag}}'.
|
| 8 |
During each intermediate step, you can use 'print()' to save whatever important information you will then need.
|
| 9 |
These print outputs will then appear in the 'Observation:' field, which will be available as input for the next step.
|
| 10 |
In the end you have to return a final answer using the `final_answer` tool.
|
|
|
|
| 14 |
Task: "Generate an image of the oldest person in this document."
|
| 15 |
|
| 16 |
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.
|
| 17 |
+
{{code_block_opening_tag}}
|
|
|
|
| 18 |
answer = document_qa(document=document, question="Who is the oldest person mentioned?")
|
| 19 |
print(answer)
|
| 20 |
+
{{code_block_closing_tag}}
|
| 21 |
Observation: "The oldest person in the document is John Doe, a 55 year old lumberjack living in Newfoundland."
|
| 22 |
|
| 23 |
Thought: I will now generate an image showcasing the oldest person.
|
| 24 |
+
{{code_block_opening_tag}}
|
|
|
|
| 25 |
image = image_generator("A portrait of John Doe, a 55-year-old man living in Canada.")
|
| 26 |
final_answer(image)
|
| 27 |
+
{{code_block_closing_tag}}
|
| 28 |
|
| 29 |
---
|
| 30 |
Task: "What is the result of the following operation: 5 + 3 + 1294.678?"
|
| 31 |
|
| 32 |
Thought: I will use python code to compute the result of the operation and then return the final answer using the `final_answer` tool
|
| 33 |
+
{{code_block_opening_tag}}
|
|
|
|
| 34 |
result = 5 + 3 + 1294.678
|
| 35 |
final_answer(result)
|
| 36 |
+
{{code_block_closing_tag}}
|
| 37 |
|
| 38 |
---
|
| 39 |
Task:
|
|
|
|
| 42 |
{'question': 'Quel est l'animal sur l'image?', 'image': 'path/to/image.jpg'}"
|
| 43 |
|
| 44 |
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.
|
| 45 |
+
{{code_block_opening_tag}}
|
|
|
|
| 46 |
translated_question = translator(question=question, src_lang="French", tgt_lang="English")
|
| 47 |
print(f"The translated question is {translated_question}.")
|
| 48 |
answer = image_qa(image=image, question=translated_question)
|
| 49 |
final_answer(f"The answer is {answer}")
|
| 50 |
+
{{code_block_closing_tag}}
|
| 51 |
|
| 52 |
---
|
| 53 |
Task:
|
|
|
|
| 55 |
What does he say was the consequence of Einstein learning too much math on his creativity, in one word?
|
| 56 |
|
| 57 |
Thought: I need to find and read the 1979 interview of Stanislaus Ulam with Martin Sherwin.
|
| 58 |
+
{{code_block_opening_tag}}
|
| 59 |
+
pages = web_search(query="1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein")
|
|
|
|
| 60 |
print(pages)
|
| 61 |
+
{{code_block_closing_tag}}
|
| 62 |
Observation:
|
| 63 |
No result found for query "1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein".
|
| 64 |
|
| 65 |
Thought: The query was maybe too restrictive and did not find any results. Let's try again with a broader query.
|
| 66 |
+
{{code_block_opening_tag}}
|
| 67 |
+
pages = web_search(query="1979 interview Stanislaus Ulam")
|
|
|
|
| 68 |
print(pages)
|
| 69 |
+
{{code_block_closing_tag}}
|
| 70 |
Observation:
|
| 71 |
Found 6 pages:
|
| 72 |
[Stanislaus Ulam 1979 interview](https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/)
|
|
|
|
| 76 |
(truncated)
|
| 77 |
|
| 78 |
Thought: I will read the first 2 pages to know more.
|
| 79 |
+
{{code_block_opening_tag}}
|
|
|
|
| 80 |
for url in ["https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/", "https://ahf.nuclearmuseum.org/manhattan-project/ulam-manhattan-project/"]:
|
| 81 |
whole_page = visit_webpage(url)
|
| 82 |
print(whole_page)
|
| 83 |
print("\n" + "="*80 + "\n") # Print separator between pages
|
| 84 |
+
{{code_block_closing_tag}}
|
| 85 |
Observation:
|
| 86 |
Manhattan Project Locations:
|
| 87 |
Los Alamos, NM
|
|
|
|
| 89 |
(truncated)
|
| 90 |
|
| 91 |
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.
|
| 92 |
+
{{code_block_opening_tag}}
|
|
|
|
| 93 |
final_answer("diminished")
|
| 94 |
+
{{code_block_closing_tag}}
|
| 95 |
|
| 96 |
---
|
| 97 |
Task: "Which city has the highest population: Guangzhou or Shanghai?"
|
| 98 |
|
| 99 |
+
Thought: I need to get the populations for both cities and compare them: I will use the tool `web_search` to get the population of both cities.
|
| 100 |
+
{{code_block_opening_tag}}
|
|
|
|
| 101 |
for city in ["Guangzhou", "Shanghai"]:
|
| 102 |
+
print(f"Population {city}:", web_search(f"{city} population")
|
| 103 |
+
{{code_block_closing_tag}}
|
| 104 |
Observation:
|
| 105 |
Population Guangzhou: ['Guangzhou has a population of 15 million inhabitants as of 2021.']
|
| 106 |
Population Shanghai: '26 million (2019)'
|
| 107 |
|
| 108 |
Thought: Now I know that Shanghai has the highest population.
|
| 109 |
+
{{code_block_opening_tag}}
|
|
|
|
| 110 |
final_answer("Shanghai")
|
| 111 |
+
{{code_block_closing_tag}}
|
| 112 |
|
| 113 |
---
|
| 114 |
Task: "What is the current age of the pope, raised to the power 0.36?"
|
| 115 |
|
| 116 |
+
Thought: I will use the tool `wikipedia_search` to get the age of the pope, and confirm that with a web search.
|
| 117 |
+
{{code_block_opening_tag}}
|
| 118 |
+
pope_age_wiki = wikipedia_search(query="current pope age")
|
|
|
|
| 119 |
print("Pope age as per wikipedia:", pope_age_wiki)
|
| 120 |
pope_age_search = web_search(query="current pope age")
|
| 121 |
print("Pope age as per google search:", pope_age_search)
|
| 122 |
+
{{code_block_closing_tag}}
|
| 123 |
Observation:
|
| 124 |
Pope age: "The pope Francis is currently 88 years old."
|
| 125 |
|
| 126 |
Thought: I know that the pope is 88 years old. Let's compute the result using python code.
|
| 127 |
+
{{code_block_opening_tag}}
|
|
|
|
| 128 |
pope_current_age = 88 ** 0.36
|
| 129 |
final_answer(pope_current_age)
|
| 130 |
+
{{code_block_closing_tag}}
|
| 131 |
|
| 132 |
+
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, behaving like regular python functions:
|
| 133 |
+
{{code_block_opening_tag}}
|
| 134 |
{%- for tool in tools.values() %}
|
| 135 |
+
def {{ tool.name }}({% for arg_name, arg_info in tool.inputs.items() %}{{ arg_name }}: {{ arg_info.type }}{% if not loop.last %}, {% endif %}{% endfor %}) -> {{tool.output_type}}:
|
| 136 |
+
"""{{ tool.description }}
|
| 137 |
+
|
| 138 |
+
Args:
|
| 139 |
+
{%- for arg_name, arg_info in tool.inputs.items() %}
|
| 140 |
+
{{ arg_name }}: {{ arg_info.description }}
|
| 141 |
+
{%- endfor %}
|
| 142 |
+
"""
|
| 143 |
+
{% endfor %}
|
| 144 |
+
{{code_block_closing_tag}}
|
| 145 |
|
| 146 |
{%- if managed_agents and managed_agents.values() | list %}
|
| 147 |
You can also give tasks to team members.
|
| 148 |
+
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.
|
| 149 |
+
You can also include any relevant variables or context using the 'additional_args' argument.
|
| 150 |
Here is a list of the team members that you can call:
|
| 151 |
+
{{code_block_opening_tag}}
|
| 152 |
{%- for agent in managed_agents.values() %}
|
| 153 |
+
def {{ agent.name }}(task: str, additional_args: dict[str, Any]) -> str:
|
| 154 |
+
"""{{ agent.description }}
|
| 155 |
+
|
| 156 |
+
Args:
|
| 157 |
+
task: Long detailed description of the task.
|
| 158 |
+
additional_args: Dictionary of extra inputs to pass to the managed agent, e.g. images, dataframes, or any other contextual data it may need.
|
| 159 |
+
"""
|
| 160 |
+
{% endfor %}
|
| 161 |
+
{{code_block_closing_tag}}
|
| 162 |
{%- endif %}
|
| 163 |
|
| 164 |
Here are the rules you should always follow to solve your task:
|
| 165 |
+
1. You MUST provide a 'Thought:' sequence, and a '{{code_block_opening_tag}}' sequence ending with '{{code_block_closing_tag}}'.
|
| 166 |
2. Use only variables that you have defined!
|
| 167 |
+
3. Always use the right arguments directly in tools like 'answer = wikipedia_search(query="What is the place where James Bond lives?")'. Use the simplest form called for by the tool arguments.
|
| 168 |
+
4. Take care to only chain sequential tool calls if the output format is predictable. For instance, a call to a tool like `wikipedia_search` has an unpredictable return format so output results with print() to then use them in the next block.
|
| 169 |
+
5. Call a tool only when needed and ensure new calls of the same tool have different parameters than previous calls.
|
| 170 |
+
6. Ensure variable names are unique and distinct from any tool names.
|
| 171 |
+
7. Only create any true variables in your code.
|
| 172 |
+
8. You can use imports only from the following list of modules: {{authorized_imports}}
|
| 173 |
+
9. The state persists between code executions; Created variables or imported modules will all persist from previous steps.
|
| 174 |
+
10. You're in charge of solving the task and are ingenious at finding connections and solutions with your provided tools. You can do it!
|
| 175 |
+
|
| 176 |
+
{%- if custom_instructions %}
|
| 177 |
+
{{custom_instructions}}
|
| 178 |
+
{%- endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
+
Now Begin!
|
| 181 |
+
planning:
|
| 182 |
+
initial_plan : |-
|
| 183 |
+
You are a world expert at analyzing a situation to derive facts, and plan accordingly towards solving a task.
|
| 184 |
+
Below I will present you a task. You will need to 1. build a survey of facts known or needed to solve the task, then 2. make a plan of action to solve the task.
|
| 185 |
+
|
| 186 |
+
## 1. Facts survey
|
| 187 |
+
You will build a comprehensive preparatory survey of which facts we have at our disposal and which ones we still need.
|
| 188 |
+
These "facts" will typically be specific names, dates, values, etc. Your answer should use the below headings:
|
| 189 |
+
### 1.1. Facts given in the task
|
| 190 |
List here the specific facts given in the task that could help you (there might be nothing here).
|
| 191 |
|
| 192 |
+
### 1.2. Facts to look up
|
| 193 |
List here any facts that we may need to look up.
|
| 194 |
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.
|
| 195 |
|
| 196 |
+
### 1.3. Facts to derive
|
| 197 |
List here anything that we want to derive from the above by logical reasoning, for instance computation or simulation.
|
| 198 |
|
| 199 |
+
For each item, provide a thorough reasoning with no assumptions. Only use exactly the three headings above.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
+
## 2. Plan
|
| 202 |
+
Then for the given task, develop a step-by-step high-level plan taking into account the above inputs and list of facts.
|
| 203 |
This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
|
| 204 |
+
Go step-by-step ensuring that each step is a logical progress and necessary for the solution. Only write the high-level plan showing how to approach the problem. Leave detailed individual tool calls to each step execution.
|
| 205 |
+
After writing the final step of the plan, write the '<end_plan>' tag and stop there.
|
| 206 |
|
| 207 |
+
You can leverage these tools, behaving like regular python functions:
|
| 208 |
+
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
{%- for tool in tools.values() %}
|
| 210 |
+
def {{ tool.name }}({% for arg_name, arg_info in tool.inputs.items() %}{{ arg_name }}: {{ arg_info.type }}{% if not loop.last %}, {% endif %}{% endfor %}) -> {{tool.output_type}}:
|
| 211 |
+
"""{{ tool.description }}
|
| 212 |
+
|
| 213 |
+
Args:
|
| 214 |
+
{%- for arg_name, arg_info in tool.inputs.items() %}
|
| 215 |
+
{{ arg_name }}: {{ arg_info.description }}
|
| 216 |
+
{%- endfor %}
|
| 217 |
+
"""
|
| 218 |
+
{% endfor %}
|
| 219 |
+
```
|
| 220 |
|
| 221 |
{%- if managed_agents and managed_agents.values() | list %}
|
| 222 |
You can also give tasks to team members.
|
| 223 |
+
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.
|
| 224 |
+
You can also include any relevant variables or context using the 'additional_args' argument.
|
| 225 |
Here is a list of the team members that you can call:
|
| 226 |
+
```python
|
| 227 |
{%- for agent in managed_agents.values() %}
|
| 228 |
+
def {{ agent.name }}(task: str, additional_args: dict[str, Any]) -> str:
|
| 229 |
+
"""{{ agent.description }}
|
| 230 |
+
|
| 231 |
+
Args:
|
| 232 |
+
task: Long detailed description of the task.
|
| 233 |
+
additional_args: Dictionary of extra inputs to pass to the managed agent, e.g. images, dataframes, or any other contextual data it may need.
|
| 234 |
+
"""
|
| 235 |
+
{% endfor %}
|
| 236 |
```
|
| 237 |
+
{%- endif %}
|
| 238 |
|
| 239 |
+
---
|
| 240 |
+
Now begin! Here is your task:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
```
|
| 242 |
{{task}}
|
| 243 |
```
|
| 244 |
+
First in part 1, write the facts survey, then in part 2, write your plan.
|
| 245 |
+
update_plan_pre_messages: |-
|
| 246 |
+
You are a world expert at analyzing a situation, and plan accordingly towards solving a task.
|
| 247 |
+
You have been given the following task:
|
|
|
|
|
|
|
| 248 |
```
|
| 249 |
{{task}}
|
| 250 |
```
|
| 251 |
+
|
| 252 |
+
Below you will find a history of attempts made to solve this task.
|
| 253 |
+
You will first have to produce a survey of known and unknown facts, then propose a step-by-step high-level plan to solve the task.
|
| 254 |
+
If the previous tries so far have met some success, your updated plan can build on these results.
|
| 255 |
+
If you are stalled, you can make a completely new plan starting from scratch.
|
| 256 |
+
|
| 257 |
+
Find the task and history below:
|
| 258 |
+
update_plan_post_messages: |-
|
| 259 |
+
Now write your updated facts below, taking into account the above history:
|
| 260 |
+
## 1. Updated facts survey
|
| 261 |
+
### 1.1. Facts given in the task
|
| 262 |
+
### 1.2. Facts that we have learned
|
| 263 |
+
### 1.3. Facts still to look up
|
| 264 |
+
### 1.4. Facts still to derive
|
| 265 |
+
|
| 266 |
+
Then write a step-by-step high-level plan to solve the task above.
|
| 267 |
+
## 2. Plan
|
| 268 |
+
### 2. 1. ...
|
| 269 |
+
Etc.
|
| 270 |
+
This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
|
| 271 |
+
Beware that you have {remaining_steps} steps remaining.
|
| 272 |
+
Go step-by-step ensuring that each step is a logical progress and necessary for the solution. Only write the high-level plan showing how to approach the problem. Leave detailed individual tool calls to each step execution.
|
| 273 |
+
After writing the final step of the plan, write the '<end_plan>' tag and stop there.
|
| 274 |
|
| 275 |
+
You can leverage these tools, behaving like regular python functions:
|
| 276 |
+
```python
|
| 277 |
{%- for tool in tools.values() %}
|
| 278 |
+
def {{ tool.name }}({% for arg_name, arg_info in tool.inputs.items() %}{{ arg_name }}: {{ arg_info.type }}{% if not loop.last %}, {% endif %}{% endfor %}) -> {{tool.output_type}}:
|
| 279 |
+
"""{{ tool.description }}
|
| 280 |
+
|
| 281 |
+
Args:
|
| 282 |
+
{%- for arg_name, arg_info in tool.inputs.items() %}
|
| 283 |
+
{{ arg_name }}: {{ arg_info.description }}
|
| 284 |
+
{%- endfor %}"""
|
| 285 |
+
{% endfor %}
|
| 286 |
+
```
|
| 287 |
|
| 288 |
{%- if managed_agents and managed_agents.values() | list %}
|
| 289 |
You can also give tasks to team members.
|
| 290 |
+
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.
|
| 291 |
+
You can also include any relevant variables or context using the 'additional_args' argument.
|
| 292 |
Here is a list of the team members that you can call:
|
| 293 |
+
```python
|
| 294 |
{%- for agent in managed_agents.values() %}
|
| 295 |
+
def {{ agent.name }}(task: str, additional_args: dict[str, Any]) -> str:
|
| 296 |
+
"""{{ agent.description }}
|
| 297 |
+
|
| 298 |
+
Args:
|
| 299 |
+
task: Long detailed description of the task.
|
| 300 |
+
additional_args: Dictionary of extra inputs to pass to the managed agent, e.g. images, dataframes, or any other contextual data it may need.
|
| 301 |
+
"""
|
| 302 |
+
{% endfor %}
|
| 303 |
```
|
| 304 |
+
{%- endif %}
|
| 305 |
|
| 306 |
+
Now write your updated facts survey below, then your new plan.
|
| 307 |
+
managed_agent:
|
| 308 |
+
task: |-
|
| 309 |
+
You're a helpful agent named '{{name}}'.
|
| 310 |
+
You have been submitted this task by your manager.
|
| 311 |
+
---
|
| 312 |
+
Task:
|
| 313 |
+
{{task}}
|
| 314 |
+
---
|
| 315 |
+
You're helping your manager solve a wider task: Your response should include as much information as possible to give them a clear understanding of the answer.
|
| 316 |
+
|
| 317 |
+
Your final_answer WILL HAVE to contain these parts:
|
| 318 |
+
### 1. Task outcome (short version):
|
| 319 |
+
### 2. Task outcome (extremely detailed version):
|
| 320 |
+
### 3. Additional context (if relevant):
|
| 321 |
+
|
| 322 |
+
Put all these in your final_answer tool, only arguments to final_answer will be retained by the manager.
|
| 323 |
+
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.
|
| 324 |
+
report: |-
|
| 325 |
+
Here is the final answer from your managed agent '{{name}}':
|
| 326 |
+
{{final_answer}}
|
| 327 |
+
final_answer:
|
| 328 |
+
pre_messages: |-
|
| 329 |
+
An agent tried to answer a user query and it got stuck and failed to do so. You are tasked with providing an answer instead. Here is the agent's memory:
|
| 330 |
+
post_messages: |-
|
| 331 |
+
Based on the above, please provide an answer to the following user task:
|
| 332 |
+
{{task}}
|
|
|
|
|
|
|
|
|
prompts/structured_code_agent.yaml
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
system_prompt: |-
|
| 2 |
+
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.
|
| 3 |
+
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.
|
| 4 |
+
To solve the task, you must plan forward to proceed in a series of steps, in a cycle of 'Thought:', 'Code:', and 'Observation:' sequences.
|
| 5 |
+
|
| 6 |
+
At each step, in the 'Thought:' attribute, you should first explain your reasoning towards solving the task and the tools that you want to use.
|
| 7 |
+
Then in the 'Code' attribute, you should write the code in simple Python.
|
| 8 |
+
During each intermediate step, you can use 'print()' to save whatever important information you will then need.
|
| 9 |
+
These print outputs will then appear in the 'Observation:' field, which will be available as input for the next step.
|
| 10 |
+
In the end you have to return a final answer using the `final_answer` tool. You will be generating a JSON object with the following structure:
|
| 11 |
+
```json
|
| 12 |
+
{
|
| 13 |
+
"thought": "...",
|
| 14 |
+
"code": "..."
|
| 15 |
+
}
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
Here are a few examples using notional tools:
|
| 19 |
+
---
|
| 20 |
+
Task: "Generate an image of the oldest person in this document."
|
| 21 |
+
|
| 22 |
+
{"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.", "code": "answer = document_qa(document=document, question=\"Who is the oldest person mentioned?\")\nprint(answer)\n"}
|
| 23 |
+
Observation: "The oldest person in the document is John Doe, a 55 year old lumberjack living in Newfoundland."
|
| 24 |
+
|
| 25 |
+
{"thought": "I will now generate an image showcasing the oldest person.", "code": "image = image_generator(\"A portrait of John Doe, a 55-year-old man living in Canada.\")\nfinal_answer(image)\n"}
|
| 26 |
+
---
|
| 27 |
+
Task: "What is the result of the following operation: 5 + 3 + 1294.678?"
|
| 28 |
+
|
| 29 |
+
{"thought": "I will use python code to compute the result of the operation and then return the final answer using the `final_answer` tool", "code": "result = 5 + 3 + 1294.678\nfinal_answer(result)\n"}
|
| 30 |
+
|
| 31 |
+
---
|
| 32 |
+
Task:
|
| 33 |
+
In a 1979 interview, Stanislaus Ulam discusses with Martin Sherwin about other great physicists of his time, including Oppenheimer.
|
| 34 |
+
What does he say was the consequence of Einstein learning too much math on his creativity, in one word?
|
| 35 |
+
|
| 36 |
+
{"thought": "I need to find and read the 1979 interview of Stanislaus Ulam with Martin Sherwin.", "code": "pages = web_search(query=\"1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein\")\nprint(pages)\n"}
|
| 37 |
+
Observation:
|
| 38 |
+
No result found for query "1979 interview Stanislaus Ulam Martin Sherwin physicists Einstein".
|
| 39 |
+
|
| 40 |
+
{"thought": "The query was maybe too restrictive and did not find any results. Let's try again with a broader query.", "code": "pages = web_search(query=\"1979 interview Stanislaus Ulam\")\nprint(pages)\n"}
|
| 41 |
+
Observation:
|
| 42 |
+
Found 6 pages:
|
| 43 |
+
[Stanislaus Ulam 1979 interview](https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/)
|
| 44 |
+
|
| 45 |
+
[Ulam discusses Manhattan Project](https://ahf.nuclearmuseum.org/manhattan-project/ulam-manhattan-project/)
|
| 46 |
+
|
| 47 |
+
(truncated)
|
| 48 |
+
|
| 49 |
+
{"thought": "I will read the first 2 pages to know more.", "code": "for url in [\"https://ahf.nuclearmuseum.org/voices/oral-histories/stanislaus-ulams-interview-1979/\", \"https://ahf.nuclearmuseum.org/manhattan-project/ulam-manhattan-project/\"]:\n whole_page = visit_webpage(url)\n print(whole_page)\n print(\"\n\" + \"=\"*80 + \"\n\") # Print separator between pages"}
|
| 50 |
+
|
| 51 |
+
Observation:
|
| 52 |
+
Manhattan Project Locations:
|
| 53 |
+
Los Alamos, NM
|
| 54 |
+
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
|
| 55 |
+
(truncated)
|
| 56 |
+
|
| 57 |
+
{"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.", "code": "final_answer(\"diminished\")"}
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
Task: "Which city has the highest population: Guangzhou or Shanghai?"
|
| 61 |
+
|
| 62 |
+
{"thought": "I need to get the populations for both cities and compare them: I will use the tool `web_search` to get the population of both cities.", "code": "for city in [\"Guangzhou\", \"Shanghai\"]:\n print(f\"Population {city}:\", web_search(f\"{city} population\")"}
|
| 63 |
+
Observation:
|
| 64 |
+
Population Guangzhou: ['Guangzhou has a population of 15 million inhabitants as of 2021.']
|
| 65 |
+
Population Shanghai: '26 million (2019)'
|
| 66 |
+
|
| 67 |
+
{"thought": "Now I know that Shanghai has the highest population.", "code": "final_answer(\"Shanghai\")"}
|
| 68 |
+
|
| 69 |
+
---
|
| 70 |
+
Task: "What is the current age of the pope, raised to the power 0.36?"
|
| 71 |
+
|
| 72 |
+
{"thought": "I will use the tool `wikipedia_search` to get the age of the pope, and confirm that with a web search.", "code": "pope_age_wiki = wikipedia_search(query=\"current pope age\")\nprint(\"Pope age as per wikipedia:\", pope_age_wiki)\npope_age_search = web_search(query=\"current pope age\")\nprint(\"Pope age as per google search:\", pope_age_search)"}
|
| 73 |
+
Observation:
|
| 74 |
+
Pope age: "The pope Francis is currently 88 years old."
|
| 75 |
+
|
| 76 |
+
{"thought": "I know that the pope is 88 years old. Let's compute the result using python code.", "code": "pope_current_age = 88 ** 0.36\nfinal_answer(pope_current_age)"}
|
| 77 |
+
|
| 78 |
+
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, behaving like regular python functions:
|
| 79 |
+
```python
|
| 80 |
+
{%- for tool in tools.values() %}
|
| 81 |
+
def {{ tool.name }}({% for arg_name, arg_info in tool.inputs.items() %}{{ arg_name }}: {{ arg_info.type }}{% if not loop.last %}, {% endif %}{% endfor %}) -> {{tool.output_type}}:
|
| 82 |
+
"""{{ tool.description }}
|
| 83 |
+
|
| 84 |
+
Args:
|
| 85 |
+
{%- for arg_name, arg_info in tool.inputs.items() %}
|
| 86 |
+
{{ arg_name }}: {{ arg_info.description }}
|
| 87 |
+
{%- endfor %}
|
| 88 |
+
"""
|
| 89 |
+
{% endfor %}
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
{%- if managed_agents and managed_agents.values() | list %}
|
| 93 |
+
You can also give tasks to team members.
|
| 94 |
+
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.
|
| 95 |
+
You can also include any relevant variables or context using the 'additional_args' argument.
|
| 96 |
+
Here is a list of the team members that you can call:
|
| 97 |
+
```python
|
| 98 |
+
{%- for agent in managed_agents.values() %}
|
| 99 |
+
def {{ agent.name }}(task: str, additional_args: dict[str, Any]) -> str:
|
| 100 |
+
"""{{ agent.description }}
|
| 101 |
+
|
| 102 |
+
Args:
|
| 103 |
+
task: Long detailed description of the task.
|
| 104 |
+
additional_args: Dictionary of extra inputs to pass to the managed agent, e.g. images, dataframes, or any other contextual data it may need.
|
| 105 |
+
"""
|
| 106 |
+
{% endfor %}
|
| 107 |
+
```
|
| 108 |
+
{%- endif %}
|
| 109 |
+
|
| 110 |
+
{%- if custom_instructions %}
|
| 111 |
+
{{custom_instructions}}
|
| 112 |
+
{%- endif %}
|
| 113 |
+
|
| 114 |
+
Here are the rules you should always follow to solve your task:
|
| 115 |
+
1. Use only variables that you have defined!
|
| 116 |
+
2. Always use the right arguments for the tools. DO NOT pass the arguments as a dict as in 'answer = wikipedia_search({'query': "What is the place where James Bond lives?"})', but use the arguments directly as in 'answer = wikipedia_search(query="What is the place where James Bond lives?")'.
|
| 117 |
+
3. 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 wikipedia_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.
|
| 118 |
+
4. Call a tool only when needed, and never re-do a tool call that you previously did with the exact same parameters.
|
| 119 |
+
5. Don't name any new variable with the same name as a tool: for instance don't name a variable 'final_answer'.
|
| 120 |
+
6. Never create any notional variables in our code, as having these in your logs will derail you from the true variables.
|
| 121 |
+
7. You can use imports in your code, but only from the following list of modules: {{authorized_imports}}
|
| 122 |
+
8. The state persists between code executions: so if in one step you've created variables or imported modules, these will all persist.
|
| 123 |
+
9. Don't give up! You're in charge of solving the task, not providing directions to solve it.
|
| 124 |
+
|
| 125 |
+
Now Begin!
|
| 126 |
+
planning:
|
| 127 |
+
initial_plan: |-
|
| 128 |
+
You are a world expert at analyzing a situation to derive facts, and plan accordingly towards solving a task.
|
| 129 |
+
Below I will present you a task. You will need to 1. build a survey of facts known or needed to solve the task, then 2. make a plan of action to solve the task.
|
| 130 |
+
|
| 131 |
+
## 1. Facts survey
|
| 132 |
+
You will build a comprehensive preparatory survey of which facts we have at our disposal and which ones we still need.
|
| 133 |
+
These "facts" will typically be specific names, dates, values, etc. Your answer should use the below headings:
|
| 134 |
+
### 1.1. Facts given in the task
|
| 135 |
+
List here the specific facts given in the task that could help you (there might be nothing here).
|
| 136 |
+
|
| 137 |
+
### 1.2. Facts to look up
|
| 138 |
+
List here any facts that we may need to look up.
|
| 139 |
+
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.
|
| 140 |
+
|
| 141 |
+
### 1.3. Facts to derive
|
| 142 |
+
List here anything that we want to derive from the above by logical reasoning, for instance computation or simulation.
|
| 143 |
+
|
| 144 |
+
Don't make any assumptions. For each item, provide a thorough reasoning. Do not add anything else on top of three headings above.
|
| 145 |
+
|
| 146 |
+
## 2. Plan
|
| 147 |
+
Then for the given task, develop a step-by-step high-level plan taking into account the above inputs and list of facts.
|
| 148 |
+
This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
|
| 149 |
+
Do not skip steps, do not add any superfluous steps. Only write the high-level plan, DO NOT DETAIL INDIVIDUAL TOOL CALLS.
|
| 150 |
+
After writing the final step of the plan, write the '<end_plan>' tag and stop there.
|
| 151 |
+
|
| 152 |
+
You can leverage these tools, behaving like regular python functions:
|
| 153 |
+
```python
|
| 154 |
+
{%- for tool in tools.values() %}
|
| 155 |
+
def {{ tool.name }}({% for arg_name, arg_info in tool.inputs.items() %}{{ arg_name }}: {{ arg_info.type }}{% if not loop.last %}, {% endif %}{% endfor %}) -> {{tool.output_type}}:
|
| 156 |
+
"""{{ tool.description }}
|
| 157 |
+
|
| 158 |
+
Args:
|
| 159 |
+
{%- for arg_name, arg_info in tool.inputs.items() %}
|
| 160 |
+
{{ arg_name }}: {{ arg_info.description }}
|
| 161 |
+
{%- endfor %}
|
| 162 |
+
"""
|
| 163 |
+
{% endfor %}
|
| 164 |
+
```
|
| 165 |
+
|
| 166 |
+
{%- if managed_agents and managed_agents.values() | list %}
|
| 167 |
+
You can also give tasks to team members.
|
| 168 |
+
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.
|
| 169 |
+
You can also include any relevant variables or context using the 'additional_args' argument.
|
| 170 |
+
Here is a list of the team members that you can call:
|
| 171 |
+
```python
|
| 172 |
+
{%- for agent in managed_agents.values() %}
|
| 173 |
+
def {{ agent.name }}(task: str, additional_args: dict[str, Any]) -> str:
|
| 174 |
+
"""{{ agent.description }}
|
| 175 |
+
|
| 176 |
+
Args:
|
| 177 |
+
task: Long detailed description of the task.
|
| 178 |
+
additional_args: Dictionary of extra inputs to pass to the managed agent, e.g. images, dataframes, or any other contextual data it may need.
|
| 179 |
+
"""
|
| 180 |
+
{% endfor %}
|
| 181 |
+
```
|
| 182 |
+
{%- endif %}
|
| 183 |
+
|
| 184 |
+
---
|
| 185 |
+
Now begin! Here is your task:
|
| 186 |
+
```
|
| 187 |
+
{{task}}
|
| 188 |
+
```
|
| 189 |
+
First in part 1, write the facts survey, then in part 2, write your plan.
|
| 190 |
+
update_plan_pre_messages: |-
|
| 191 |
+
You are a world expert at analyzing a situation, and plan accordingly towards solving a task.
|
| 192 |
+
You have been given the following task:
|
| 193 |
+
```
|
| 194 |
+
{{task}}
|
| 195 |
+
```
|
| 196 |
+
|
| 197 |
+
Below you will find a history of attempts made to solve this task.
|
| 198 |
+
You will first have to produce a survey of known and unknown facts, then propose a step-by-step high-level plan to solve the task.
|
| 199 |
+
If the previous tries so far have met some success, your updated plan can build on these results.
|
| 200 |
+
If you are stalled, you can make a completely new plan starting from scratch.
|
| 201 |
+
|
| 202 |
+
Find the task and history below:
|
| 203 |
+
update_plan_post_messages: |-
|
| 204 |
+
Now write your updated facts below, taking into account the above history:
|
| 205 |
+
## 1. Updated facts survey
|
| 206 |
+
### 1.1. Facts given in the task
|
| 207 |
+
### 1.2. Facts that we have learned
|
| 208 |
+
### 1.3. Facts still to look up
|
| 209 |
+
### 1.4. Facts still to derive
|
| 210 |
+
|
| 211 |
+
Then write a step-by-step high-level plan to solve the task above.
|
| 212 |
+
## 2. Plan
|
| 213 |
+
### 2. 1. ...
|
| 214 |
+
Etc.
|
| 215 |
+
This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
|
| 216 |
+
Beware that you have {remaining_steps} steps remaining.
|
| 217 |
+
Do not skip steps, do not add any superfluous steps. Only write the high-level plan, DO NOT DETAIL INDIVIDUAL TOOL CALLS.
|
| 218 |
+
After writing the final step of the plan, write the '<end_plan>' tag and stop there.
|
| 219 |
+
|
| 220 |
+
You can leverage these tools, behaving like regular python functions:
|
| 221 |
+
```python
|
| 222 |
+
{%- for tool in tools.values() %}
|
| 223 |
+
def {{ tool.name }}({% for arg_name, arg_info in tool.inputs.items() %}{{ arg_name }}: {{ arg_info.type }}{% if not loop.last %}, {% endif %}{% endfor %}) -> {{tool.output_type}}:
|
| 224 |
+
"""{{ tool.description }}
|
| 225 |
+
|
| 226 |
+
Args:
|
| 227 |
+
{%- for arg_name, arg_info in tool.inputs.items() %}
|
| 228 |
+
{{ arg_name }}: {{ arg_info.description }}
|
| 229 |
+
{%- endfor %}"""
|
| 230 |
+
{% endfor %}
|
| 231 |
+
```
|
| 232 |
+
|
| 233 |
+
{%- if managed_agents and managed_agents.values() | list %}
|
| 234 |
+
You can also give tasks to team members.
|
| 235 |
+
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.
|
| 236 |
+
You can also include any relevant variables or context using the 'additional_args' argument.
|
| 237 |
+
Here is a list of the team members that you can call:
|
| 238 |
+
```python
|
| 239 |
+
{%- for agent in managed_agents.values() %}
|
| 240 |
+
def {{ agent.name }}(task: str, additional_args: dict[str, Any]) -> str:
|
| 241 |
+
"""{{ agent.description }}
|
| 242 |
+
|
| 243 |
+
Args:
|
| 244 |
+
task: Long detailed description of the task.
|
| 245 |
+
additional_args: Dictionary of extra inputs to pass to the managed agent, e.g. images, dataframes, or any other contextual data it may need.
|
| 246 |
+
"""
|
| 247 |
+
{% endfor %}
|
| 248 |
+
```
|
| 249 |
+
{%- endif %}
|
| 250 |
+
|
| 251 |
+
Now write your updated facts survey below, then your new plan.
|
| 252 |
+
managed_agent:
|
| 253 |
+
task: |-
|
| 254 |
+
You're a helpful agent named '{{name}}'.
|
| 255 |
+
You have been submitted this task by your manager.
|
| 256 |
+
---
|
| 257 |
+
Task:
|
| 258 |
+
{{task}}
|
| 259 |
+
---
|
| 260 |
+
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.
|
| 261 |
+
|
| 262 |
+
Your final_answer WILL HAVE to contain these parts:
|
| 263 |
+
### 1. Task outcome (short version):
|
| 264 |
+
### 2. Task outcome (extremely detailed version):
|
| 265 |
+
### 3. Additional context (if relevant):
|
| 266 |
+
|
| 267 |
+
Put all these in your final_answer tool, everything that you do not pass as an argument to final_answer will be lost.
|
| 268 |
+
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.
|
| 269 |
+
report: |-
|
| 270 |
+
Here is the final answer from your managed agent '{{name}}':
|
| 271 |
+
{{final_answer}}
|
| 272 |
+
final_answer:
|
| 273 |
+
pre_messages: |-
|
| 274 |
+
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:
|
| 275 |
+
post_messages: |-
|
| 276 |
+
Based on the above, please provide an answer to the following user task:
|
| 277 |
+
{{task}}
|
prompts/toolcalling_agent.yaml
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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": "web_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": "web_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 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.
|
| 102 |
+
You can also include any relevant variables or context using the 'additional_args' argument.
|
| 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 |
+
- Takes inputs: {{agent.inputs}}
|
| 107 |
+
- Returns an output of type: {{agent.output_type}}
|
| 108 |
+
{%- endfor %}
|
| 109 |
+
{%- endif %}
|
| 110 |
+
|
| 111 |
+
{%- if custom_instructions %}
|
| 112 |
+
{{custom_instructions}}
|
| 113 |
+
{%- endif %}
|
| 114 |
+
|
| 115 |
+
Here are the rules you should always follow to solve your task:
|
| 116 |
+
1. ALWAYS provide at least one tool call to ensure forward progress.
|
| 117 |
+
2. Always use the right arguments for the tools. Use the variable values as the action arguments.
|
| 118 |
+
3. Call a tool only when needed and try to solve the task yourself; for example call the search agent only when you need information.
|
| 119 |
+
4. Use final_answer tool to return your answer if
|
| 120 |
+
5. When calling the same tool again, ensure that the parameters are unique from previous calls.
|
| 121 |
+
|
| 122 |
+
Now Begin!
|
| 123 |
+
planning:
|
| 124 |
+
initial_plan : |-
|
| 125 |
+
You are a world expert at analyzing a situation to derive facts, and plan accordingly towards solving a task.
|
| 126 |
+
Below I will present you a task. You will need to 1. build a survey of facts known or needed to solve the task, then 2. make a plan of action to solve the task.
|
| 127 |
+
|
| 128 |
+
## 1. Facts survey
|
| 129 |
+
You will build a comprehensive preparatory survey of which facts we have at our disposal and which ones we still need.
|
| 130 |
+
These "facts" will typically be specific names, dates, values, etc. Your answer should use the below headings:
|
| 131 |
+
### 1.1. Facts given in the task
|
| 132 |
+
List here the specific facts given in the task that could help you (there might be nothing here).
|
| 133 |
+
|
| 134 |
+
### 1.2. Facts to look up
|
| 135 |
+
List here any facts that we may need to look up.
|
| 136 |
+
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.
|
| 137 |
+
|
| 138 |
+
### 1.3. Facts to derive
|
| 139 |
+
List here anything that we want to derive from the above by logical reasoning, for instance computation or simulation.
|
| 140 |
+
|
| 141 |
+
For each item, provide a thorough reasoning with no assumptions. Only use exactly the three headings above.
|
| 142 |
+
|
| 143 |
+
## 2. Plan
|
| 144 |
+
Then for the given task, develop a step-by-step high-level plan taking into account the above inputs and list of facts.
|
| 145 |
+
This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
|
| 146 |
+
Go step-by-step ensuring that each step is a logical progress and necessary for the solution. Only write the high-level plan showing how to approach the problem. Leave detailed individual tool calls to each step execution.
|
| 147 |
+
After writing the final step of the plan, write the '<end_plan>' tag and stop there.
|
| 148 |
+
|
| 149 |
+
You can leverage these tools:
|
| 150 |
+
{%- for tool in tools.values() %}
|
| 151 |
+
- {{ tool.name }}: {{ tool.description }}
|
| 152 |
+
Takes inputs: {{tool.inputs}}
|
| 153 |
+
Returns an output of type: {{tool.output_type}}
|
| 154 |
+
{%- endfor %}
|
| 155 |
+
|
| 156 |
+
{%- if managed_agents and managed_agents.values() | list %}
|
| 157 |
+
You can also give tasks to team members.
|
| 158 |
+
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.
|
| 159 |
+
You can also include any relevant variables or context using the 'additional_args' argument.
|
| 160 |
+
Here is a list of the team members that you can call:
|
| 161 |
+
{%- for agent in managed_agents.values() %}
|
| 162 |
+
- {{ agent.name }}: {{ agent.description }}
|
| 163 |
+
- {{ agent.name }}: {{ agent.description }}
|
| 164 |
+
- Takes inputs: {{agent.inputs}}
|
| 165 |
+
- Returns an output of type: {{agent.output_type}}
|
| 166 |
+
{%- endfor %}
|
| 167 |
+
{%- endif %}
|
| 168 |
+
|
| 169 |
+
---
|
| 170 |
+
Now begin! Here is your task:
|
| 171 |
+
```
|
| 172 |
+
{{task}}
|
| 173 |
+
```
|
| 174 |
+
First in part 1, write the facts survey, then in part 2, write your plan.
|
| 175 |
+
update_plan_pre_messages: |-
|
| 176 |
+
You are a world expert at analyzing a situation, and plan accordingly towards solving a task.
|
| 177 |
+
You have been given the following task:
|
| 178 |
+
```
|
| 179 |
+
{{task}}
|
| 180 |
+
```
|
| 181 |
+
|
| 182 |
+
Below you will find a history of attempts made to solve this task.
|
| 183 |
+
You will first have to produce a survey of known and unknown facts, then propose a step-by-step high-level plan to solve the task.
|
| 184 |
+
If the previous tries so far have met some success, your updated plan can build on these results.
|
| 185 |
+
If you are stalled, you can make a completely new plan starting from scratch.
|
| 186 |
+
|
| 187 |
+
Find the task and history below:
|
| 188 |
+
update_plan_post_messages: |-
|
| 189 |
+
Now write your updated facts below, taking into account the above history:
|
| 190 |
+
## 1. Updated facts survey
|
| 191 |
+
### 1.1. Facts given in the task
|
| 192 |
+
### 1.2. Facts that we have learned
|
| 193 |
+
### 1.3. Facts still to look up
|
| 194 |
+
### 1.4. Facts still to derive
|
| 195 |
+
|
| 196 |
+
Then write a step-by-step high-level plan to solve the task above.
|
| 197 |
+
## 2. Plan
|
| 198 |
+
### 2. 1. ...
|
| 199 |
+
Etc.
|
| 200 |
+
This plan should involve individual tasks based on the available tools, that if executed correctly will yield the correct answer.
|
| 201 |
+
Beware that you have {remaining_steps} steps remaining.
|
| 202 |
+
Go step-by-step ensuring that each step is a logical progress and necessary for the solution. Only write the high-level plan showing how to approach the problem. Leave detailed individual tool calls to each step execution.
|
| 203 |
+
After writing the final step of the plan, write the '<end_plan>' tag and stop there.
|
| 204 |
+
|
| 205 |
+
You can leverage these tools:
|
| 206 |
+
{%- for tool in tools.values() %}
|
| 207 |
+
- {{ tool.name }}: {{ tool.description }}
|
| 208 |
+
Takes inputs: {{tool.inputs}}
|
| 209 |
+
Returns an output of type: {{tool.output_type}}
|
| 210 |
+
{%- endfor %}
|
| 211 |
+
|
| 212 |
+
{%- if managed_agents and managed_agents.values() | list %}
|
| 213 |
+
You can also give tasks to team members.
|
| 214 |
+
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.
|
| 215 |
+
You can also include any relevant variables or context using the 'additional_args' argument.
|
| 216 |
+
Here is a list of the team members that you can call:
|
| 217 |
+
{%- for agent in managed_agents.values() %}
|
| 218 |
+
- {{ agent.name }}: {{ agent.description }}
|
| 219 |
+
- Takes inputs: {{agent.inputs}}
|
| 220 |
+
- Returns an output of type: {{agent.output_type}}
|
| 221 |
+
{%- endfor %}
|
| 222 |
+
{%- endif %}
|
| 223 |
+
|
| 224 |
+
Now write your new plan below.
|
| 225 |
+
managed_agent:
|
| 226 |
+
task: |-
|
| 227 |
+
You're a helpful agent named '{{name}}'.
|
| 228 |
+
You have been submitted this task by your manager.
|
| 229 |
+
---
|
| 230 |
+
Task:
|
| 231 |
+
{{task}}
|
| 232 |
+
---
|
| 233 |
+
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.
|
| 234 |
+
|
| 235 |
+
Your final_answer WILL HAVE to contain these parts:
|
| 236 |
+
### 1. Task outcome (short version):
|
| 237 |
+
### 2. Task outcome (extremely detailed version):
|
| 238 |
+
### 3. Additional context (if relevant):
|
| 239 |
+
|
| 240 |
+
Put all these in your final_answer tool, everything that you do not pass as an argument to final_answer will be lost.
|
| 241 |
+
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.
|
| 242 |
+
report: |-
|
| 243 |
+
Here is the final answer from your managed agent '{{name}}':
|
| 244 |
+
{{final_answer}}
|
| 245 |
+
final_answer:
|
| 246 |
+
pre_messages: |-
|
| 247 |
+
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:
|
| 248 |
+
post_messages: |-
|
| 249 |
+
Based on the above, please provide an answer to the following user task:
|
| 250 |
+
{{task}}
|
requirements.txt
CHANGED
|
@@ -1,9 +1,13 @@
|
|
| 1 |
gradio
|
| 2 |
requests
|
| 3 |
pandas
|
| 4 |
-
smolagents
|
| 5 |
duckduckgo-search
|
| 6 |
markdownify
|
| 7 |
gradio[oauth]
|
| 8 |
huggingface_hub
|
| 9 |
-
openai
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
gradio
|
| 2 |
requests
|
| 3 |
pandas
|
| 4 |
+
smolagents[telemetry]
|
| 5 |
duckduckgo-search
|
| 6 |
markdownify
|
| 7 |
gradio[oauth]
|
| 8 |
huggingface_hub
|
| 9 |
+
openai
|
| 10 |
+
openpyxl
|
| 11 |
+
wikipedia-api
|
| 12 |
+
langfuse
|
| 13 |
+
openinference-instrumentation-smolagents
|
tools.py
CHANGED
|
@@ -48,13 +48,13 @@ def analyze_image(url: str, prompt: str) -> str:
|
|
| 48 |
url: The URL of the image to analyze
|
| 49 |
prompt: Specific questions or things you are looking for in the image. Can also specify how to format a response. The model will return a general description if this is blank.
|
| 50 |
|
| 51 |
-
|
| 52 |
Answers to your question(s) or else a textual description of the image
|
| 53 |
"""
|
| 54 |
|
| 55 |
model_id = "Qwen/Qwen2.5-VL-32B-Instruct"
|
| 56 |
client = InferenceClient()
|
| 57 |
-
image_url = "https://agents-course-unit4-scoring.hf.space/files/cca530fc-4052-43b2-b130-b30968d8aa44"
|
| 58 |
|
| 59 |
if prompt is None:
|
| 60 |
prompt = "Describe the content of the image in detail."
|
|
@@ -63,7 +63,7 @@ def analyze_image(url: str, prompt: str) -> str:
|
|
| 63 |
{
|
| 64 |
"role": "user",
|
| 65 |
"content": [
|
| 66 |
-
{"type": "image_url", "image_url": {"url":
|
| 67 |
{"type": "text", "text": prompt}
|
| 68 |
]
|
| 69 |
}
|
|
@@ -77,8 +77,10 @@ def analyze_image(url: str, prompt: str) -> str:
|
|
| 77 |
)
|
| 78 |
description = response.choices[0].message.content
|
| 79 |
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
def download_file(url, save_path):
|
| 82 |
"""Download a file from a URL and save it locally."""
|
| 83 |
try:
|
| 84 |
response = requests.get(url, stream=True)
|
|
@@ -92,10 +94,15 @@ def download_file(url, save_path):
|
|
| 92 |
|
| 93 |
|
| 94 |
@tool
|
| 95 |
-
def transcribe_audio(file_path_or_url):
|
| 96 |
"""
|
| 97 |
Transcribe an MP3 file using OpenAI Whisper API.
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
"""
|
| 100 |
client = OpenAI(
|
| 101 |
api_key=os.environ['OPENAI_API_KEY'],
|
|
|
|
| 48 |
url: The URL of the image to analyze
|
| 49 |
prompt: Specific questions or things you are looking for in the image. Can also specify how to format a response. The model will return a general description if this is blank.
|
| 50 |
|
| 51 |
+
Returns:
|
| 52 |
Answers to your question(s) or else a textual description of the image
|
| 53 |
"""
|
| 54 |
|
| 55 |
model_id = "Qwen/Qwen2.5-VL-32B-Instruct"
|
| 56 |
client = InferenceClient()
|
| 57 |
+
#image_url = "https://agents-course-unit4-scoring.hf.space/files/cca530fc-4052-43b2-b130-b30968d8aa44"
|
| 58 |
|
| 59 |
if prompt is None:
|
| 60 |
prompt = "Describe the content of the image in detail."
|
|
|
|
| 63 |
{
|
| 64 |
"role": "user",
|
| 65 |
"content": [
|
| 66 |
+
{"type": "image_url", "image_url": {"url": url}},
|
| 67 |
{"type": "text", "text": prompt}
|
| 68 |
]
|
| 69 |
}
|
|
|
|
| 77 |
)
|
| 78 |
description = response.choices[0].message.content
|
| 79 |
|
| 80 |
+
return description
|
| 81 |
+
|
| 82 |
|
| 83 |
+
def download_file(url: str, save_path: str) -> str:
|
| 84 |
"""Download a file from a URL and save it locally."""
|
| 85 |
try:
|
| 86 |
response = requests.get(url, stream=True)
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
@tool
|
| 97 |
+
def transcribe_audio(file_path_or_url: str) -> str:
|
| 98 |
"""
|
| 99 |
Transcribe an MP3 file using OpenAI Whisper API.
|
| 100 |
+
|
| 101 |
+
Args:
|
| 102 |
+
file_path_or_url: The local file path or URL of the audio file to transcribe
|
| 103 |
+
|
| 104 |
+
Returns:
|
| 105 |
+
Transcription text as a string.
|
| 106 |
"""
|
| 107 |
client = OpenAI(
|
| 108 |
api_key=os.environ['OPENAI_API_KEY'],
|
watch
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|