cryogenic22 commited on
Commit
ac6a55a
·
verified ·
1 Parent(s): 11bfcdf

Update agents.py

Browse files
Files changed (1) hide show
  1. agents.py +344 -69
agents.py CHANGED
@@ -1,41 +1,364 @@
1
  # agents.py
2
  from crewai import Agent, Crew, Process, Task
3
- from crewai_tools import SerperDevTool
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  def create_research_crew(topic: str):
6
- """Create the research crew with SerperDev tool integration"""
7
  try:
8
- # Initialize SerperDev tool
9
- search_tool = SerperDevTool()
10
 
11
- # Create agents
12
  researcher = Agent(
13
- role='Research Analyst',
14
- goal=f'Conduct exhaustive market research about {topic} with comprehensive analysis',
15
- backstory="""Senior market research analyst with 15+ years of experience in detailed industry analysis.""",
16
- tools=[search_tool],
 
 
 
 
17
  verbose=True
18
  )
19
 
 
20
  analyst = Agent(
21
- role='Data Analyst',
22
- goal='Transform research data into actionable insights with visualizations',
23
- backstory="""Expert data analyst specializing in predictive analytics and trend analysis.""",
24
- tools=[search_tool],
 
 
 
25
  verbose=True
26
  )
27
 
 
28
  writer = Agent(
29
- role='Report Writer',
30
- goal='Create comprehensive market research reports with compelling narratives',
31
- backstory="""Professional writer specializing in creating clear, engaging market research reports.""",
 
 
 
32
  verbose=True
33
  )
34
 
35
- # Create tasks
36
- research_task = create_research_task(topic, researcher)
37
- analysis_task = create_analysis_task(analyst, research_task)
38
- report_task = create_report_task(writer, [research_task, analysis_task])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  return Crew(
41
  agents=[researcher, analyst, writer],
@@ -43,54 +366,6 @@ def create_research_crew(topic: str):
43
  verbose=True,
44
  process=Process.sequential
45
  )
 
46
  except Exception as e:
47
  raise Exception(f"Error initializing research crew: {str(e)}")
48
-
49
- def create_research_task(topic: str, agent):
50
- """Create the research task"""
51
- return Task(
52
- description=f"""
53
- Conduct exhaustive market research on {topic} covering:
54
- 1. Market Overview (size, growth, segmentation)
55
- 2. Competitive Analysis (players, shares, positioning)
56
- 3. Market Dynamics (drivers, challenges, trends)
57
- 4. Economic Factors (macro influences, indicators)
58
-
59
- Provide specific numerical data and sources.
60
- """,
61
- agent=agent,
62
- expected_output="Comprehensive research data with verified sources"
63
- )
64
-
65
- def create_analysis_task(agent, research_task):
66
- """Create the analysis task"""
67
- return Task(
68
- description="""
69
- Analyze the research findings providing:
70
- 1. Strategic Market Analysis
71
- 2. Advanced Data Analysis
72
- 3. Competitive Intelligence
73
- 4. Trend Analysis
74
-
75
- Include specific metrics and visualization-ready data.
76
- """,
77
- agent=agent,
78
- expected_output="Detailed analysis with visualization-ready metrics",
79
- context=[research_task]
80
- )
81
-
82
- def create_report_task(agent, context_tasks):
83
- """Create the report task"""
84
- return Task(
85
- description="""
86
- Create a professional report with:
87
- 1. Executive Summary (2-3 pages)
88
- 2. Detailed Analysis (10+ pages)
89
- 3. Sources and Citations
90
-
91
- Format as JSON with exec_summary, detailed_report, and metrics sections.
92
- """,
93
- agent=agent,
94
- expected_output="JSON formatted report with executive summary and details",
95
- context=context_tasks
96
- )
 
1
  # agents.py
2
  from crewai import Agent, Crew, Process, Task
