From 65401b570754e62300817c1d486b43814cc14956 Mon Sep 17 00:00:00 2001 From: Inaki Fernandez Date: Sat, 25 Apr 2026 12:08:49 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20corregir=20error=20de=20inicializaci?= =?UTF-8?q?=C3=B3n=20de=20pydantic-ai=20moviendo=20result=5Ftype=20al=20m?= =?UTF-8?q?=C3=A9todo=20run?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agentic_curator.py | 8 ++++++-- src/autonomous_discovery.py | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/agentic_curator.py b/src/agentic_curator.py index 075ca417..4469fa85 100644 --- a/src/agentic_curator.py +++ b/src/agentic_curator.py @@ -10,9 +10,12 @@ class LinkEvaluationResult(BaseModel): technical_description: str = Field(description="Descripción técnica de máx 150 caracteres.") evaluation_rationale: str = Field(description="Razonamiento de la decisión.") +# NOTA: En versiones recientes de pydantic-ai, result_type se pasa al ejecutar .run() +# o se define en la configuración del agente según la versión. +# Para máxima compatibilidad, lo definiremos aquí. + curation_agent = Agent( 'google-gla:gemini-2.0-flash-exp', - result_type=LinkEvaluationResult, system_prompt=( "Actúas como el Ingeniero Curador Principal de 'nubenetes/awesome-kubernetes'. " "Tu misión es filtrar recursos de altísima calidad sobre K8s, Agentes de IA, MCP y Cloud Native. " @@ -26,7 +29,8 @@ async def evaluate_extracted_assets(raw_assets: list[dict]) -> list[dict]: for asset in raw_assets: cognitive_prompt = f"Evalúa este candidato:\nURL: {asset['url']}\nContexto: {asset['context']}" try: - response = await curation_agent.run(cognitive_prompt) + # Pasamos result_type aquí para evitar errores de inicialización + response = await curation_agent.run(cognitive_prompt, result_type=LinkEvaluationResult) ev = response.data if ev.is_exceptional_value: for cat in ev.category_assignments: diff --git a/src/autonomous_discovery.py b/src/autonomous_discovery.py index a93fbf39..7a34b91d 100644 --- a/src/autonomous_discovery.py +++ b/src/autonomous_discovery.py @@ -24,7 +24,6 @@ async def fetch_github_trending_k8s() -> str: explorer_agent = Agent( 'google-gla:gemini-2.0-flash-exp', - result_type=DiscoveryReport, system_prompt=( "Descubre las 3 herramientas de Kubernetes más populares y recientes. " "Usa la herramienta 'fetch_github_trending_k8s'. " @@ -35,7 +34,10 @@ explorer_agent.tool(fetch_github_trending_k8s) async def discover_trending_assets() -> list[dict]: try: - response = await explorer_agent.run("Busca herramientas revolucionarias en el ecosistema.") + response = await explorer_agent.run( + "Busca herramientas revolucionarias en el ecosistema.", + result_type=DiscoveryReport + ) return [dict(res) for res in response.data.new_high_value_resources] except Exception as e: print(f"Error en descubrimiento: {str(e)}")