Update crew.py
Browse files
crew.py
CHANGED
|
@@ -13,8 +13,8 @@ from openinference.instrumentation.crewai import CrewAIInstrumentor
|
|
| 13 |
from phoenix.otel import register
|
| 14 |
from util import get_final_answer
|
| 15 |
|
| 16 |
-
MANAGER_MODEL = "gpt-
|
| 17 |
-
AGENT_MODEL = "gpt-
|
| 18 |
|
| 19 |
PHOENIX_API_KEY = os.environ["PHOENIX_API_KEY"]
|
| 20 |
|
|
@@ -40,90 +40,64 @@ def run_crew(question, file_name):
|
|
| 40 |
# Agents
|
| 41 |
|
| 42 |
image_analysis_agent = Agent(
|
| 43 |
-
role="
|
| 44 |
goal="Analyze image to help answer question \"{topic}\". ",
|
| 45 |
backstory="As an expert image analysis assistant, you analyze the image to help answer the question. ",
|
| 46 |
allow_delegation=False,
|
| 47 |
llm=AGENT_MODEL,
|
| 48 |
-
max_iter=
|
| 49 |
tools=[image_analysis_tool],
|
| 50 |
verbose=False
|
| 51 |
)
|
| 52 |
|
| 53 |
python_coding_agent = Agent(
|
| 54 |
-
role="
|
| 55 |
goal="Write and/or execute Python code to help answer question \"{topic}\". ",
|
| 56 |
backstory="As an expert Python coding assistant, you write and/or execute Python code to help answer the question. ",
|
| 57 |
allow_delegation=False,
|
| 58 |
llm=AGENT_MODEL,
|
| 59 |
-
max_iter=
|
| 60 |
tools=[python_coding_tool],
|
| 61 |
verbose=False,
|
| 62 |
)
|
| 63 |
|
| 64 |
video_analysis_agent = Agent(
|
| 65 |
-
role="
|
| 66 |
goal="Analyze video to help answer question \"{topic}\". ",
|
| 67 |
backstory="As an expert video analysis assistant, you analyze the video to help answer the question. ",
|
| 68 |
allow_delegation=False,
|
| 69 |
llm=AGENT_MODEL,
|
| 70 |
-
max_iter=
|
| 71 |
tools=[video_analysis_tool],
|
| 72 |
verbose=False
|
| 73 |
)
|
| 74 |
|
| 75 |
web_search_agent = Agent(
|
| 76 |
-
role="
|
| 77 |
goal="Search the web to help answer question \"{topic}\", then scrape the most relevant web page. ",
|
| 78 |
backstory="As an expert web search assistant, you search the web to help answer the question. ",
|
| 79 |
allow_delegation=False,
|
| 80 |
llm=AGENT_MODEL,
|
| 81 |
-
max_iter=
|
| 82 |
tools=[web_search_tool, web_rag_tool],
|
| 83 |
verbose=False
|
| 84 |
)
|
| 85 |
|
| 86 |
manager_agent = Agent(
|
| 87 |
-
role="
|
| 88 |
goal="Try to answer the following question. If needed, delegate to **one** of your coworkers, image_analysis_agent, python_coding_agent, video_analysis_agent, or web_search_agent for help. Question: \"{topic}\" ",
|
| 89 |
backstory="As an expert manager assistant, you answer the question. ",
|
| 90 |
allow_delegation=True,
|
| 91 |
llm=MANAGER_MODEL,
|
| 92 |
max_iter=5,
|
| 93 |
-
verbose=
|
| 94 |
)
|
| 95 |
|
| 96 |
# Tasks
|
| 97 |
-
|
| 98 |
-
"""
|
| 99 |
-
image_analysis_task = Task(
|
| 100 |
-
agent=image_analysis_agent,
|
| 101 |
-
description="Analyze image to help answer question \"{topic}\". ",
|
| 102 |
-
expected_output="Content to help answer the question. "
|
| 103 |
-
)
|
| 104 |
-
|
| 105 |
-
python_coding_task = Task(
|
| 106 |
-
agent=python_coding_agent,
|
| 107 |
-
description="Write and/or execute Python code to help answer question \"{topic}\". ",
|
| 108 |
-
expected_output="Content to help answer the question. "
|
| 109 |
-
)
|
| 110 |
-
|
| 111 |
-
video_analysis_task = Task(
|
| 112 |
-
agent=video_analysis_agent,
|
| 113 |
-
description="Analyze video to help answer question \"{topic}\". ",
|
| 114 |
-
expected_output="Content to help answer the question. "
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
web_search_task = Task(
|
| 118 |
-
agent=web_search_agent,
|
| 119 |
-
description="Search the web to help answer question \"{topic}\", then scrape the most relevant web page. ",
|
| 120 |
-
expected_output="Content to help answer the question. "
|
| 121 |
-
)
|
| 122 |
-
"""
|
| 123 |
-
|
| 124 |
manager_task = Task(
|
| 125 |
agent=manager_agent,
|
| 126 |
-
description="Try to answer the following question. If needed, delegate to **one** of your coworkers,
|
| 127 |
expected_output="The answer to the question. "
|
| 128 |
)
|
| 129 |
|
|
@@ -133,7 +107,7 @@ def run_crew(question, file_name):
|
|
| 133 |
agents=[image_analysis_agent, python_coding_agent, video_analysis_agent, web_search_agent],
|
| 134 |
manager_agent=manager_agent,
|
| 135 |
tasks=[manager_task],
|
| 136 |
-
verbose=
|
| 137 |
)
|
| 138 |
|
| 139 |
print(crew.agents)
|
|
|
|
| 13 |
from phoenix.otel import register
|
| 14 |
from util import get_final_answer
|
| 15 |
|
| 16 |
+
MANAGER_MODEL = "gpt-4o"
|
| 17 |
+
AGENT_MODEL = "gpt-4o"
|
| 18 |
|
| 19 |
PHOENIX_API_KEY = os.environ["PHOENIX_API_KEY"]
|
| 20 |
|
|
|
|
| 40 |
# Agents
|
| 41 |
|
| 42 |
image_analysis_agent = Agent(
|
| 43 |
+
role="Image Analysis Agent",
|
| 44 |
goal="Analyze image to help answer question \"{topic}\". ",
|
| 45 |
backstory="As an expert image analysis assistant, you analyze the image to help answer the question. ",
|
| 46 |
allow_delegation=False,
|
| 47 |
llm=AGENT_MODEL,
|
| 48 |
+
max_iter=3,
|
| 49 |
tools=[image_analysis_tool],
|
| 50 |
verbose=False
|
| 51 |
)
|
| 52 |
|
| 53 |
python_coding_agent = Agent(
|
| 54 |
+
role="Python Coding Agent",
|
| 55 |
goal="Write and/or execute Python code to help answer question \"{topic}\". ",
|
| 56 |
backstory="As an expert Python coding assistant, you write and/or execute Python code to help answer the question. ",
|
| 57 |
allow_delegation=False,
|
| 58 |
llm=AGENT_MODEL,
|
| 59 |
+
max_iter=3,
|
| 60 |
tools=[python_coding_tool],
|
| 61 |
verbose=False,
|
| 62 |
)
|
| 63 |
|
| 64 |
video_analysis_agent = Agent(
|
| 65 |
+
role="Video Analysis Agent",
|
| 66 |
goal="Analyze video to help answer question \"{topic}\". ",
|
| 67 |
backstory="As an expert video analysis assistant, you analyze the video to help answer the question. ",
|
| 68 |
allow_delegation=False,
|
| 69 |
llm=AGENT_MODEL,
|
| 70 |
+
max_iter=3,
|
| 71 |
tools=[video_analysis_tool],
|
| 72 |
verbose=False
|
| 73 |
)
|
| 74 |
|
| 75 |
web_search_agent = Agent(
|
| 76 |
+
role="Web Search Agent",
|
| 77 |
goal="Search the web to help answer question \"{topic}\", then scrape the most relevant web page. ",
|
| 78 |
backstory="As an expert web search assistant, you search the web to help answer the question. ",
|
| 79 |
allow_delegation=False,
|
| 80 |
llm=AGENT_MODEL,
|
| 81 |
+
max_iter=3,
|
| 82 |
tools=[web_search_tool, web_rag_tool],
|
| 83 |
verbose=False
|
| 84 |
)
|
| 85 |
|
| 86 |
manager_agent = Agent(
|
| 87 |
+
role="Manager Agent",
|
| 88 |
goal="Try to answer the following question. If needed, delegate to **one** of your coworkers, image_analysis_agent, python_coding_agent, video_analysis_agent, or web_search_agent for help. Question: \"{topic}\" ",
|
| 89 |
backstory="As an expert manager assistant, you answer the question. ",
|
| 90 |
allow_delegation=True,
|
| 91 |
llm=MANAGER_MODEL,
|
| 92 |
max_iter=5,
|
| 93 |
+
verbose=False
|
| 94 |
)
|
| 95 |
|
| 96 |
# Tasks
|
| 97 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
manager_task = Task(
|
| 99 |
agent=manager_agent,
|
| 100 |
+
description="Try to answer the following question. If needed, delegate to **one** of your coworkers, Image Analysis Agent, Python Coding Agent, Video Analysis Agent, or Web Search Agent for help. Question: \"{topic}\" ",
|
| 101 |
expected_output="The answer to the question. "
|
| 102 |
)
|
| 103 |
|
|
|
|
| 107 |
agents=[image_analysis_agent, python_coding_agent, video_analysis_agent, web_search_agent],
|
| 108 |
manager_agent=manager_agent,
|
| 109 |
tasks=[manager_task],
|
| 110 |
+
verbose=False
|
| 111 |
)
|
| 112 |
|
| 113 |
print(crew.agents)
|