3
+ from crewai_tools import SerperDevTool, ScrapeWebsiteTool
4
+ from langchain.tools import Tool
5
+
6
+ class MarketResearchTools:
7
+ """Advanced research tools using Serper capabilities"""
8
+
9
+ def __init__(self):
10
+ self.serper = SerperDevTool()
11
+ self.scraper = ScrapeWebsiteTool()
12
+
13
+ # Specialized search tools
14
+ self.news_search = Tool(
15
+ name="News Search",
16
+ func=self.serper.search_news,
17
+ description="Search recent news articles, press releases, and media coverage"
18
+ )
19
+
20
+ self.market_search = Tool(
21
+ name="Market Research",
22
+ func=self.serper.search,
23
+ description="Search for market reports, statistics, and industry analysis"
24
+ )
25
+
26
+ self.competitor_search = Tool(
27
+ name="Competitor Analysis",
28
+ func=self.serper.search,
29
+ description="Research specific companies, their market position, and strategies"
30
+ )
31
+
32
+ def create_research_crew(topic: str):
33
+ """Create an advanced research crew with specialized tools"""
34
+ try:
35
+ tools = MarketResearchTools()
36
+
37
+ # Advanced Research Analyst
38
+ researcher = Agent(
39
+ role='Senior Market Research Analyst',
40
+ goal=f'Conduct exhaustive market research about {topic} with detailed data and industry insights',
41
+ backstory="""You are a veteran market research analyst with 20+ years of experience.
42
+ You excel at uncovering hard-to-find data points, analyzing industry dynamics,
43
+ and identifying emerging trends. You have a strong network of industry contacts
44
+ and access to premium research databases. You always validate data through
45
+ multiple sources and provide confidence levels for your findings.""",
46
+ tools=[tools.market_search, tools.news_search, tools.competitor_search, tools.scraper],
47
+ verbose=True
48
+ )
49
+
50
+ # Industry Expert Analyst
51
+ analyst = Agent(
52
+ role='Industry Expert & Strategy Analyst',
53
+ goal='Transform research into strategic insights and actionable recommendations',
54
+ backstory="""You are an industry expert with deep domain knowledge and strategic consulting
55
+ experience. You specialize in connecting market data to business implications,
56
+ forecasting industry changes, and developing strategic recommendations.
57
+ Your analysis is always backed by concrete examples and case studies.""",
58
+ tools=[tools.market_search, tools.competitor_search],
59
+ verbose=True
60
+ )
61
+
62
+ # Professional Report Writer
63
+ writer = Agent(
64
+ role='Executive Report Writer',
65
+ goal='Create compelling, comprehensive market analysis reports',
66
+ backstory="""You are an experienced business writer who specializes in creating
67
+ executive-level market research reports. You excel at distilling complex
68
+ information into clear narratives while maintaining analytical rigor.
69
+ You always include relevant examples, case studies, and data visualizations.""",
70
+ verbose=True
71
+ )
72
+
73
+ # Create enhanced tasks
74
+ research_task = Task(
75
+ description=f"""
76
+ Conduct comprehensive market research on {topic} with the following focus areas:
77
+
78
+ 1. Market Overview:
79
+ - Current market size with specific values
80
+ - Historical growth patterns (5-year minimum)
81
+ - Future projections with CAGR
82
+ - Market segmentation analysis
83
+ - Regional market distribution
84
+ - Value chain analysis
85
+ - Pricing trends and dynamics
86
+
87
+ 2. Competitive Landscape:
88
+ - Detailed analysis of top 5-7 players
89
+ - Market share breakdown
90
+ - Competitive strategies
91
+ - Recent developments and initiatives
92
+ - SWOT analysis of major players
93
+ - Barriers to entry analysis
94
+ - Industry concentration metrics
95
+
96
+ 3. Technology & Innovation:
97
+ - Current technology trends
98
+ - Innovation patterns
99
+ - Patent analysis
100
+ - R&D investments
101
+ - Emerging technologies
102
+ - Digital transformation trends
103
+
104
+ 4. Regulatory & Environmental Factors:
105
+ - Current regulations
106
+ - Upcoming policy changes
107
+ - Environmental considerations
108
+ - Compliance requirements
109
+ - Industry standards
110
+ - Certification needs
111
+
112
+ Requirements:
113
+ - Use multiple sources for each data point
114
+ - Focus on recent data (last 12 months)
115
+ - Include source citations
116
+ - Note confidence levels for projections
117
+ - Identify any data gaps or inconsistencies
118
+ """,
119
+ agent=researcher,
120
+ expected_output="Comprehensive research data with verified sources and confidence levels"
121
+ )
122
+
123
+ analysis_task = Task(
124
+ description="""
125
+ Analyze the research findings and create strategic insights:
126
+
127
+ 1. Strategic Analysis:
128
+ - Porter's Five Forces analysis
129
+ - PESTLE analysis
130
+ - Value chain opportunities
131
+ - Growth vectors
132
+ - Market maturity assessment
133
+ - Investment potential
134
+
135
+ 2. Trend Analysis:
136
+ - Major market trends
137
+ - Technology impact assessment
138
+ - Consumer behavior shifts
139
+ - Emerging business models
140
+ - Future scenarios
141
+ - Risk assessment
142
+
143
+ 3. Strategic Implications:
144
+ - Market entry strategies
145
+ - Growth opportunities
146
+ - Potential threats
147
+ - Success factors
148
+ - Risk mitigation strategies
149
+ - Partnership opportunities
150
+
151
+ Requirements:
152
+ - Provide concrete examples
153
+ - Include case studies
154
+ - Support all conclusions with data
155
+ - Identify key success factors
156
+ - Assess market attractiveness
157
+ """,
158
+ agent=analyst,
159
+ expected_output="Strategic analysis with actionable insights",
160
+ context=[research_task]
161
+ )
162
+
163
+ # agents.py
164
+ from crewai import Agent, Crew, Process, Task
165
+ from crewai_tools import SerperDevTool, ScrapeWebsiteTool
166
+ from langchain.tools import Tool
167
+
168
+ class MarketResearchTools:
169
+ """Advanced research tools using Serper capabilities"""
170
+
171
+ def __init__(self):
172
+ self.serper = SerperDevTool()
173
+ self.scraper = ScrapeWebsiteTool()
174
+
175
+ # Specialized search tools
176
+ self.news_search = Tool(
177
+ name="News Search",
178
+ func=self.serper.search_news,
179
+ description="Search recent news articles, press releases, and media coverage"
180
+ )
181
+
182
+ self.market_search = Tool(
183
+ name="Market Research",
184
+ func=self.serper.search,
185
+ description="Search for market reports, statistics, and industry analysis"
186
+ )
187
+
188
+ self.competitor_search = Tool(
189
+ name="Competitor Analysis",
190
+ func=self.serper.search,
191
+ description="Research specific companies, their market position, and strategies"
192
+ )
193
 
