|
1 | | -"""Claim Lattice Expert Implementation.""" |
| 1 | +"""Claim Lattice Expert Implementation (Grounded with Real-World Search).""" |
2 | 2 | from typing import Dict, Any |
3 | 3 | from epistemic_forge.experts.base import EpistemicExpert |
4 | 4 | from epistemic_forge.models import ProjectSpec, ClaimLatticeOutput |
5 | 5 | from epistemic_forge.llm import generate_structured |
| 6 | +from epistemic_forge.tools.search import search_web |
6 | 7 | from loguru import logger |
7 | 8 |
|
8 | 9 | class ClaimLatticeExpert(EpistemicExpert): |
9 | 10 | """Deconstructs the question into a structured, epistemically grounded claim lattice.""" |
10 | 11 |
|
11 | 12 | @property |
12 | 13 | def expert_name(self) -> str: |
13 | | - return "Epistemic_Claim_Lattice_Generator" |
| 14 | + return "Grounded_Claim_Lattice_Generator" |
14 | 15 |
|
15 | 16 | def analyze(self, spec: ProjectSpec, context: Dict[str, Any]) -> ClaimLatticeOutput: |
16 | | - """Forces the LLM to generate claims ONLY if it can provide a warrant/explanation.""" |
| 17 | + """Uses Live Web Search to ground the LLM's claims in reality.""" |
| 18 | + |
| 19 | + # 1. Fetch real-world context before asking the LLM to build claims |
| 20 | + logger.debug("Gathering live empirical data to prevent hallucination...") |
| 21 | + search_query = f"{spec.question} scientific consensus" |
| 22 | + live_evidence = search_web(search_query, max_results=3) |
17 | 23 |
|
18 | 24 | messages = [ |
19 | 25 | { |
20 | 26 | "role": "system", |
21 | 27 | "content": ( |
22 | | - "You are a rigorous analytical philosopher and scientist. Your task is to break down the user's premise into a 'Claim Lattice'. " |
23 | | - "CRITICAL RULE: You are strictly forbidden from making ANY claim without providing an 'epistemic_warrant' (a clear logical explanation or evidence) " |
24 | | - "and a 'potential_falsifier' (what would prove it wrong). No confident mush allowed." |
| 28 | + "You are a rigorous analytical philosopher and empirical scientist. Your task is to break down the user's premise into a 'Claim Lattice'. " |
| 29 | + "CRITICAL RULE: You MUST ground your claims using the 'Live Evidence' provided. Do not hallucinate. " |
| 30 | + "You are strictly forbidden from making ANY claim without providing an 'epistemic_warrant' (a clear logical explanation) " |
| 31 | + "and a 'potential_falsifier'. No confident mush allowed." |
25 | 32 | ) |
26 | 33 | }, |
27 | 34 | { |
28 | 35 | "role": "user", |
29 | | - "content": f"Core Premise: {spec.question}\nKeywords: {spec.keywords}\nDeconstruct this into rigorously grounded claims." |
| 36 | + "content": f"Core Premise: {spec.question}\nKeywords: {spec.keywords}\n\n=== LIVE EMPIRICAL EVIDENCE ===\n{live_evidence}\n=====================\n\nDeconstruct this into rigorously grounded claims, citing the evidence where applicable." |
30 | 37 | } |
31 | 38 | ] |
32 | 39 |
|
33 | | - logger.debug("Dispatching to LLM for Claim Lattice Generation (Enforcing Truthfulness)...") |
| 40 | + logger.debug("Dispatching to LLM for Grounded Claim Lattice Generation...") |
34 | 41 | return generate_structured( |
35 | 42 | messages=messages, |
36 | 43 | response_model=ClaimLatticeOutput, |
|
0 commit comments