48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
"""Meta-Reasoning Layer for Hermes Agent.
|
|
|
|
Implements a sovereign self-correction loop where a 'strong' model (Gemini 3.1 Pro)
|
|
critiques the plans generated by the primary agent loop before execution.
|
|
"""
|
|
|
|
import logging
|
|
from typing import Any, Dict, List, Optional
|
|
from agent.gemini_adapter import GeminiAdapter
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
class MetaReasoningLayer:
|
|
def __init__(self):
|
|
self.adapter = GeminiAdapter()
|
|
|
|
def critique_plan(self, goal: str, proposed_plan: str, context: str) -> Dict[str, Any]:
|
|
"""Critiques a proposed plan using Gemini's thinking capabilities."""
|
|
prompt = f"""
|
|
Goal: {goal}
|
|
|
|
Context:
|
|
{context}
|
|
|
|
Proposed Plan:
|
|
{proposed_plan}
|
|
|
|
Please perform a deep symbolic and neuro-symbolic analysis of this plan.
|
|
Identify potential risks, logical fallacies, or missing steps.
|
|
Suggest improvements to make the plan more sovereign, cost-efficient, and robust.
|
|
"""
|
|
try:
|
|
result = self.adapter.generate(
|
|
model="gemini-3.1-pro-preview",
|
|
prompt=prompt,
|
|
system_instruction="You are a Senior Meta-Reasoning Engine for the Hermes Agent. Your goal is to ensure the agent's plans are flawless and sovereign.",
|
|
thinking=True,
|
|
thinking_budget=8000
|
|
)
|
|
return {
|
|
"critique": result["text"],
|
|
"thoughts": result.get("thoughts", ""),
|
|
"grounding": result.get("grounding")
|
|
}
|
|
except Exception as e:
|
|
logger.error(f"Meta-reasoning failed: {e}")
|
|
return {"critique": "Meta-reasoning unavailable.", "error": str(e)}
|