YanCotta commited on
Commit
018b50a
·
1 Parent(s): e47e72c

Add ResearcherAgent class for qualitative market research and sentiment analysis

Browse files
Files changed (1) hide show
  1. src/agents/researcher.py +86 -0
src/agents/researcher.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Researcher Agent - Qualitative market research specialist.
3
+
4
+ The Researcher agent focuses on gathering and synthesizing news,
5
+ sentiment, and qualitative information about companies.
6
+ """
7
+
8
+ import logging
9
+ from typing import Optional
10
+
11
+ from crewai import Agent
12
+
13
+ from src.agents.base import BaseAgentFactory, create_llm
14
+ from src.config.settings import get_settings
15
+ from src.tools.news_search import NewsSearchTool
16
+ from src.tools.memory import MemoryTool
17
+
18
+
19
+ logger = logging.getLogger(__name__)
20
+
21
+
22
+ class ResearcherAgent:
23
+ """
24
+ Factory and wrapper for the Researcher Agent.
25
+
26
+ The Researcher agent:
27
+ - Searches for recent news and developments
28
+ - Analyzes market sentiment
29
+ - Identifies key narratives and trends
30
+ - Verifies sources before including them
31
+ """
32
+
33
+ AGENT_NAME = "researcher"
34
+
35
+ def __init__(
36
+ self,
37
+ memory_tool: Optional[MemoryTool] = None,
38
+ news_tool: Optional[NewsSearchTool] = None
39
+ ):
40
+ """
41
+ Initialize the Researcher agent factory.
42
+
43
+ Args:
44
+ memory_tool: Optional shared memory tool instance
45
+ news_tool: Optional news search tool instance
46
+ """
47
+ self._memory_tool = memory_tool or MemoryTool()
48
+ self._news_tool = news_tool or NewsSearchTool()
49
+ self._agent: Optional[Agent] = None
50
+
51
+ def create(self) -> Agent:
52
+ """
53
+ Create and return the Researcher agent.
54
+
55
+ Returns:
56
+ Configured Researcher Agent instance
57
+ """
58
+ if self._agent is not None:
59
+ return self._agent
60
+
61
+ settings = get_settings()
62
+
63
+ # Researcher uses higher temperature for creative synthesis
64
+ llm = create_llm(
65
+ model=settings.worker_model,
66
+ temperature=settings.researcher_temperature
67
+ )
68
+
69
+ # Researcher gets news search and memory tools
70
+ tools = [self._news_tool, self._memory_tool]
71
+
72
+ self._agent = BaseAgentFactory.create_agent(
73
+ agent_name=self.AGENT_NAME,
74
+ llm=llm,
75
+ tools=tools
76
+ )
77
+
78
+ logger.info("Researcher agent created successfully")
79
+ return self._agent
80
+
81
+ @property
82
+ def agent(self) -> Agent:
83
+ """Get the agent instance, creating if necessary."""
84
+ if self._agent is None:
85
+ self.create()
86
+ return self._agent