Skip to content

Commit 0a91bac

Browse files
committed
fix: Properly define agent fields in Pydantic models
- Add llm field to base Agent class - Add vector_store field to ResearchAgent - Fix initialization of agent fields through super().__init__
1 parent 3b7ca5c commit 0a91bac

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

agentic_rag/agents/agent_factory.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ class Agent(BaseModel):
88
name: str
99
role: str
1010
description: str
11+
llm: Any = Field(description="Language model for the agent")
1112

1213
class PlannerAgent(Agent):
1314
"""Agent responsible for breaking down problems and planning steps"""
1415
def __init__(self, llm):
1516
super().__init__(
1617
name="Planner",
1718
role="Strategic Planner",
18-
description="Breaks down complex problems into manageable steps"
19+
description="Breaks down complex problems into manageable steps",
20+
llm=llm
1921
)
20-
self.llm = llm
2122

2223
def plan(self, query: str, context: List[Dict[str, Any]] = None) -> str:
2324
if context:
@@ -51,14 +52,16 @@ def plan(self, query: str, context: List[Dict[str, Any]] = None) -> str:
5152

5253
class ResearchAgent(Agent):
5354
"""Agent responsible for gathering and analyzing information"""
55+
vector_store: Any = Field(description="Vector store for searching")
56+
5457
def __init__(self, llm, vector_store):
5558
super().__init__(
5659
name="Researcher",
5760
role="Information Gatherer",
58-
description="Gathers and analyzes relevant information from knowledge bases"
61+
description="Gathers and analyzes relevant information from knowledge bases",
62+
llm=llm,
63+
vector_store=vector_store
5964
)
60-
self.llm = llm
61-
self.vector_store = vector_store
6265

6366
def research(self, query: str, step: str) -> List[Dict[str, Any]]:
6467
# Query all collections
@@ -96,9 +99,9 @@ def __init__(self, llm):
9699
super().__init__(
97100
name="Reasoner",
98101
role="Logic and Analysis",
99-
description="Applies logical reasoning to information and draws conclusions"
102+
description="Applies logical reasoning to information and draws conclusions",
103+
llm=llm
100104
)
101-
self.llm = llm
102105

103106
def reason(self, query: str, step: str, context: List[Dict[str, Any]]) -> str:
104107
template = """You are a reasoning agent. Your role is to apply logical analysis to information and draw conclusions.
@@ -127,9 +130,9 @@ def __init__(self, llm):
127130
super().__init__(
128131
name="Synthesizer",
129132
role="Information Synthesizer",
130-
description="Combines multiple pieces of information into a coherent response"
133+
description="Combines multiple pieces of information into a coherent response",
134+
llm=llm
131135
)
132-
self.llm = llm
133136

134137
def synthesize(self, query: str, reasoning_steps: List[str]) -> str:
135138
template = """You are a synthesis agent. Your role is to combine multiple pieces of information into a clear, coherent response.

0 commit comments

Comments
 (0)