feat: add Meta-Reasoning Layer

This commit is contained in:
2026-03-30 22:16:19 +00:00
parent bf82581189
commit fdce07ff40

47
agent/meta_reasoning.py Normal file
View File

@@ -0,0 +1,47 @@
"""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)}