Spaces:
Sleeping
Sleeping
Update agents.py
Browse files
agents.py
CHANGED
|
@@ -160,171 +160,9 @@ def create_research_crew(topic: str):
|
|
| 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
|
| 328 |
|
| 329 |
1. Executive Summary (2-3 pages):
|
| 330 |
- Key findings
|
|
@@ -347,6 +185,31 @@ def create_research_crew(topic: str):
|
|
| 347 |
- Source citations
|
| 348 |
- Methodology notes
|
| 349 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
Requirements:
|
| 351 |
- Clear, professional writing
|
| 352 |
- Logical flow of information
|
|
@@ -360,6 +223,7 @@ def create_research_crew(topic: str):
|
|
| 360 |
context=[research_task, analysis_task]
|
| 361 |
)
|
| 362 |
|
|
|
|
| 363 |
return Crew(
|
| 364 |
agents=[researcher, analyst, writer],
|
| 365 |
tasks=[research_task, analysis_task, report_task],
|
|
@@ -368,4 +232,4 @@ def create_research_crew(topic: str):
|
|
| 368 |
)
|
| 369 |
|
| 370 |
except Exception as e:
|
| 371 |
-
raise Exception(f"Error initializing research crew: {str(e)}")
|
|
|
|
| 160 |
context=[research_task]
|
| 161 |
)
|
| 162 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
|
| 166 |
|
| 167 |
1. Executive Summary (2-3 pages):
|
| 168 |
- Key findings
|
|
|
|
| 185 |
- Source citations
|
| 186 |
- Methodology notes
|
| 187 |
|
| 188 |
+
Format as JSON:
|
| 189 |
+
{
|
| 190 |
+
"exec_summary": {
|
| 191 |
+
"summary": "comprehensive executive overview",
|
| 192 |
+
"market_highlights": "key market metrics and findings",
|
| 193 |
+
"strategic_implications": "main strategic insights",
|
| 194 |
+
"recommendations": "key recommendations"
|
| 195 |
+
},
|
| 196 |
+
"market_analysis": {
|
| 197 |
+
"overview": "detailed market overview section",
|
| 198 |
+
"dynamics": "comprehensive industry dynamics",
|
| 199 |
+
"competitive_landscape": "detailed competitive analysis",
|
| 200 |
+
"strategic_analysis": "in-depth strategic insights"
|
| 201 |
+
},
|
| 202 |
+
"future_outlook": "detailed future projections and implications",
|
| 203 |
+
"appendices": "supporting data and sources",
|
| 204 |
+
"sources": ["source1", "source2", "..."],
|
| 205 |
+
"metrics": {
|
| 206 |
+
"market_size": "current and projected size",
|
| 207 |
+
"growth_rate": "historical and projected growth",
|
| 208 |
+
"market_shares": "key player market shares",
|
| 209 |
+
"key_metrics": "other important metrics"
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
Requirements:
|
| 214 |
- Clear, professional writing
|
| 215 |
- Logical flow of information
|
|
|
|
| 223 |
context=[research_task, analysis_task]
|
| 224 |
)
|
| 225 |
|
| 226 |
+
# Create and return the crew
|
| 227 |
return Crew(
|
| 228 |
agents=[researcher, analyst, writer],
|
| 229 |
tasks=[research_task, analysis_task, report_task],
|
|
|
|
| 232 |
)
|
| 233 |
|
| 234 |
except Exception as e:
|
| 235 |
+
raise Exception(f"Error initializing research crew: {str(e)}")
|