1
+ from crewai import Agent , Task , Crew , Process
2
+ from dotenv import load_dotenv
3
+ from langchain_groq import ChatGroq
4
+ import os
5
+
6
+ load_dotenv ()
7
+
8
+ # Define your LLM
9
+ llms = ChatGroq (
10
+ model = "groq/llama-3.1-8b-instant" ,
11
+ api_key = os .getenv ("Groq_API_Key" ),
12
+ )
13
+
14
+ # Agent: Content Planner
15
+ planner = Agent (
16
+ role = "Content Planner" ,
17
+ goal = "Plan engaging and factually accurate content on {topic}" ,
18
+ backstory = "You're working on planning a blog article "
19
+ "about the topic: {topic}."
20
+ "You collect information that helps the "
21
+ "audience learn something "
22
+ "and make informed decisions. "
23
+ "Your work is the basis for "
24
+ "the Content Writer to write an article on this topic." ,
25
+ allow_delegation = False ,
26
+ verbose = True ,
27
+ llm = llms ,
28
+ )
29
+
30
+ # Agent: Content Writer
31
+ writer = Agent (
32
+ role = "Content Writer" ,
33
+ goal = "Write insightful and factually accurate "
34
+ "opinion piece about the topic: {topic}" ,
35
+ backstory = "You're working on a writing "
36
+ "a new opinion piece about the topic: {topic}. "
37
+ "You base your writing on the work of "
38
+ "the Content Planner, who provides an outline "
39
+ "and relevant context about the topic. "
40
+ "You follow the main objectives and "
41
+ "direction of the outline, "
42
+ "as provide by the Content Planner. "
43
+ "You also provide objective and impartial insights "
44
+ "and back them up with information "
45
+ "provide by the Content Planner. "
46
+ "You acknowledge in your opinion piece "
47
+ "when your statements are opinions "
48
+ "as opposed to objective statements." ,
49
+ allow_delegation = False ,
50
+ verbose = True ,
51
+ llm = llms ,
52
+ )
53
+
54
+ # Agent: Content Editor
55
+ editor = Agent (
56
+ role = "Editor" ,
57
+ goal = "Edit a given blog post to align with "
58
+ "the writing style of the organization. " ,
59
+ backstory = "You are an editor who receives a blog post "
60
+ "from the Content Writer. "
61
+ "Your goal is to review the blog post "
62
+ "to ensure that it follows journalistic best practices,"
63
+ "provides balanced viewpoints "
64
+ "when providing opinions or assertions, "
65
+ "and also avoids major controversial topics "
66
+ "or opinions when possible." ,
67
+ allow_delegation = False ,
68
+ verbose = True ,
69
+ llm = llms ,
70
+ )
71
+
72
+ # Task: Content Planner
73
+ plan = Task (
74
+ description = (
75
+ "1. Prioritize the latest trends, key players, "
76
+ "and noteworthy news on {topic}.\n "
77
+ "2. Identify the target audience, considering "
78
+ "their interests and pain points.\n "
79
+ "3. Develop a detailed content outline including "
80
+ "an introduction, key points, and a call to action.\n "
81
+ "4. Include SEO keywords and relevant data or sources."
82
+ ),
83
+ expected_output = "A comprehensive content plan document "
84
+ "with an outline, audience analysis, "
85
+ "SEO keywords, and resources." ,
86
+ agent = planner ,
87
+ )
88
+
89
+ # Task: Content Writer
90
+ write = Task (
91
+ description = (
92
+ "1. Use the content plan to craft a compelling "
93
+ "blog post on {topic}.\n "
94
+ "2. Incorporate SEO keywords naturally.\n "
95
+ "3. Sections/Subtitles are properly named "
96
+ "in an engaging manner.\n "
97
+ "4. Ensure the post is structured with an "
98
+ "engaging introduction, insightful body, "
99
+ "and a summarizing conclusion.\n "
100
+ "5. Proofread for grammatical errors and "
101
+ "alignment with the brand's voice.\n "
102
+ ),
103
+ expected_output = "A well-written blog post "
104
+ "in markdown format, ready for publication, "
105
+ "each section should have 2 or 3 paragraphs." ,
106
+ agent = writer ,
107
+ )
108
+
109
+ # Task: Content Editor
110
+ edit = Task (
111
+ description = (
112
+ "Proofread the given blog post for "
113
+ "grammatical errors and "
114
+ "alignment with the brand's voice."
115
+ ),
116
+ expected_output = "A well-written blog post in markdown format, "
117
+ "ready for publication, "
118
+ "each section should have 2 or 3 paragraphs." ,
119
+ agent = editor ,
120
+ )
121
+
122
+
123
+ crew = Crew (
124
+ agents = [planner , writer , editor ],
125
+ tasks = [plan , write , edit ],
126
+ process = Process .sequential ,
127
+ verbose = True ,
128
+ )
129
+
130
+ result = crew .kickoff (inputs = {"topic" : "Rivalry between Nikola Tesla and Thomas Edison" })
131
+
132
+ print (result )
0 commit comments