-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdynamic_research.py
63 lines (52 loc) · 2.06 KB
/
dynamic_research.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from crewai import Agent, Task, Crew, Process
from langchain_openai import OpenAI
from crewai_tools import SerperDevTool
import os
# Set up tools
search_tool = SerperDevTool()
# Set up language model
llm = OpenAI(model_name="gpt-4o-mini")
os.environ["OPENAI_MODEL_NAME"] = "gpt-4o-mini"
def create_crew(topic):
# Create researcher agent
researcher = Agent(
role="Senior Research Analyst",
goal=f"Uncover cutting-edge developments in {topic}",
backstory=f"You are an experienced research analyst with a keen eye for emerging trends in {topic}. Your expertise lies in identifying groundbreaking innovations and their potential impact on various industries.",
verbose=True,
allow_delegation=False,
tools=[search_tool],
)
# Create writer agent
writer = Agent(
role="Content Writer",
goal=f"Create engaging articles about {topic} developments",
backstory=f"You are a skilled writer with a passion for explaining complex {topic} concepts in simple terms. Your articles captivate readers while conveying accurate information about advancements in {topic}.",
verbose=True,
allow_delegation=False,
)
research_task = Task(
description=f"Research the latest advancements in {topic} and summarize the top 3 breakthroughs",
agent=researcher,
expected_output=f"A bullet-point list of the top 3 {topic} breakthroughs with a brief explanation of each"
)
writing_task = Task(
description=f"Write a blog post about the top 3 {topic} breakthroughs",
agent=writer,
expected_output=f"A 500-word blog post discussing the top 3 {topic} breakthroughs",
context=[research_task]
)
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, writing_task],
process=Process.sequential,
verbose=True,
)
return crew
def main():
topic = input("Enter the topic you want to research: ")
crew = create_crew(topic)
result = crew.kickoff()
print(result)
if __name__ == "__main__":
main()