Spaces:
Sleeping
Sleeping
Update agents.py
Browse files
agents.py
CHANGED
|
@@ -3,6 +3,7 @@ from crewai import Agent, Crew, Process, Task
|
|
| 3 |
from crewai_tools import SerperDevTool, ScrapeWebsiteTool
|
| 4 |
from langchain.tools import Tool
|
| 5 |
|
|
|
|
| 6 |
class MarketResearchTools:
|
| 7 |
"""Advanced research tools using Serper capabilities"""
|
| 8 |
|
|
@@ -10,31 +11,43 @@ class MarketResearchTools:
|
|
| 10 |
self.serper = SerperDevTool()
|
| 11 |
self.scraper = ScrapeWebsiteTool()
|
| 12 |
|
| 13 |
-
# Specialized search tools
|
| 14 |
self.news_search = Tool(
|
| 15 |
-
name="News
|
| 16 |
-
func=self.serper.
|
| 17 |
-
description="Search recent news articles
|
| 18 |
)
|
| 19 |
|
| 20 |
self.market_search = Tool(
|
| 21 |
name="Market Research",
|
| 22 |
-
func=self.serper.
|
| 23 |
-
description="Search for market reports
|
| 24 |
)
|
| 25 |
|
| 26 |
self.competitor_search = Tool(
|
| 27 |
name="Competitor Analysis",
|
| 28 |
-
func=self.serper.
|
| 29 |
-
description="Research
|
| 30 |
)
|
| 31 |
|
| 32 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
"""Create an advanced research crew with specialized tools"""
|
| 34 |
try:
|
| 35 |
tools = MarketResearchTools()
|
| 36 |
|
| 37 |
-
# Advanced Research Analyst
|
| 38 |
researcher = Agent(
|
| 39 |
role='Senior Market Research Analyst',
|
| 40 |
goal=f'Conduct exhaustive market research about {topic} with detailed data and industry insights',
|
|
@@ -43,11 +56,14 @@ def create_research_crew(topic: str):
|
|
| 43 |
and identifying emerging trends. You have a strong network of industry contacts
|
| 44 |
and access to premium research databases. You always validate data through
|
| 45 |
multiple sources and provide confidence levels for your findings.""",
|
| 46 |
-
tools=[
|
|
|
|
|
|
|
|
|
|
| 47 |
verbose=True
|
| 48 |
)
|
| 49 |
|
| 50 |
-
# Industry Expert Analyst
|
| 51 |
analyst = Agent(
|
| 52 |
role='Industry Expert & Strategy Analyst',
|
| 53 |
goal='Transform research into strategic insights and actionable recommendations',
|
|
@@ -55,11 +71,11 @@ def create_research_crew(topic: str):
|
|
| 55 |
experience. You specialize in connecting market data to business implications,
|
| 56 |
forecasting industry changes, and developing strategic recommendations.
|
| 57 |
Your analysis is always backed by concrete examples and case studies.""",
|
| 58 |
-
tools=[tools.market_search,
|
| 59 |
verbose=True
|
| 60 |
)
|
| 61 |
|
| 62 |
-
# Professional Report Writer
|
| 63 |
writer = Agent(
|
| 64 |
role='Executive Report Writer',
|
| 65 |
goal='Create compelling, comprehensive market analysis reports',
|
|
|
|
| 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 |
|
|
|
|
| 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',
|
|
|
|
| 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',
|
|
|
|
| 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',
|