194
  def create_research_crew(topic: str):
195
+ """Create an advanced research crew with specialized tools"""
196
  try:
197
+ tools = MarketResearchTools()
 
198
 
199
+ # Advanced Research Analyst
200
  researcher = Agent(
201
+ role='Senior Market Research Analyst',
202
+ goal=f'Conduct exhaustive market research about {topic} with detailed data and industry insights',
203
+ backstory="""You are a veteran market research analyst with 20+ years of experience.
204
+ You excel at uncovering hard-to-find data points, analyzing industry dynamics,
205
+ and identifying emerging trends. You have a strong network of industry contacts
206
+ and access to premium research databases. You always validate data through
207
+ multiple sources and provide confidence levels for your findings.""",
208
+ tools=[tools.market_search, tools.news_search, tools.competitor_search, tools.scraper],
209
  verbose=True
210
  )
211
 
212
+ # Industry Expert Analyst
213
  analyst = Agent(
214
+ role='Industry Expert & Strategy Analyst',
215
+ goal='Transform research into strategic insights and actionable recommendations',
216
+ backstory="""You are an industry expert with deep domain knowledge and strategic consulting
217
+ experience. You specialize in connecting market data to business implications,
218
+ forecasting industry changes, and developing strategic recommendations.
219
+ Your analysis is always backed by concrete examples and case studies.""",
220
+ tools=[tools.market_search, tools.competitor_search],
221
  verbose=True
222
  )
223
 
224
+ # Professional Report Writer
225
  writer = Agent(
226
+ role='Executive Report Writer',
227
+ goal='Create compelling, comprehensive market analysis reports',
228
+ backstory="""You are an experienced business writer who specializes in creating
229
+ executive-level market research reports. You excel at distilling complex
230
+ information into clear narratives while maintaining analytical rigor.
231
+ You always include relevant examples, case studies, and data visualizations.""",
232
  verbose=True
233
  )
234
 
