Spaces:
Sleeping
Sleeping
| # 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 exact structure and formatting: | |
| === EXECUTIVE SUMMARY === | |
| [Main executive summary content here] | |
| ### Key Market Findings | |
| - Point 1 | |
| - Point 2 | |
| - Point 3 | |
| - verbose narrative to summarize your view | |
| ### Strategic Implications | |
| - Implication 1 | |
| - Implication 2 | |
| - Implication 3 | |
| - verbose narrative to summarize your view | |
| ### Recommendations | |
| - Recommendation 1 | |
| - Recommendation 2 | |
| - Recommendation 3 | |
| - verbose narrative to summarize your view | |
| === MARKET ANALYSIS === | |
| ### Market Overview | |
| [Detailed market overview including:] | |
| - Market size and valuation | |
| - Growth rates and projections | |
| - Market segmentation | |
| - Geographic distribution | |
| - Value chain analysis | |
| - verbose narrative to summarize your view | |
| ### Industry Dynamics | |
| [Comprehensive industry analysis including:] | |
| - Growth drivers | |
| - Market challenges | |
| - Emerging opportunities | |
| - Current trends | |
| - Technology impact | |
| - Regulatory landscape | |
| - verbose narrative to summarize your view | |
| ### Competitive Landscape | |
| [Detailed competitive analysis including:] | |
| - Market structure | |
| - Key player profiles | |
| - Market share analysis | |
| - Competitive strategies | |
| - Recent developments | |
| - SWOT analysis | |
| - Case studies | |
| - verbose narrative to summarize your view | |
| ### Strategic Analysis | |
| [Strategic insights including:] | |
| - Porter's Five Forces analysis | |
| - Success factors | |
| - Entry barriers | |
| - Risk assessment | |
| - Growth opportunities | |
| - verbose narrative to summarize your view | |
| === FUTURE OUTLOOK === | |
| [Detailed future projections and analysis including:] | |
| - Market forecasts | |
| - Emerging trends | |
| - Technology roadmap | |
| - Future scenarios | |
| - Strategic implications | |
| - verbose narrative to summarize your view | |
| === SOURCES === | |
| [List all sources with bullet points, including:] | |
| - Market research reports used | |
| - Industry databases referenced | |
| - Expert interviews conducted | |
| - Company reports analyzed | |
| - News articles and publications | |
| Important Instructions: | |
| 1. Use exactly these section markers (===) and subsection markers (###) | |
| 2. Provide detailed content under each section | |
| 3. Use bullet points for better readability | |
| 4. Include specific numbers and data points | |
| 5. Ensure proper formatting for each section | |
| 6. List all sources properly with bullet points | |
| 7. Where possible summarize and provide your narrative for better readership | |
| """, | |
| agent=writer, | |
| expected_output="A comprehensive market research report with proper section formatting", | |
| 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)}") |