Spaces:
Sleeping
Sleeping
| # agents.py | |
| from crewai import Agent, Crew, Process, Task | |
| from crewai_tools import SerperDevTool, ScrapeWebsiteTool | |
| from langchain.tools import Tool | |
| class MarketResearchTools: | |
| """Advanced research tools using Serper capabilities""" | |
| def __init__(self): | |
| self.serper = SerperDevTool() | |
| self.scraper = ScrapeWebsiteTool() | |
| # Specialized search tools | |
| self.news_search = Tool( | |
| name="News Search", | |
| func=self.serper.search_news, | |
| description="Search recent news articles, press releases, and media coverage" | |
| ) | |
| self.market_search = Tool( | |
| name="Market Research", | |
| func=self.serper.search, | |
| description="Search for market reports, statistics, and industry analysis" | |
| ) | |
| self.competitor_search = Tool( | |
| name="Competitor Analysis", | |
| func=self.serper.search, | |
| description="Research specific companies, their market position, and strategies" | |
| ) | |
| def create_research_crew(topic: str): | |
| """Create an advanced research crew with specialized tools""" | |
| try: | |
| tools = MarketResearchTools() | |
| # Advanced Research Analyst | |
| researcher = Agent( | |
| role='Senior Market Research Analyst', | |
| goal=f'Conduct exhaustive market research about {topic} with detailed data and industry insights', | |
| backstory="""You are a veteran market research analyst with 20+ years of experience. | |
| You excel at uncovering hard-to-find data points, analyzing industry dynamics, | |
| and identifying emerging trends. You have a strong network of industry contacts | |
| and access to premium research databases. You always validate data through | |
| multiple sources and provide confidence levels for your findings.""", | |
| tools=[tools.market_search, tools.news_search, tools.competitor_search, tools.scraper], | |
| verbose=True | |
| ) | |
| # Industry Expert Analyst | |
| analyst = Agent( | |
| role='Industry Expert & Strategy Analyst', | |
| goal='Transform research into strategic insights and actionable recommendations', | |
| backstory="""You are an industry expert with deep domain knowledge and strategic consulting | |
| experience. You specialize in connecting market data to business implications, | |
| forecasting industry changes, and developing strategic recommendations. | |
| Your analysis is always backed by concrete examples and case studies.""", | |
| tools=[tools.market_search, tools.competitor_search], | |
| verbose=True | |
| ) | |
| # Professional Report Writer | |
| writer = Agent( | |
| role='Executive Report Writer', | |
| goal='Create compelling, comprehensive market analysis reports', | |
| backstory="""You are an experienced business writer who specializes in creating | |
| executive-level market research reports. You excel at distilling complex | |
| information into clear narratives while maintaining analytical rigor. | |
| You always include relevant examples, case studies, and data visualizations.""", | |
| verbose=True | |
| ) | |
| # Create enhanced tasks | |
| research_task = Task( | |
| description=f""" | |
| Conduct comprehensive market research on {topic} with the following focus areas: | |
| 1. Market Overview: | |
| - Current market size with specific values | |
| - Historical growth patterns (5-year minimum) | |
| - Future projections with CAGR | |
| - Market segmentation analysis | |
| - Regional market distribution | |
| - Value chain analysis | |
| - Pricing trends and dynamics | |
| 2. Competitive Landscape: | |
| - Detailed analysis of top 5-7 players | |
| - Market share breakdown | |
| - Competitive strategies | |
| - Recent developments and initiatives | |
| - SWOT analysis of major players | |
| - Barriers to entry analysis | |
| - Industry concentration metrics | |
| 3. Technology & Innovation: | |
| - Current technology trends | |
| - Innovation patterns | |
| - Patent analysis | |
| - R&D investments | |
| - Emerging technologies | |
| - Digital transformation trends | |
| 4. Regulatory & Environmental Factors: | |
| - Current regulations | |
| - Upcoming policy changes | |
| - Environmental considerations | |
| - Compliance requirements | |
| - Industry standards | |
| - Certification needs | |
| Requirements: | |
| - Use multiple sources for each data point | |
| - Focus on recent data (last 12 months) | |
| - Include source citations | |
| - Note confidence levels for projections | |
| - Identify any data gaps or inconsistencies | |
| """, | |
| agent=researcher, | |
| expected_output="Comprehensive research data with verified sources and confidence levels" | |
| ) | |
| analysis_task = Task( | |
| description=""" | |
| Analyze the research findings and create strategic insights: | |
| 1. Strategic Analysis: | |
| - Porter's Five Forces analysis | |
| - PESTLE analysis | |
| - Value chain opportunities | |
| - Growth vectors | |
| - Market maturity assessment | |
| - Investment potential | |
| 2. Trend Analysis: | |
| - Major market trends | |
| - Technology impact assessment | |
| - Consumer behavior shifts | |
| - Emerging business models | |
| - Future scenarios | |
| - Risk assessment | |
| 3. Strategic Implications: | |
| - Market entry strategies | |
| - Growth opportunities | |
| - Potential threats | |
| - Success factors | |
| - Risk mitigation strategies | |
| - Partnership opportunities | |
| Requirements: | |
| - Provide concrete examples | |
| - Include case studies | |
| - Support all conclusions with data | |
| - Identify key success factors | |
| - Assess market attractiveness | |
| """, | |
| agent=analyst, | |
| expected_output="Strategic analysis with actionable insights", | |
| context=[research_task] | |
| ) | |
| report_task = Task( | |
| description=""" | |
| Create a comprehensive market research report: | |
| 1. Executive Summary (2-3 pages): | |
| - Key findings | |
| - Market highlights | |
| - Strategic implications | |
| - Recommendations | |
| - Investment thesis | |
| 2. Comprehensive Analysis (15-20 pages): | |
| - Detailed market analysis | |
| - Competitive landscape | |
| - Strategic insights | |
| - Future outlook | |
| - Risk analysis | |
| 3. Supporting Materials: | |
| - Case studies | |
| - Company profiles | |
| - Data tables | |
| - Source citations | |
| - Methodology notes | |
| Format as JSON: | |
| { | |
| "exec_summary": { | |
| "summary": "comprehensive executive overview", | |
| "market_highlights": "key market metrics and findings", | |
| "strategic_implications": "main strategic insights", | |
| "recommendations": "key recommendations" | |
| }, | |
| "market_analysis": { | |
| "overview": "detailed market overview section", | |
| "dynamics": "comprehensive industry dynamics", | |
| "competitive_landscape": "detailed competitive analysis", | |
| "strategic_analysis": "in-depth strategic insights" | |
| }, | |
| "future_outlook": "detailed future projections and implications", | |
| "appendices": "supporting data and sources", | |
| "sources": ["source1", "source2", "..."], | |
| "metrics": { | |
| "market_size": "current and projected size", | |
| "growth_rate": "historical and projected growth", | |
| "market_shares": "key player market shares", | |
| "key_metrics": "other important metrics" | |
| } | |
| } | |
| Requirements: | |
| - Clear, professional writing | |
| - Logical flow of information | |
| - Evidence-based conclusions | |
| - Actionable recommendations | |
| - 5-10 credible sources | |
| - Recent data points | |
| """, | |
| agent=writer, | |
| expected_output="Professional report with executive summary and detailed analysis", | |
| context=[research_task, analysis_task] | |
| ) | |
| # Create and return the crew | |
| return Crew( | |
| agents=[researcher, analyst, writer], | |
| tasks=[research_task, analysis_task, report_task], | |
| verbose=True, | |
| process=Process.sequential | |
| ) | |
| except Exception as e: | |
| raise Exception(f"Error initializing research crew: {str(e)}") |