cryogenic22 commited on
Commit
6344f94
·
verified ·
1 Parent(s): 4f3496f

Update agents.py

Browse files
Files changed (1) hide show
  1. agents.py +149 -191
agents.py CHANGED
@@ -1,176 +1,135 @@
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
- # agents.py
7
- class MarketResearchTools:
8
- """Advanced research tools using Serper capabilities"""
9
-
10
- def __init__(self):
11
- self.serper = SerperDevTool()
12
- self.scraper = ScrapeWebsiteTool()
13
-
14
- # Specialized search tools using Serper's default search
15
- self.news_search = Tool(
16
- name="News Research",
17
- func=self.serper.run, # Using the standard run method
18
- description="Search for recent news articles and market updates"
19
- )
20
-
21
- self.market_search = Tool(
22
- name="Market Research",
23
- func=self.serper.run, # Using the standard run method
24
- description="Search for market reports and industry analysis"
25
- )
26
-
27
- self.competitor_search = Tool(
28
- name="Competitor Analysis",
29
- func=self.serper.run, # Using the standard run method
30
- description="Research companies and their market positions"
31
- )
32
-
33
- def search_with_type(self, query: str, search_type: str) -> str:
34
- """Custom search method with type specification"""
35
- base_query = query
36
- if search_type == "news":
37
- base_query = f"latest news about {query} market trends"
38
- elif search_type == "market":
39
- base_query = f"market research reports analysis {query} industry"
40
- elif search_type == "competitor":
41
- base_query = f"company analysis competitors {query} market share"
42
-
43
- return self.serper.run(base_query)
44
-
45
  def create_research_crew(topic: str):
46
  """Create an advanced research crew with specialized tools"""
47
  try:
48
- tools = MarketResearchTools()
 
 
49
 
50
- # Advanced Research Analyst with fixed tool setup
51
  researcher = Agent(
52
  role='Senior Market Research Analyst',
53
  goal=f'Conduct exhaustive market research about {topic} with detailed data and industry insights',
54
  backstory="""You are a veteran market research analyst with 20+ years of experience.
55
- You excel at uncovering hard-to-find data points, analyzing industry dynamics,
56
- and identifying emerging trends. You have a strong network of industry contacts
57
- and access to premium research databases. You always validate data through
58
- multiple sources and provide confidence levels for your findings.""",
59
- tools=[
60
- tools.market_search, # For general market research
61
- tools.scraper, # For website scraping
62
- ],
63
  verbose=True
64
  )
65
 
66
- # Industry Expert Analyst with market search capability
67
  analyst = Agent(
68
  role='Industry Expert & Strategy Analyst',
69
  goal='Transform research into strategic insights and actionable recommendations',
70
  backstory="""You are an industry expert with deep domain knowledge and strategic consulting
71
- experience. You specialize in connecting market data to business implications,
72
- forecasting industry changes, and developing strategic recommendations.
73
- Your analysis is always backed by concrete examples and case studies.""",
74
- tools=[tools.market_search], # Only needs market search
75
  verbose=True
76
  )
77
 
78
- # Professional Report Writer (no tools needed)
79
  writer = Agent(
80
  role='Executive Report Writer',
81
  goal='Create compelling, comprehensive market analysis reports',
82
  backstory="""You are an experienced business writer who specializes in creating
83
- executive-level market research reports. You excel at distilling complex
84
- information into clear narratives while maintaining analytical rigor.
85
- You always include relevant examples, case studies, and data visualizations.""",
86
  verbose=True
87
  )
88
 
89
  # Create enhanced tasks
