Update crew.py
Browse files
crew.py
CHANGED
|
@@ -47,7 +47,7 @@ def run_crew(question, file_path):
|
|
| 47 |
|
| 48 |
@tool("Web Search Tool")
|
| 49 |
def web_search_tool(question: str) -> str:
|
| 50 |
-
"""
|
| 51 |
|
| 52 |
Args:
|
| 53 |
question (str): Question to answer
|
|
@@ -74,7 +74,7 @@ def run_crew(question, file_path):
|
|
| 74 |
|
| 75 |
@tool("Image Analysis Tool")
|
| 76 |
def image_analysis_tool(question: str, file_path: str) -> str:
|
| 77 |
-
"""
|
| 78 |
|
| 79 |
Args:
|
| 80 |
question (str): Question about an image file
|
|
@@ -101,7 +101,7 @@ def run_crew(question, file_path):
|
|
| 101 |
|
| 102 |
@tool("Audio Analysis Tool")
|
| 103 |
def audio_analysis_tool(question: str, file_path: str) -> str:
|
| 104 |
-
"""
|
| 105 |
|
| 106 |
Args:
|
| 107 |
question (str): Question about an audio file
|
|
@@ -128,7 +128,7 @@ def run_crew(question, file_path):
|
|
| 128 |
|
| 129 |
@tool("Video Analysis Tool")
|
| 130 |
def video_analysis_tool(question: str, file_path: str) -> str:
|
| 131 |
-
"""
|
| 132 |
|
| 133 |
Args:
|
| 134 |
question (str): Question about a video file
|
|
@@ -155,7 +155,7 @@ def run_crew(question, file_path):
|
|
| 155 |
|
| 156 |
@tool("YouTube Analysis Tool")
|
| 157 |
def youtube_analysis_tool(question: str, url: str) -> str:
|
| 158 |
-
"""
|
| 159 |
|
| 160 |
Args:
|
| 161 |
question (str): Question about a YouTube video
|
|
@@ -180,11 +180,12 @@ def run_crew(question, file_path):
|
|
| 180 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 181 |
|
| 182 |
@tool("Code Generation Tool")
|
| 183 |
-
def code_generation_tool(question: str) -> str:
|
| 184 |
-
"""Given a question
|
| 185 |
|
| 186 |
Args:
|
| 187 |
question (str): Question to answer
|
|
|
|
| 188 |
|
| 189 |
Returns:
|
| 190 |
str: Answer to the question
|
|
@@ -196,7 +197,7 @@ def run_crew(question, file_path):
|
|
| 196 |
|
| 197 |
response = client.models.generate_content(
|
| 198 |
model=CODE_GENERATION_MODEL,
|
| 199 |
-
contents=[question],
|
| 200 |
config=types.GenerateContentConfig(
|
| 201 |
tools=[types.Tool(code_execution=types.ToolCodeExecution)]
|
| 202 |
),
|
|
@@ -210,11 +211,11 @@ def run_crew(question, file_path):
|
|
| 210 |
|
| 211 |
@tool("Code Execution Tool")
|
| 212 |
def code_execution_tool(question: str, file_path: str) -> str:
|
| 213 |
-
"""Given a question and
|
| 214 |
|
| 215 |
Args:
|
| 216 |
question (str): Question to answer
|
| 217 |
-
file_path (str): The
|
| 218 |
|
| 219 |
Returns:
|
| 220 |
str: Answer to the question
|
|
@@ -244,8 +245,8 @@ def run_crew(question, file_path):
|
|
| 244 |
|
| 245 |
web_search_agent = Agent(
|
| 246 |
role="Web Search Agent",
|
| 247 |
-
goal="
|
| 248 |
-
backstory="As an expert web search assistant, you search the web to
|
| 249 |
allow_delegation=False,
|
| 250 |
llm=AGENT_MODEL,
|
| 251 |
max_iter=2,
|
|
@@ -255,8 +256,8 @@ def run_crew(question, file_path):
|
|
| 255 |
|
| 256 |
image_analysis_agent = Agent(
|
| 257 |
role="Image Analysis Agent",
|
| 258 |
-
goal="
|
| 259 |
-
backstory="As an expert image analysis assistant, you analyze the image
|
| 260 |
allow_delegation=False,
|
| 261 |
llm=AGENT_MODEL,
|
| 262 |
max_iter=2,
|
|
@@ -266,8 +267,8 @@ def run_crew(question, file_path):
|
|
| 266 |
|
| 267 |
audio_analysis_agent = Agent(
|
| 268 |
role="Audio Analysis Agent",
|
| 269 |
-
goal="
|
| 270 |
-
backstory="As an expert audio analysis assistant, you analyze the audio
|
| 271 |
allow_delegation=False,
|
| 272 |
llm=AGENT_MODEL,
|
| 273 |
max_iter=2,
|
|
@@ -277,8 +278,8 @@ def run_crew(question, file_path):
|
|
| 277 |
|
| 278 |
video_analysis_agent = Agent(
|
| 279 |
role="Video Analysis Agent",
|
| 280 |
-
goal="
|
| 281 |
-
backstory="As an expert video analysis assistant, you analyze the video file to
|
| 282 |
allow_delegation=False,
|
| 283 |
llm=AGENT_MODEL,
|
| 284 |
max_iter=2,
|
|
@@ -288,8 +289,8 @@ def run_crew(question, file_path):
|
|
| 288 |
|
| 289 |
youtube_analysis_agent = Agent(
|
| 290 |
role="YouTube Analysis Agent",
|
| 291 |
-
goal="
|
| 292 |
-
backstory="As an expert YouTube analysis assistant, you analyze the video to
|
| 293 |
allow_delegation=False,
|
| 294 |
llm=AGENT_MODEL,
|
| 295 |
max_iter=2,
|
|
@@ -299,8 +300,8 @@ def run_crew(question, file_path):
|
|
| 299 |
|
| 300 |
code_generation_agent = Agent(
|
| 301 |
role="Code Generation Agent",
|
| 302 |
-
goal="Given a question
|
| 303 |
-
backstory="As an expert Python code generation assistant, you generate code to
|
| 304 |
allow_delegation=False,
|
| 305 |
llm=AGENT_MODEL,
|
| 306 |
max_iter=3,
|
|
@@ -310,8 +311,8 @@ def run_crew(question, file_path):
|
|
| 310 |
|
| 311 |
code_execution_agent = Agent(
|
| 312 |
role="Code Execution Agent",
|
| 313 |
-
goal="Given a question and
|
| 314 |
-
backstory="As an expert Python code execution assistant, you execute
|
| 315 |
allow_delegation=False,
|
| 316 |
llm=AGENT_MODEL,
|
| 317 |
max_iter=3,
|
|
@@ -321,21 +322,19 @@ def run_crew(question, file_path):
|
|
| 321 |
|
| 322 |
manager_agent = Agent(
|
| 323 |
role="Manager Agent",
|
| 324 |
-
goal="
|
| 325 |
-
"If there is no good coworker, delegate to the Code Generation Agent to implement a tool for the task. "
|
| 326 |
-
"Question: {question}",
|
| 327 |
backstory="As an expert manager assistant, you answer the question.",
|
| 328 |
allow_delegation=True,
|
| 329 |
llm=MANAGER_MODEL,
|
| 330 |
max_iter=5,
|
| 331 |
-
verbose=
|
| 332 |
)
|
| 333 |
|
| 334 |
# Task
|
| 335 |
|
| 336 |
manager_task = Task(
|
| 337 |
agent=manager_agent,
|
| 338 |
-
description="
|
| 339 |
expected_output="The answer to the question."
|
| 340 |
)
|
| 341 |
|
|
@@ -360,7 +359,7 @@ def run_crew(question, file_path):
|
|
| 360 |
file_data = read_file(file_path)
|
| 361 |
|
| 362 |
if file_data:
|
| 363 |
-
question = f"{question}
|
| 364 |
else:
|
| 365 |
question = f"{question} File path: {file_path}."
|
| 366 |
|
|
|
|
| 47 |
|
| 48 |
@tool("Web Search Tool")
|
| 49 |
def web_search_tool(question: str) -> str:
|
| 50 |
+
"""Given a question, search the web to answer the question.
|
| 51 |
|
| 52 |
Args:
|
| 53 |
question (str): Question to answer
|
|
|
|
| 74 |
|
| 75 |
@tool("Image Analysis Tool")
|
| 76 |
def image_analysis_tool(question: str, file_path: str) -> str:
|
| 77 |
+
"""Given a question and image file, analyze the image to answer the question.
|
| 78 |
|
| 79 |
Args:
|
| 80 |
question (str): Question about an image file
|
|
|
|
| 101 |
|
| 102 |
@tool("Audio Analysis Tool")
|
| 103 |
def audio_analysis_tool(question: str, file_path: str) -> str:
|
| 104 |
+
"""Given a question and audio file, analyze the audio to answer the question.
|
| 105 |
|
| 106 |
Args:
|
| 107 |
question (str): Question about an audio file
|
|
|
|
| 128 |
|
| 129 |
@tool("Video Analysis Tool")
|
| 130 |
def video_analysis_tool(question: str, file_path: str) -> str:
|
| 131 |
+
"""Given a question and video file, analyze the video to answer the question.
|
| 132 |
|
| 133 |
Args:
|
| 134 |
question (str): Question about a video file
|
|
|
|
| 155 |
|
| 156 |
@tool("YouTube Analysis Tool")
|
| 157 |
def youtube_analysis_tool(question: str, url: str) -> str:
|
| 158 |
+
"""Given a question and YouTube URL, analyze the video to answer the question.
|
| 159 |
|
| 160 |
Args:
|
| 161 |
question (str): Question about a YouTube video
|
|
|
|
| 180 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 181 |
|
| 182 |
@tool("Code Generation Tool")
|
| 183 |
+
def code_generation_tool(question: str, json_data: str) -> str:
|
| 184 |
+
"""Given a question and JSON data, generate and execute code to answer the question.
|
| 185 |
|
| 186 |
Args:
|
| 187 |
question (str): Question to answer
|
| 188 |
+
json_data (str): The JSON data
|
| 189 |
|
| 190 |
Returns:
|
| 191 |
str: Answer to the question
|
|
|
|
| 197 |
|
| 198 |
response = client.models.generate_content(
|
| 199 |
model=CODE_GENERATION_MODEL,
|
| 200 |
+
contents=[f"{question}\n{json_data}"],
|
| 201 |
config=types.GenerateContentConfig(
|
| 202 |
tools=[types.Tool(code_execution=types.ToolCodeExecution)]
|
| 203 |
),
|
|
|
|
| 211 |
|
| 212 |
@tool("Code Execution Tool")
|
| 213 |
def code_execution_tool(question: str, file_path: str) -> str:
|
| 214 |
+
"""Given a question and Python file, execute the file to answer the question.
|
| 215 |
|
| 216 |
Args:
|
| 217 |
question (str): Question to answer
|
| 218 |
+
file_path (str): The Python file path
|
| 219 |
|
| 220 |
Returns:
|
| 221 |
str: Answer to the question
|
|
|
|
| 245 |
|
| 246 |
web_search_agent = Agent(
|
| 247 |
role="Web Search Agent",
|
| 248 |
+
goal="Given a question, search the web and answer the question: {question}",
|
| 249 |
+
backstory="As an expert web search assistant, you search the web to answer the question.",
|
| 250 |
allow_delegation=False,
|
| 251 |
llm=AGENT_MODEL,
|
| 252 |
max_iter=2,
|
|
|
|
| 256 |
|
| 257 |
image_analysis_agent = Agent(
|
| 258 |
role="Image Analysis Agent",
|
| 259 |
+
goal="Given a question and image file, analyze the image and answer the question: {question}",
|
| 260 |
+
backstory="As an expert image analysis assistant, you analyze the image to answer the question.",
|
| 261 |
allow_delegation=False,
|
| 262 |
llm=AGENT_MODEL,
|
| 263 |
max_iter=2,
|
|
|
|
| 267 |
|
| 268 |
audio_analysis_agent = Agent(
|
| 269 |
role="Audio Analysis Agent",
|
| 270 |
+
goal="Given a question and audio file, analyze the audio and answer the question: {question}",
|
| 271 |
+
backstory="As an expert audio analysis assistant, you analyze the audio to answer the question.",
|
| 272 |
allow_delegation=False,
|
| 273 |
llm=AGENT_MODEL,
|
| 274 |
max_iter=2,
|
|
|
|
| 278 |
|
| 279 |
video_analysis_agent = Agent(
|
| 280 |
role="Video Analysis Agent",
|
| 281 |
+
goal="Given a question and video file, analyze the video and answer the question: {question}",
|
| 282 |
+
backstory="As an expert video analysis assistant, you analyze the video file to answer the question.",
|
| 283 |
allow_delegation=False,
|
| 284 |
llm=AGENT_MODEL,
|
| 285 |
max_iter=2,
|
|
|
|
| 289 |
|
| 290 |
youtube_analysis_agent = Agent(
|
| 291 |
role="YouTube Analysis Agent",
|
| 292 |
+
goal="Given a question and YouTube video, analyze the video and answer the question: {question}",
|
| 293 |
+
backstory="As an expert YouTube analysis assistant, you analyze the video to answer the question.",
|
| 294 |
allow_delegation=False,
|
| 295 |
llm=AGENT_MODEL,
|
| 296 |
max_iter=2,
|
|
|
|
| 300 |
|
| 301 |
code_generation_agent = Agent(
|
| 302 |
role="Code Generation Agent",
|
| 303 |
+
goal="Given a question and JSON data, generate and execute code to answer the question: {question}",
|
| 304 |
+
backstory="As an expert Python code generation assistant, you generate and execute code to answer the question.",
|
| 305 |
allow_delegation=False,
|
| 306 |
llm=AGENT_MODEL,
|
| 307 |
max_iter=3,
|
|
|
|
| 311 |
|
| 312 |
code_execution_agent = Agent(
|
| 313 |
role="Code Execution Agent",
|
| 314 |
+
goal="Given a question and Python file, execute the file to answer the question: {question}",
|
| 315 |
+
backstory="As an expert Python code execution assistant, you execute code to answer the question.",
|
| 316 |
allow_delegation=False,
|
| 317 |
llm=AGENT_MODEL,
|
| 318 |
max_iter=3,
|
|
|
|
| 322 |
|
| 323 |
manager_agent = Agent(
|
| 324 |
role="Manager Agent",
|
| 325 |
+
goal="Answer the following question. If needed, delegate to one of your coworkers. Question: {question}",
|
|
|
|
|
|
|
| 326 |
backstory="As an expert manager assistant, you answer the question.",
|
| 327 |
allow_delegation=True,
|
| 328 |
llm=MANAGER_MODEL,
|
| 329 |
max_iter=5,
|
| 330 |
+
verbose=False
|
| 331 |
)
|
| 332 |
|
| 333 |
# Task
|
| 334 |
|
| 335 |
manager_task = Task(
|
| 336 |
agent=manager_agent,
|
| 337 |
+
description="Answer the following question. If needed, delegate to one of your coworkers. Question: {question}",
|
| 338 |
expected_output="The answer to the question."
|
| 339 |
)
|
| 340 |
|
|
|
|
| 359 |
file_data = read_file(file_path)
|
| 360 |
|
| 361 |
if file_data:
|
| 362 |
+
question = f"{question} JSON data: {file_data}" # sandbox contraints
|
| 363 |
else:
|
| 364 |
question = f"{question} File path: {file_path}."
|
| 365 |
|