VibecoderMcSwaggins commited on
Commit
bc74531
·
1 Parent(s): c690006

fix: address CodeRabbit Phase 7 review feedback

Browse files

- Lazy initialize HypothesisAgent's pydantic-ai Agent to avoid
requiring API keys at import time (fixes CI failure)
- Add explicit default=None to primary_hypothesis field for
Pydantic v2 compliance

src/agents/hypothesis_agent.py CHANGED
@@ -35,11 +35,17 @@ class HypothesisAgent(BaseAgent): # type: ignore[misc]
35
  )
36
  self._evidence_store = evidence_store
37
  self._embeddings = embedding_service # Used for MMR evidence selection
38
- self._agent = Agent(
39
- model=get_model(), # Uses configured LLM (OpenAI/Anthropic)
40
- output_type=HypothesisAssessment,
41
- system_prompt=SYSTEM_PROMPT,
42
- )
 
 
 
 
 
 
43
 
44
  async def run(
45
  self,
@@ -68,7 +74,7 @@ class HypothesisAgent(BaseAgent): # type: ignore[misc]
68
 
69
  # Generate hypotheses with diverse evidence selection
70
  prompt = await format_hypothesis_prompt(query, evidence, embeddings=self._embeddings)
71
- result = await self._agent.run(prompt)
72
  assessment = result.output # pydantic-ai returns .output for structured output
73
 
74
  # Store hypotheses in shared context
 
35
  )
36
  self._evidence_store = evidence_store
37
  self._embeddings = embedding_service # Used for MMR evidence selection
38
+ self._agent: Agent[None, HypothesisAssessment] | None = None # Lazy init
39
+
40
+ def _get_agent(self) -> Agent[None, HypothesisAssessment]:
41
+ """Lazy initialization of LLM agent to avoid requiring API keys at import."""
42
+ if self._agent is None:
43
+ self._agent = Agent(
44
+ model=get_model(), # Uses configured LLM (OpenAI/Anthropic)
45
+ output_type=HypothesisAssessment,
46
+ system_prompt=SYSTEM_PROMPT,
47
+ )
48
+ return self._agent
49
 
50
  async def run(
51
  self,
 
74
 
75
  # Generate hypotheses with diverse evidence selection
76
  prompt = await format_hypothesis_prompt(query, evidence, embeddings=self._embeddings)
77
+ result = await self._get_agent().run(prompt)
78
  assessment = result.output # pydantic-ai returns .output for structured output
79
 
80
  # Store hypotheses in shared context
src/utils/models.py CHANGED
@@ -166,7 +166,7 @@ class HypothesisAssessment(BaseModel):
166
 
167
  hypotheses: list[MechanismHypothesis]
168
  primary_hypothesis: MechanismHypothesis | None = Field(
169
- description="Most promising hypothesis based on current evidence"
170
  )
171
  knowledge_gaps: list[str] = Field(description="What we don't know yet")
172
  recommended_searches: list[str] = Field(description="Searches to fill knowledge gaps")
 
166
 
167
  hypotheses: list[MechanismHypothesis]
168
  primary_hypothesis: MechanismHypothesis | None = Field(
169
+ default=None, description="Most promising hypothesis based on current evidence"
170
  )
171
  knowledge_gaps: list[str] = Field(description="What we don't know yet")
172
  recommended_searches: list[str] = Field(description="Searches to fill knowledge gaps")