90
  research_task = Task(
91
  description=f"""
92
- Conduct comprehensive market research on {topic} with the following focus areas:
93
-
94
- 1. Market Overview:
95
- - Current market size with specific values
96
- - Historical growth patterns (5-year minimum)
97
- - Future projections with CAGR
98
- - Market segmentation analysis
99
- - Regional market distribution
100
- - Value chain analysis
101
- - Pricing trends and dynamics
102
-
103
- 2. Competitive Landscape:
104
- - Detailed analysis of top 5-7 players
105
- - Market share breakdown
106
- - Competitive strategies
107
- - Recent developments and initiatives
108
- - SWOT analysis of major players
109
- - Barriers to entry analysis
110
- - Industry concentration metrics
111
-
112
- 3. Technology & Innovation:
113
- - Current technology trends
114
- - Innovation patterns
115
- - Patent analysis
116
- - R&D investments
117
- - Emerging technologies
118
- - Digital transformation trends
119
-
120
- 4. Regulatory & Environmental Factors:
121
- - Current regulations
122
- - Upcoming policy changes
123
- - Environmental considerations
124
- - Compliance requirements
125
- - Industry standards
126
- - Certification needs
127
-
128
- Requirements:
129
- - Use multiple sources for each data point
130
- - Focus on recent data (last 12 months)
131
- - Include source citations
132
- - Note confidence levels for projections
133
- - Identify any data gaps or inconsistencies
134
- """,
135
  agent=researcher,
136
  expected_output="Comprehensive research data with verified sources and confidence levels"
137
  )
138
 