235
+ # Create enhanced tasks
236
+ research_task = Task(
237
+ description=f"""
238
+ Conduct comprehensive market research on {topic} with the following focus areas:
239
+
240
+ 1. Market Overview:
241
+ - Current market size with specific values
242
+ - Historical growth patterns (5-year minimum)
243
+ - Future projections with CAGR
244
+ - Market segmentation analysis
245
+ - Regional market distribution
246
+ - Value chain analysis
247
+ - Pricing trends and dynamics
248
+
249
+ 2. Competitive Landscape:
250
+ - Detailed analysis of top 5-7 players
251
+ - Market share breakdown
252
+ - Competitive strategies
253
+ - Recent developments and initiatives
254
+ - SWOT analysis of major players
255
+ - Barriers to entry analysis
256
+ - Industry concentration metrics
257
+
258
+ 3. Technology & Innovation:
259
+ - Current technology trends
260
+ - Innovation patterns
261
+ - Patent analysis
262
+ - R&D investments
263
+ - Emerging technologies
264
+ - Digital transformation trends
265
+
266
+ 4. Regulatory & Environmental Factors:
267
+ - Current regulations
268
+ - Upcoming policy changes
269
+ - Environmental considerations
270
+ - Compliance requirements
271
+ - Industry standards
272
+ - Certification needs
273
+
274
+ Requirements:
275
+ - Use multiple sources for each data point
276
+ - Focus on recent data (last 12 months)
277
+ - Include source citations
278
+ - Note confidence levels for projections
279
+ - Identify any data gaps or inconsistencies
280
+ """,
281
+ agent=researcher,
282
+ expected_output="Comprehensive research data with verified sources and confidence levels"
283
+ )
284
+
285
+ analysis_task = Task(
286
+ description="""
287
+ Analyze the research findings and create strategic insights:
288
+
289
+ 1. Strategic Analysis:
290
+ - Porter's Five Forces analysis
291
+ - PESTLE analysis
292
+ - Value chain opportunities
293
+ - Growth vectors
294
+ - Market maturity assessment
295
+ - Investment potential
296
+
297
+ 2. Trend Analysis:
298
+ - Major market trends
299
+ - Technology impact assessment
300
+ - Consumer behavior shifts
301
+ - Emerging business models
302
+ - Future scenarios
303
+ - Risk assessment
304
+
305
+ 3. Strategic Implications:
306
+ - Market entry strategies
307
+ - Growth opportunities
308
+ - Potential threats
309
+ - Success factors
310
+ - Risk mitigation strategies
311
+ - Partnership opportunities
312
+
313
+ Requirements:
314
+ - Provide concrete examples
315
+ - Include case studies
316
+ - Support all conclusions with data
317
+ - Identify key success factors
318
+ - Assess market attractiveness
319
+ """,
320
+ agent=analyst,
321
+ expected_output="Strategic analysis with actionable insights",
322
+ context=[research_task]
323
+ )
324
+
325
+ report_task = Task(
326
+ description="""
327
+ Create a professional market research report:
328
+
329
+ 1. Executive Summary (2-3 pages):
330
+ - Key findings
331
+ - Market highlights
332
+ - Strategic implications
333
+ - Recommendations
334
+ - Investment thesis
335
+
336
+ 2. Comprehensive Analysis (15-20 pages):
337
+ - Detailed market analysis
338
+ - Competitive landscape
339
+ - Strategic insights
340
+ - Future outlook
341
+ - Risk analysis
342
+
343
+ 3. Supporting Materials:
344
+ - Case studies
345
+ - Company profiles
346
+ - Data tables
347
+ - Source citations
348
+ - Methodology notes
349
+
350
+ Requirements:
351
+ - Clear, professional writing
352
+ - Logical flow of information
353
+ - Evidence-based conclusions
354
+ - Actionable recommendations
355
+ - 5-10 credible sources
356
+ - Recent data points
357
+ """,
358
+ agent=writer,
359
+ expected_output="Professional report with executive summary and detailed analysis",
360
+ context=[research_task, analysis_task]
361
+ )
362
 
363
  return Crew(
364
  agents=[researcher, analyst, writer],
 
366
  verbose=True,
367
  process=Process.sequential
368
  )
369
+
370
  except Exception as e:
371
  raise Exception(f"Error initializing research crew: {str(e)}")