"""Phase 3: Deep Knowledge Distillation from Google. Performs deep dives into technical domains and distills them into Timmy's Sovereign Knowledge Graph. """ import logging import json from typing import List, Dict, Any from agent.gemini_adapter import GeminiAdapter from agent.symbolic_memory import SymbolicMemory logger = logging.getLogger(__name__) class DomainDistiller: def __init__(self): self.adapter = GeminiAdapter() self.symbolic = SymbolicMemory() def distill_domain(self, domain: str): """Crawls and distills an entire technical domain.""" logger.info(f"Distilling domain: {domain}") prompt = f""" Please perform a deep knowledge distillation of the following domain: {domain} Use Google Search to find foundational papers, recent developments, and key entities. Synthesize this into a structured 'Domain Map' consisting of high-fidelity knowledge triples. Focus on the structural relationships that define the domain. Format: [{{"s": "subject", "p": "predicate", "o": "object"}}] """ result = self.adapter.generate( model="gemini-3.1-pro-preview", prompt=prompt, system_instruction=f"You are Timmy's Domain Distiller. Your goal is to map the entire {domain} domain into a structured Knowledge Graph.", grounding=True, thinking=True, response_mime_type="application/json" ) triples = json.loads(result["text"]) count = self.symbolic.ingest_text(json.dumps(triples)) logger.info(f"Distilled {count} new triples for domain: {domain}") return count