139
  analysis_task = Task(
140
  description="""
141
- Analyze the research findings and create strategic insights:
142
-
143
- 1. Strategic Analysis:
144
- - Porter's Five Forces analysis
145
- - PESTLE analysis
146
- - Value chain opportunities
147
- - Growth vectors
148
- - Market maturity assessment
149
- - Investment potential
150
-
151
- 2. Trend Analysis:
152
- - Major market trends
153
- - Technology impact assessment
154
- - Consumer behavior shifts
155
- - Emerging business models
156
- - Future scenarios
157
- - Risk assessment
158
-
159
- 3. Strategic Implications:
160
- - Market entry strategies
161
- - Growth opportunities
162
- - Potential threats
163
- - Success factors
164
- - Risk mitigation strategies
165
- - Partnership opportunities
166
-
167
- Requirements:
168
- - Provide concrete examples
169
- - Include case studies
170
- - Support all conclusions with data
171
- - Identify key success factors
172
- - Assess market attractiveness
173
- """,
174
  agent=analyst,
175
  expected_output="Strategic analysis with actionable insights",
176
  context=[research_task]
@@ -178,68 +137,67 @@ def create_research_crew(topic: str):
178
 
179
  report_task = Task(
180
  description="""
181
- Create a comprehensive market research report:
182
-
183
- 1. Executive Summary (2-3 pages):
184
- - Key findings
185
- - Market highlights
186
- - Strategic implications
187
- - Recommendations
188
- - Investment thesis
189
-
190
- 2. Comprehensive Analysis (15-20 pages):
191
- - Detailed market analysis
192
- - Competitive landscape
193
- - Strategic insights
194
- - Future outlook
195
- - Risk analysis
196
-
197
- 3. Supporting Materials:
198
- - Case studies
199
- - Company profiles
200
- - Data tables
201
- - Source citations
202
- - Methodology notes
203
-
204
- Format as JSON:
205
- {
206
- "exec_summary": {
207
- "summary": "comprehensive executive overview",
208
- "market_highlights": "key market metrics and findings",
209
- "strategic_implications": "main strategic insights",
210
- "recommendations": "key recommendations"
211
- },
212
- "market_analysis": {
213
- "overview": "detailed market overview section",
214
- "dynamics": "comprehensive industry dynamics",
215
- "competitive_landscape": "detailed competitive analysis",
216
- "strategic_analysis": "in-depth strategic insights"
217
- },
218
- "future_outlook": "detailed future projections and implications",
219
- "appendices": "supporting data and sources",
220
- "sources": ["source1", "source2", "..."],
221
- "metrics": {
222
- "market_size": "current and projected size",
223
- "growth_rate": "historical and projected growth",
224
- "market_shares": "key player market shares",
225
- "key_metrics": "other important metrics"
226
- }
227
  }
228
-
229
- Requirements:
230
- - Clear, professional writing
231
- - Logical flow of information
232
- - Evidence-based conclusions
233
- - Actionable recommendations
234
- - 5-10 credible sources
235
- - Recent data points
236
- """,
 
237
  agent=writer,
238
  expected_output="Professional report with executive summary and detailed analysis",
239
  context=[research_task, analysis_task]
240
  )
241
 
242
- # Create and return the crew
243
  return Crew(
244
  agents=[researcher, analyst, writer],
245
  tasks=[research_task, analysis_task, report_task],
 
1
  # agents.py
2
  from crewai import Agent, Crew, Process, Task
3
  from crewai_tools import SerperDevTool, ScrapeWebsiteTool
 
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  def create_research_crew(topic: str):
6
  """Create an advanced research crew with specialized tools"""
7
  try:
8
+ # Initialize tools directly - no wrapper needed
9
+ search_tool = SerperDevTool()
10
+ scrape_tool = ScrapeWebsiteTool()
11
 
12
+ # Advanced Research Analyst
13
  researcher = Agent(
14
  role='Senior Market Research Analyst',
15
  goal=f'Conduct exhaustive market research about {topic} with detailed data and industry insights',
16
  backstory="""You are a veteran market research analyst with 20+ years of experience.
17
+ You excel at uncovering hard-to-find data points, analyzing industry dynamics,
18
+ and identifying emerging trends. You have a strong network of industry contacts
19
+ and access to premium research databases. You always validate data through
20
+ multiple sources and provide confidence levels for your findings.""",
21
+ tools=[search_tool, scrape_tool], # Use tools directly
 
 
 
22
  verbose=True
23
  )
24
 
25
+ # Industry Expert Analyst
26
  analyst = Agent(
27
  role='Industry Expert & Strategy Analyst',
28
  goal='Transform research into strategic insights and actionable recommendations',
29
  backstory="""You are an industry expert with deep domain knowledge and strategic consulting
30
+ experience. You specialize in connecting market data to business implications,
31
+ forecasting industry changes, and developing strategic recommendations.
32
+ Your analysis is always backed by concrete examples and case studies.""",
33
+ tools=[search_tool], # Only needs search tool
34
  verbose=True
35
  )
36
 
37
+ # Professional Report Writer
38
  writer = Agent(
39
  role='Executive Report Writer',
40
  goal='Create compelling, comprehensive market analysis reports',
41
  backstory="""You are an experienced business writer who specializes in creating
42
+ executive-level market research reports. You excel at distilling complex
43
+ information into clear narratives while maintaining analytical rigor.
44
+ You always include relevant examples, case studies, and data visualizations.""",
45
  verbose=True
46
  )
47
 
48
  # Create enhanced tasks
49
  research_task = Task(
50
  description=f"""
51
+ Conduct comprehensive market research on {topic} with the following focus areas:
52
+
53
+ 1. Market Overview:
54
+ - Current market size with specific values
55
+ - Historical growth patterns (5-year minimum)
56
+ - Future projections with CAGR
57
+ - Market segmentation analysis
58
+ - Regional market distribution
59
+ - Value chain analysis
60
+ - Pricing trends and dynamics
61
+
62
+ 2. Competitive Landscape:
63
+ - Detailed analysis of top 5-7 players
64
+ - Market share breakdown
65
+ - Competitive strategies
66
+ - Recent developments and initiatives
67
+ - SWOT analysis of major players
68
+ - Barriers to entry analysis
69
+ - Industry concentration metrics
70
+
71
+ 3. Technology & Innovation:
72
+ - Current technology trends
73
+ - Innovation patterns
74
+ - Patent analysis
75
+ - R&D investments
76
+ - Emerging technologies
77
+ - Digital transformation trends
78
+
79
+ 4. Regulatory & Environmental Factors:
80
+ - Current regulations
81
+ - Upcoming policy changes
82
+ - Environmental considerations
83
+ - Compliance requirements
84
+ - Industry standards
85
+ - Certification needs
86
+
87
+ Requirements:
88
+ - Use multiple sources for each data point
89
+ - Focus on recent data (last 12 months)
90
+ - Include source citations
91
+ - Note confidence levels for projections
92
+ - Identify any data gaps or inconsistencies
93
+ """,
94
  agent=researcher,
95
  expected_output="Comprehensive research data with verified sources and confidence levels"
96
  )
97
 
98
  analysis_task = Task(
99
  description="""
100
+ Analyze the research findings and create strategic insights:
101
+
102
+ 1. Strategic Analysis:
103
+ - Porter's Five Forces analysis
104
+ - PESTLE analysis
105
+ - Value chain opportunities
106
+ - Growth vectors
107
+ - Market maturity assessment
108
+ - Investment potential
109
+
110
+ 2. Trend Analysis:
111
+ - Major market trends
112
+ - Technology impact assessment
113
+ - Consumer behavior shifts
114
+ - Emerging business models
115
+ - Future scenarios
116
+ - Risk assessment
117
+
118
+ 3. Strategic Implications:
119
+ - Market entry strategies
120
+ - Growth opportunities
121
+ - Potential threats
122
+ - Success factors
123
+ - Risk mitigation strategies
124
+ - Partnership opportunities
125
+
126
+ Requirements:
127
+ - Provide concrete examples
128
+ - Include case studies
129
+ - Support all conclusions with data
130
+ - Identify key success factors
131
+ - Assess market attractiveness
132
+ """,
133
  agent=analyst,
134
  expected_output="Strategic analysis with actionable insights",
135
  context=[research_task]
 
137
 
138
  report_task = Task(
139
  description="""
140
+ Create a comprehensive market research report:
141
+
142
+ 1. Executive Summary (2-3 pages):
143
+ - Key findings
144
+ - Market highlights
145
+ - Strategic implications
146
+ - Recommendations
147
+ - Investment thesis
148
+
149
+ 2. Comprehensive Analysis (15-20 pages):
150
+ - Detailed market analysis
151
+ - Competitive landscape
152
+ - Strategic insights
153
+ - Future outlook
154
+ - Risk analysis
155
+
156
+ 3. Supporting Materials:
157
+ - Case studies
158
+ - Company profiles
159
+ - Data tables
160
+ - Source citations
161
+ - Methodology notes
162
+
163
+ Format as JSON:
164
+ {
165
+ "exec_summary": {
166
+ "summary": "comprehensive executive overview",
167
+ "market_highlights": "key market metrics and findings",
168
+ "strategic_implications": "main strategic insights",
169
+ "recommendations": "key recommendations"
170
+ },
171
+ "market_analysis": {
172
+ "overview": "detailed market overview section",
173
+ "dynamics": "comprehensive industry dynamics",
174
+ "competitive_landscape": "detailed competitive analysis",
175
+ "strategic_analysis": "in-depth strategic insights"
176
+ },
177
+ "future_outlook": "detailed future projections and implications",
178
+ "appendices": "supporting data and sources",
179
+ "sources": ["source1", "source2", "..."],
180
+ "metrics": {
181
+ "market_size": "current and projected size",
182
+ "growth_rate": "historical and projected growth",
183
+ "market_shares": "key player market shares",
184
+ "key_metrics": "other important metrics"
 
185
  }
186
+ }
187
+
188
+ Requirements:
189
+ - Clear, professional writing
190
+ - Logical flow of information
191
+ - Evidence-based conclusions
192
+ - Actionable recommendations
193
+ - 5-10 credible sources
194
+ - Recent data points
195
+ """,
196
  agent=writer,
197
  expected_output="Professional report with executive summary and detailed analysis",
198
  context=[research_task, analysis_task]
199
  )
200
 
 
201
  return Crew(
202
  agents=[researcher, analyst, writer],
203
  tasks=[research_task, analysis_task, report_task],