# agents.py from crewai import Agent, Crew, Process, Task from crewai_tools import SerperDevTool, ScrapeWebsiteTool def create_research_crew(topic: str): """Create an advanced research crew with specialized tools""" try: # Initialize tools directly - no wrapper needed search_tool = SerperDevTool() scrape_tool = ScrapeWebsiteTool() # 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=[search_tool, scrape_tool], # Use tools directly 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=[search_tool], # Only needs search tool 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=""" === STRATEGIC ANALYSIS === Analyze the research findings to provide comprehensive strategic insights: 1. Industry Analysis ## Porter's Five Forces - Detailed analysis of each force - Overall industry attractiveness - Strategic implications - Future evolution ## PESTLE Analysis - Political factors and impacts - Economic drivers and constraints - Social and demographic influences - Technological enablers and threats - Legal and regulatory framework - Environmental considerations 2. Growth Vector Analysis ## Market Expansion Opportunities - Geographic expansion potential - Segment growth opportunities - New market opportunities - Market penetration strategies ## Product/Service Development - Innovation opportunities - Feature expansion potential - Service enhancement areas - Technology integration possibilities 3. Risk Assessment ## Market Risks - Competition risks - Technology risks - Regulatory risks - Economic risks ## Mitigation Strategies - Risk mitigation approaches - Alternative strategies - Contingency planning - Success factors 4. Investment Analysis ## Market Attractiveness - Investment potential - ROI analysis - Payback periods - Capital requirements ## Success Requirements - Critical success factors - Core capabilities needed - Resource requirements - Timeline considerations Requirements: - Provide detailed analysis for each section - Include specific examples and case studies - Support conclusions with data - Consider multiple scenarios - Provide actionable insights - Include expert opinions """, agent=analyst, expected_output="Comprehensive strategic analysis with actionable insights", context=[research_task] ) report_task = Task( description=""" Create a comprehensive market research report following this structure: === EXECUTIVE SUMMARY === Start with a 2-3 page executive summary that includes: - Key market findings and insights - Critical market metrics and highlights - Major strategic implications - Core recommendations - Investment potential === MARKET ANALYSIS === Provide detailed market analysis covering: 1. Market Overview - Define market scope and segmentation - Current market size and valuation - Historical growth analysis - Future growth projections - Key market segments - Geographic distribution - Value chain analysis 2. Industry Dynamics - Growth drivers (with examples) - Market challenges - Emerging opportunities - Current trends - Technology impact - Regulatory landscape 3. Competitive Landscape - Market structure - Key player profiles - Market share analysis - Competitive strategies - Recent developments - SWOT analysis - Case studies 4. Strategic Analysis - Porter's Five Forces - Success factors - Entry barriers - Risk assessment - Growth vectors - Strategic recommendations === FUTURE OUTLOOK === Provide comprehensive future projections: - Market forecasts - Emerging trends - Technology roadmap - Future scenarios - Strategic implications === SOURCES AND METHODOLOGY === List all sources used and methodology followed. Requirements: - Write in clear, professional language - Use specific numbers and metrics - Include recent case studies - Cite 5-10 credible sources - Provide confidence levels for projections - Use contextual examples Structure the content with clear headings (use === for main sections and ## for subsections) Make it a narrative document that flows well and tells a story about the market. Important: Use the exact section markers (=== and ##) as shown above. Write detailed content for each section, replacing the placeholders. """, agent=writer, expected_output="A comprehensive narrative market research report with detailed analysis", context=[research_task, analysis_task] ) 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)}")