feat: consequence engine, causal world model, metacognition, interpretability, claim verification
Choice → Consequence → Learning:
- ConsequenceEngine tracks every decision point with alternatives,
risk/reward estimates, and actual outcomes
- Consequences feed into AdaptiveEthics for experience-based learning
- FusionAGILoop now wires ethics + consequences into task lifecycle
Causal World Model:
- CausalWorldModel learns state-transition patterns from execution history
- Predicts outcomes based on observed action→effect patterns
- Uncertainty estimates decrease as more evidence accumulates
Metacognition:
- assess_head_outputs() evaluates reasoning quality from head outputs
- Detects knowledge gaps, measures head agreement, identifies uncertainty
- Actively recommends whether to seek more information
Interpretability:
- ReasoningTracer captures full prompt→answer reasoning traces
- Each step records stage, component, input/output, timing
- explain() generates human-readable reasoning explanations
Claim Verification:
- ClaimVerifier cross-checks claims for evidence, consistency, grounding
- Flags high-confidence claims lacking evidence support
- Detects contradictions between claims from different heads
325 tests passing, 0 ruff errors, 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 06:25:35 +00:00
|
|
|
"""AGI loop: wires self-correction, auto-training, adaptive ethics, and
|
|
|
|
|
consequence tracking to the event bus.
|
|
|
|
|
|
|
|
|
|
Choice → Consequence → Learning:
|
|
|
|
|
- Every task failure/success is recorded as a consequence of the choices made.
|
|
|
|
|
- Consequences feed into AdaptiveEthics for learned ethical growth.
|
|
|
|
|
- The ConsequenceEngine tracks risk/reward patterns across all actions.
|
|
|
|
|
- Trust is earned through demonstrable learning from outcomes.
|
|
|
|
|
"""
|
2026-02-09 21:51:42 -08:00
|
|
|
|
|
|
|
|
from typing import Any, Callable
|
|
|
|
|
|
|
|
|
|
from fusionagi._logger import logger
|
fix: deep GPU integration, fix all ruff/mypy issues, add .dockerignore
- Integrate GPU scoring inline into reasoning/multi_path.py (auto-uses GPU when available)
- Integrate GPU deduplication into multi_agent/consensus_engine.py
- Add semantic_search() method to memory/semantic_graph.py with GPU acceleration
- Integrate GPU training into self_improvement/training.py AutoTrainer
- Fix all 758 ruff lint issues (whitespace, import sorting, unused imports, ambiguous vars, undefined names)
- Fix all 40 mypy type errors across the codebase (no-any-return, union-attr, arg-type, etc.)
- Fix deprecated ruff config keys (select/ignore -> [tool.ruff.lint])
- Add .dockerignore to exclude .venv/, tests/, docs/ from Docker builds
- Add type hints and docstrings to verification/outcome.py
- Fix E402 import ordering in witness_agent.py
- Fix F821 undefined names in vector_pgvector.py and native.py
- Fix E741 ambiguous variable names in reflective.py and recommender.py
All 276 tests pass. 0 ruff errors. 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 05:48:37 +00:00
|
|
|
from fusionagi.core.event_bus import EventBus
|
feat: consequence engine, causal world model, metacognition, interpretability, claim verification
Choice → Consequence → Learning:
- ConsequenceEngine tracks every decision point with alternatives,
risk/reward estimates, and actual outcomes
- Consequences feed into AdaptiveEthics for experience-based learning
- FusionAGILoop now wires ethics + consequences into task lifecycle
Causal World Model:
- CausalWorldModel learns state-transition patterns from execution history
- Predicts outcomes based on observed action→effect patterns
- Uncertainty estimates decrease as more evidence accumulates
Metacognition:
- assess_head_outputs() evaluates reasoning quality from head outputs
- Detects knowledge gaps, measures head agreement, identifies uncertainty
- Actively recommends whether to seek more information
Interpretability:
- ReasoningTracer captures full prompt→answer reasoning traces
- Each step records stage, component, input/output, timing
- explain() generates human-readable reasoning explanations
Claim Verification:
- ClaimVerifier cross-checks claims for evidence, consistency, grounding
- Flags high-confidence claims lacking evidence support
- Detects contradictions between claims from different heads
325 tests passing, 0 ruff errors, 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 06:25:35 +00:00
|
|
|
from fusionagi.governance.adaptive_ethics import AdaptiveEthics
|
|
|
|
|
from fusionagi.governance.audit_log import AuditLog
|
|
|
|
|
from fusionagi.governance.consequence_engine import ConsequenceEngine
|
fix: deep GPU integration, fix all ruff/mypy issues, add .dockerignore
- Integrate GPU scoring inline into reasoning/multi_path.py (auto-uses GPU when available)
- Integrate GPU deduplication into multi_agent/consensus_engine.py
- Add semantic_search() method to memory/semantic_graph.py with GPU acceleration
- Integrate GPU training into self_improvement/training.py AutoTrainer
- Fix all 758 ruff lint issues (whitespace, import sorting, unused imports, ambiguous vars, undefined names)
- Fix all 40 mypy type errors across the codebase (no-any-return, union-attr, arg-type, etc.)
- Fix deprecated ruff config keys (select/ignore -> [tool.ruff.lint])
- Add .dockerignore to exclude .venv/, tests/, docs/ from Docker builds
- Add type hints and docstrings to verification/outcome.py
- Fix E402 import ordering in witness_agent.py
- Fix F821 undefined names in vector_pgvector.py and native.py
- Fix E741 ambiguous variable names in reflective.py and recommender.py
All 276 tests pass. 0 ruff errors. 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 05:48:37 +00:00
|
|
|
from fusionagi.schemas.recommendation import Recommendation, TrainingSuggestion
|
|
|
|
|
from fusionagi.schemas.task import TaskState
|
2026-02-09 21:51:42 -08:00
|
|
|
from fusionagi.self_improvement.correction import (
|
fix: deep GPU integration, fix all ruff/mypy issues, add .dockerignore
- Integrate GPU scoring inline into reasoning/multi_path.py (auto-uses GPU when available)
- Integrate GPU deduplication into multi_agent/consensus_engine.py
- Add semantic_search() method to memory/semantic_graph.py with GPU acceleration
- Integrate GPU training into self_improvement/training.py AutoTrainer
- Fix all 758 ruff lint issues (whitespace, import sorting, unused imports, ambiguous vars, undefined names)
- Fix all 40 mypy type errors across the codebase (no-any-return, union-attr, arg-type, etc.)
- Fix deprecated ruff config keys (select/ignore -> [tool.ruff.lint])
- Add .dockerignore to exclude .venv/, tests/, docs/ from Docker builds
- Add type hints and docstrings to verification/outcome.py
- Fix E402 import ordering in witness_agent.py
- Fix F821 undefined names in vector_pgvector.py and native.py
- Fix E741 ambiguous variable names in reflective.py and recommender.py
All 276 tests pass. 0 ruff errors. 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 05:48:37 +00:00
|
|
|
CriticLike,
|
|
|
|
|
OrchestratorLike,
|
2026-02-09 21:51:42 -08:00
|
|
|
SelfCorrectionLoop,
|
|
|
|
|
StateManagerLike,
|
|
|
|
|
)
|
|
|
|
|
from fusionagi.self_improvement.recommender import AutoRecommender
|
|
|
|
|
from fusionagi.self_improvement.training import AutoTrainer, ReflectiveMemoryLike
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FusionAGILoop:
|
feat: consequence engine, causal world model, metacognition, interpretability, claim verification
Choice → Consequence → Learning:
- ConsequenceEngine tracks every decision point with alternatives,
risk/reward estimates, and actual outcomes
- Consequences feed into AdaptiveEthics for experience-based learning
- FusionAGILoop now wires ethics + consequences into task lifecycle
Causal World Model:
- CausalWorldModel learns state-transition patterns from execution history
- Predicts outcomes based on observed action→effect patterns
- Uncertainty estimates decrease as more evidence accumulates
Metacognition:
- assess_head_outputs() evaluates reasoning quality from head outputs
- Detects knowledge gaps, measures head agreement, identifies uncertainty
- Actively recommends whether to seek more information
Interpretability:
- ReasoningTracer captures full prompt→answer reasoning traces
- Each step records stage, component, input/output, timing
- explain() generates human-readable reasoning explanations
Claim Verification:
- ClaimVerifier cross-checks claims for evidence, consistency, grounding
- Flags high-confidence claims lacking evidence support
- Detects contradictions between claims from different heads
325 tests passing, 0 ruff errors, 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 06:25:35 +00:00
|
|
|
"""High-level AGI loop with consequence-driven learning.
|
|
|
|
|
|
|
|
|
|
Subscribes to task_state_changed and reflection_done events.
|
|
|
|
|
Runs self-correction on failures, auto-recommend + auto-training
|
|
|
|
|
after reflection, and feeds all outcomes into the adaptive ethics
|
|
|
|
|
and consequence engines.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
event_bus: Event bus for task and reflection events.
|
|
|
|
|
state_manager: State manager for task state and traces.
|
|
|
|
|
orchestrator: Orchestrator for plan and state transitions.
|
|
|
|
|
critic_agent: Critic agent for evaluation.
|
|
|
|
|
reflective_memory: Optional reflective memory for lessons/heuristics.
|
|
|
|
|
audit_log: Optional audit log for full transparency.
|
|
|
|
|
auto_retry_on_failure: Auto-retry failed tasks.
|
|
|
|
|
max_retries_per_task: Max retries per task (``None`` = unlimited).
|
|
|
|
|
on_recommendations: Callback for recommendations.
|
|
|
|
|
on_training_suggestions: Callback for training suggestions.
|
2026-02-09 21:51:42 -08:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
event_bus: EventBus,
|
|
|
|
|
state_manager: StateManagerLike,
|
|
|
|
|
orchestrator: OrchestratorLike,
|
|
|
|
|
critic_agent: CriticLike,
|
|
|
|
|
reflective_memory: ReflectiveMemoryLike | None = None,
|
feat: consequence engine, causal world model, metacognition, interpretability, claim verification
Choice → Consequence → Learning:
- ConsequenceEngine tracks every decision point with alternatives,
risk/reward estimates, and actual outcomes
- Consequences feed into AdaptiveEthics for experience-based learning
- FusionAGILoop now wires ethics + consequences into task lifecycle
Causal World Model:
- CausalWorldModel learns state-transition patterns from execution history
- Predicts outcomes based on observed action→effect patterns
- Uncertainty estimates decrease as more evidence accumulates
Metacognition:
- assess_head_outputs() evaluates reasoning quality from head outputs
- Detects knowledge gaps, measures head agreement, identifies uncertainty
- Actively recommends whether to seek more information
Interpretability:
- ReasoningTracer captures full prompt→answer reasoning traces
- Each step records stage, component, input/output, timing
- explain() generates human-readable reasoning explanations
Claim Verification:
- ClaimVerifier cross-checks claims for evidence, consistency, grounding
- Flags high-confidence claims lacking evidence support
- Detects contradictions between claims from different heads
325 tests passing, 0 ruff errors, 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 06:25:35 +00:00
|
|
|
audit_log: AuditLog | None = None,
|
2026-02-09 21:51:42 -08:00
|
|
|
*,
|
|
|
|
|
auto_retry_on_failure: bool = False,
|
feat: consequence engine, causal world model, metacognition, interpretability, claim verification
Choice → Consequence → Learning:
- ConsequenceEngine tracks every decision point with alternatives,
risk/reward estimates, and actual outcomes
- Consequences feed into AdaptiveEthics for experience-based learning
- FusionAGILoop now wires ethics + consequences into task lifecycle
Causal World Model:
- CausalWorldModel learns state-transition patterns from execution history
- Predicts outcomes based on observed action→effect patterns
- Uncertainty estimates decrease as more evidence accumulates
Metacognition:
- assess_head_outputs() evaluates reasoning quality from head outputs
- Detects knowledge gaps, measures head agreement, identifies uncertainty
- Actively recommends whether to seek more information
Interpretability:
- ReasoningTracer captures full prompt→answer reasoning traces
- Each step records stage, component, input/output, timing
- explain() generates human-readable reasoning explanations
Claim Verification:
- ClaimVerifier cross-checks claims for evidence, consistency, grounding
- Flags high-confidence claims lacking evidence support
- Detects contradictions between claims from different heads
325 tests passing, 0 ruff errors, 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 06:25:35 +00:00
|
|
|
max_retries_per_task: int | None = None,
|
2026-02-09 21:51:42 -08:00
|
|
|
on_recommendations: Callable[[list[Recommendation]], None] | None = None,
|
|
|
|
|
on_training_suggestions: Callable[[list[TrainingSuggestion]], None] | None = None,
|
|
|
|
|
) -> None:
|
|
|
|
|
self._event_bus = event_bus
|
|
|
|
|
self._state = state_manager
|
|
|
|
|
self._orchestrator = orchestrator
|
|
|
|
|
self._critic = critic_agent
|
|
|
|
|
self._memory = reflective_memory
|
|
|
|
|
self._auto_retry = auto_retry_on_failure
|
|
|
|
|
self._on_recs = on_recommendations
|
|
|
|
|
self._on_training = on_training_suggestions
|
|
|
|
|
|
feat: consequence engine, causal world model, metacognition, interpretability, claim verification
Choice → Consequence → Learning:
- ConsequenceEngine tracks every decision point with alternatives,
risk/reward estimates, and actual outcomes
- Consequences feed into AdaptiveEthics for experience-based learning
- FusionAGILoop now wires ethics + consequences into task lifecycle
Causal World Model:
- CausalWorldModel learns state-transition patterns from execution history
- Predicts outcomes based on observed action→effect patterns
- Uncertainty estimates decrease as more evidence accumulates
Metacognition:
- assess_head_outputs() evaluates reasoning quality from head outputs
- Detects knowledge gaps, measures head agreement, identifies uncertainty
- Actively recommends whether to seek more information
Interpretability:
- ReasoningTracer captures full prompt→answer reasoning traces
- Each step records stage, component, input/output, timing
- explain() generates human-readable reasoning explanations
Claim Verification:
- ClaimVerifier cross-checks claims for evidence, consistency, grounding
- Flags high-confidence claims lacking evidence support
- Detects contradictions between claims from different heads
325 tests passing, 0 ruff errors, 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 06:25:35 +00:00
|
|
|
self._audit = audit_log or AuditLog()
|
|
|
|
|
self._ethics = AdaptiveEthics(audit_log=self._audit)
|
|
|
|
|
self._consequences = ConsequenceEngine(audit_log=self._audit)
|
|
|
|
|
|
2026-02-09 21:51:42 -08:00
|
|
|
self._correction = SelfCorrectionLoop(
|
|
|
|
|
state_manager=state_manager,
|
|
|
|
|
orchestrator=orchestrator,
|
|
|
|
|
critic_agent=critic_agent,
|
|
|
|
|
max_retries_per_task=max_retries_per_task,
|
|
|
|
|
)
|
|
|
|
|
self._recommender = AutoRecommender(reflective_memory=reflective_memory)
|
feat: consequence engine, causal world model, metacognition, interpretability, claim verification
Choice → Consequence → Learning:
- ConsequenceEngine tracks every decision point with alternatives,
risk/reward estimates, and actual outcomes
- Consequences feed into AdaptiveEthics for experience-based learning
- FusionAGILoop now wires ethics + consequences into task lifecycle
Causal World Model:
- CausalWorldModel learns state-transition patterns from execution history
- Predicts outcomes based on observed action→effect patterns
- Uncertainty estimates decrease as more evidence accumulates
Metacognition:
- assess_head_outputs() evaluates reasoning quality from head outputs
- Detects knowledge gaps, measures head agreement, identifies uncertainty
- Actively recommends whether to seek more information
Interpretability:
- ReasoningTracer captures full prompt→answer reasoning traces
- Each step records stage, component, input/output, timing
- explain() generates human-readable reasoning explanations
Claim Verification:
- ClaimVerifier cross-checks claims for evidence, consistency, grounding
- Flags high-confidence claims lacking evidence support
- Detects contradictions between claims from different heads
325 tests passing, 0 ruff errors, 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 06:25:35 +00:00
|
|
|
self._trainer = AutoTrainer(
|
|
|
|
|
reflective_memory=reflective_memory,
|
|
|
|
|
audit_log=self._audit,
|
|
|
|
|
)
|
2026-02-09 21:51:42 -08:00
|
|
|
|
|
|
|
|
self._event_bus.subscribe("task_state_changed", self._on_task_state_changed)
|
|
|
|
|
self._event_bus.subscribe("reflection_done", self._on_reflection_done)
|
feat: consequence engine, causal world model, metacognition, interpretability, claim verification
Choice → Consequence → Learning:
- ConsequenceEngine tracks every decision point with alternatives,
risk/reward estimates, and actual outcomes
- Consequences feed into AdaptiveEthics for experience-based learning
- FusionAGILoop now wires ethics + consequences into task lifecycle
Causal World Model:
- CausalWorldModel learns state-transition patterns from execution history
- Predicts outcomes based on observed action→effect patterns
- Uncertainty estimates decrease as more evidence accumulates
Metacognition:
- assess_head_outputs() evaluates reasoning quality from head outputs
- Detects knowledge gaps, measures head agreement, identifies uncertainty
- Actively recommends whether to seek more information
Interpretability:
- ReasoningTracer captures full prompt→answer reasoning traces
- Each step records stage, component, input/output, timing
- explain() generates human-readable reasoning explanations
Claim Verification:
- ClaimVerifier cross-checks claims for evidence, consistency, grounding
- Flags high-confidence claims lacking evidence support
- Detects contradictions between claims from different heads
325 tests passing, 0 ruff errors, 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 06:25:35 +00:00
|
|
|
logger.info("FusionAGILoop: subscribed (with consequence + ethics engines)")
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def ethics(self) -> AdaptiveEthics:
|
|
|
|
|
"""Access the adaptive ethics engine."""
|
|
|
|
|
return self._ethics
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def consequences(self) -> ConsequenceEngine:
|
|
|
|
|
"""Access the consequence engine."""
|
|
|
|
|
return self._consequences
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def audit_log(self) -> AuditLog:
|
|
|
|
|
"""Access the audit log."""
|
|
|
|
|
return self._audit
|
2026-02-09 21:51:42 -08:00
|
|
|
|
|
|
|
|
def _on_task_state_changed(self, event_type: str, payload: dict[str, Any]) -> None:
|
feat: consequence engine, causal world model, metacognition, interpretability, claim verification
Choice → Consequence → Learning:
- ConsequenceEngine tracks every decision point with alternatives,
risk/reward estimates, and actual outcomes
- Consequences feed into AdaptiveEthics for experience-based learning
- FusionAGILoop now wires ethics + consequences into task lifecycle
Causal World Model:
- CausalWorldModel learns state-transition patterns from execution history
- Predicts outcomes based on observed action→effect patterns
- Uncertainty estimates decrease as more evidence accumulates
Metacognition:
- assess_head_outputs() evaluates reasoning quality from head outputs
- Detects knowledge gaps, measures head agreement, identifies uncertainty
- Actively recommends whether to seek more information
Interpretability:
- ReasoningTracer captures full prompt→answer reasoning traces
- Each step records stage, component, input/output, timing
- explain() generates human-readable reasoning explanations
Claim Verification:
- ClaimVerifier cross-checks claims for evidence, consistency, grounding
- Flags high-confidence claims lacking evidence support
- Detects contradictions between claims from different heads
325 tests passing, 0 ruff errors, 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 06:25:35 +00:00
|
|
|
"""On state change, record consequences and optionally retry."""
|
2026-02-09 21:51:42 -08:00
|
|
|
try:
|
|
|
|
|
to_state = payload.get("to_state")
|
|
|
|
|
task_id = payload.get("task_id", "")
|
feat: consequence engine, causal world model, metacognition, interpretability, claim verification
Choice → Consequence → Learning:
- ConsequenceEngine tracks every decision point with alternatives,
risk/reward estimates, and actual outcomes
- Consequences feed into AdaptiveEthics for experience-based learning
- FusionAGILoop now wires ethics + consequences into task lifecycle
Causal World Model:
- CausalWorldModel learns state-transition patterns from execution history
- Predicts outcomes based on observed action→effect patterns
- Uncertainty estimates decrease as more evidence accumulates
Metacognition:
- assess_head_outputs() evaluates reasoning quality from head outputs
- Detects knowledge gaps, measures head agreement, identifies uncertainty
- Actively recommends whether to seek more information
Interpretability:
- ReasoningTracer captures full prompt→answer reasoning traces
- Each step records stage, component, input/output, timing
- explain() generates human-readable reasoning explanations
Claim Verification:
- ClaimVerifier cross-checks claims for evidence, consistency, grounding
- Flags high-confidence claims lacking evidence support
- Detects contradictions between claims from different heads
325 tests passing, 0 ruff errors, 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 06:25:35 +00:00
|
|
|
if not task_id:
|
2026-02-09 21:51:42 -08:00
|
|
|
return
|
feat: consequence engine, causal world model, metacognition, interpretability, claim verification
Choice → Consequence → Learning:
- ConsequenceEngine tracks every decision point with alternatives,
risk/reward estimates, and actual outcomes
- Consequences feed into AdaptiveEthics for experience-based learning
- FusionAGILoop now wires ethics + consequences into task lifecycle
Causal World Model:
- CausalWorldModel learns state-transition patterns from execution history
- Predicts outcomes based on observed action→effect patterns
- Uncertainty estimates decrease as more evidence accumulates
Metacognition:
- assess_head_outputs() evaluates reasoning quality from head outputs
- Detects knowledge gaps, measures head agreement, identifies uncertainty
- Actively recommends whether to seek more information
Interpretability:
- ReasoningTracer captures full prompt→answer reasoning traces
- Each step records stage, component, input/output, timing
- explain() generates human-readable reasoning explanations
Claim Verification:
- ClaimVerifier cross-checks claims for evidence, consistency, grounding
- Flags high-confidence claims lacking evidence support
- Detects contradictions between claims from different heads
325 tests passing, 0 ruff errors, 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 06:25:35 +00:00
|
|
|
|
|
|
|
|
if to_state == TaskState.FAILED.value:
|
|
|
|
|
self._consequences.record_consequence(
|
|
|
|
|
choice_id=f"task_{task_id}",
|
|
|
|
|
outcome_positive=False,
|
|
|
|
|
actual_risk_realized=0.8,
|
|
|
|
|
actual_reward_gained=0.1,
|
|
|
|
|
description=f"Task {task_id} failed",
|
|
|
|
|
cost={"retries_needed": True},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self._ethics.record_experience(
|
|
|
|
|
action_type="task_execution",
|
|
|
|
|
context_summary=f"Task {task_id} execution",
|
|
|
|
|
advisory_reason="",
|
|
|
|
|
proceeded=True,
|
|
|
|
|
outcome_positive=False,
|
|
|
|
|
task_id=task_id,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if self._auto_retry:
|
|
|
|
|
ok, _ = self._correction.suggest_retry(task_id)
|
|
|
|
|
if ok:
|
|
|
|
|
self._correction.prepare_retry(task_id)
|
|
|
|
|
else:
|
|
|
|
|
recs = self._correction.correction_recommendations(task_id)
|
|
|
|
|
if recs and self._on_recs:
|
|
|
|
|
self._on_recs(recs)
|
|
|
|
|
|
|
|
|
|
elif to_state == TaskState.COMPLETED.value:
|
|
|
|
|
self._consequences.record_consequence(
|
|
|
|
|
choice_id=f"task_{task_id}",
|
|
|
|
|
outcome_positive=True,
|
|
|
|
|
actual_risk_realized=0.1,
|
|
|
|
|
actual_reward_gained=0.8,
|
|
|
|
|
description=f"Task {task_id} completed successfully",
|
|
|
|
|
benefit={"task_completed": True},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self._ethics.record_experience(
|
|
|
|
|
action_type="task_execution",
|
|
|
|
|
context_summary=f"Task {task_id} execution",
|
|
|
|
|
advisory_reason="",
|
|
|
|
|
proceeded=True,
|
|
|
|
|
outcome_positive=True,
|
|
|
|
|
task_id=task_id,
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-09 21:51:42 -08:00
|
|
|
except Exception:
|
|
|
|
|
logger.exception(
|
|
|
|
|
"FusionAGILoop: _on_task_state_changed failed (best-effort)",
|
|
|
|
|
extra={"event_type": event_type},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def _on_reflection_done(self, event_type: str, payload: dict[str, Any]) -> None:
|
feat: consequence engine, causal world model, metacognition, interpretability, claim verification
Choice → Consequence → Learning:
- ConsequenceEngine tracks every decision point with alternatives,
risk/reward estimates, and actual outcomes
- Consequences feed into AdaptiveEthics for experience-based learning
- FusionAGILoop now wires ethics + consequences into task lifecycle
Causal World Model:
- CausalWorldModel learns state-transition patterns from execution history
- Predicts outcomes based on observed action→effect patterns
- Uncertainty estimates decrease as more evidence accumulates
Metacognition:
- assess_head_outputs() evaluates reasoning quality from head outputs
- Detects knowledge gaps, measures head agreement, identifies uncertainty
- Actively recommends whether to seek more information
Interpretability:
- ReasoningTracer captures full prompt→answer reasoning traces
- Each step records stage, component, input/output, timing
- explain() generates human-readable reasoning explanations
Claim Verification:
- ClaimVerifier cross-checks claims for evidence, consistency, grounding
- Flags high-confidence claims lacking evidence support
- Detects contradictions between claims from different heads
325 tests passing, 0 ruff errors, 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 06:25:35 +00:00
|
|
|
"""After reflection, run auto-recommend, auto-training, and update ethics."""
|
2026-02-09 21:51:42 -08:00
|
|
|
try:
|
|
|
|
|
task_id = payload.get("task_id") or ""
|
|
|
|
|
evaluation = payload.get("evaluation") or {}
|
feat: consequence engine, causal world model, metacognition, interpretability, claim verification
Choice → Consequence → Learning:
- ConsequenceEngine tracks every decision point with alternatives,
risk/reward estimates, and actual outcomes
- Consequences feed into AdaptiveEthics for experience-based learning
- FusionAGILoop now wires ethics + consequences into task lifecycle
Causal World Model:
- CausalWorldModel learns state-transition patterns from execution history
- Predicts outcomes based on observed action→effect patterns
- Uncertainty estimates decrease as more evidence accumulates
Metacognition:
- assess_head_outputs() evaluates reasoning quality from head outputs
- Detects knowledge gaps, measures head agreement, identifies uncertainty
- Actively recommends whether to seek more information
Interpretability:
- ReasoningTracer captures full prompt→answer reasoning traces
- Each step records stage, component, input/output, timing
- explain() generates human-readable reasoning explanations
Claim Verification:
- ClaimVerifier cross-checks claims for evidence, consistency, grounding
- Flags high-confidence claims lacking evidence support
- Detects contradictions between claims from different heads
325 tests passing, 0 ruff errors, 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 06:25:35 +00:00
|
|
|
|
|
|
|
|
success = evaluation.get("success", False)
|
|
|
|
|
|
|
|
|
|
self._ethics.record_experience(
|
|
|
|
|
action_type="reflection_outcome",
|
|
|
|
|
context_summary=f"Reflection on task {task_id}",
|
|
|
|
|
advisory_reason="",
|
|
|
|
|
proceeded=True,
|
|
|
|
|
outcome_positive=success,
|
|
|
|
|
task_id=task_id or None,
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-09 21:51:42 -08:00
|
|
|
recs = self._recommender.recommend(
|
|
|
|
|
task_id=task_id or None,
|
|
|
|
|
evaluation=evaluation,
|
|
|
|
|
include_lessons=True,
|
|
|
|
|
)
|
|
|
|
|
if self._on_recs:
|
|
|
|
|
try:
|
|
|
|
|
self._on_recs(recs)
|
|
|
|
|
except Exception:
|
|
|
|
|
logger.exception("FusionAGILoop: on_recommendations callback failed")
|
|
|
|
|
suggestions = self._trainer.run_auto_training(
|
|
|
|
|
task_id=task_id or None,
|
|
|
|
|
evaluation=evaluation,
|
|
|
|
|
apply_heuristics=True,
|
|
|
|
|
)
|
|
|
|
|
if self._on_training:
|
|
|
|
|
try:
|
|
|
|
|
self._on_training(suggestions)
|
|
|
|
|
except Exception:
|
|
|
|
|
logger.exception("FusionAGILoop: on_training_suggestions callback failed")
|
|
|
|
|
except Exception:
|
|
|
|
|
logger.exception(
|
|
|
|
|
"FusionAGILoop: _on_reflection_done failed (best-effort)",
|
|
|
|
|
extra={"event_type": event_type},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def run_after_reflection(
|
|
|
|
|
self,
|
|
|
|
|
task_id: str,
|
|
|
|
|
evaluation: dict[str, Any],
|
|
|
|
|
) -> tuple[list[Recommendation], list[TrainingSuggestion]]:
|
feat: consequence engine, causal world model, metacognition, interpretability, claim verification
Choice → Consequence → Learning:
- ConsequenceEngine tracks every decision point with alternatives,
risk/reward estimates, and actual outcomes
- Consequences feed into AdaptiveEthics for experience-based learning
- FusionAGILoop now wires ethics + consequences into task lifecycle
Causal World Model:
- CausalWorldModel learns state-transition patterns from execution history
- Predicts outcomes based on observed action→effect patterns
- Uncertainty estimates decrease as more evidence accumulates
Metacognition:
- assess_head_outputs() evaluates reasoning quality from head outputs
- Detects knowledge gaps, measures head agreement, identifies uncertainty
- Actively recommends whether to seek more information
Interpretability:
- ReasoningTracer captures full prompt→answer reasoning traces
- Each step records stage, component, input/output, timing
- explain() generates human-readable reasoning explanations
Claim Verification:
- ClaimVerifier cross-checks claims for evidence, consistency, grounding
- Flags high-confidence claims lacking evidence support
- Detects contradictions between claims from different heads
325 tests passing, 0 ruff errors, 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 06:25:35 +00:00
|
|
|
"""Run auto-recommend and auto-training after a reflection.
|
|
|
|
|
|
|
|
|
|
Also records the reflection outcome for ethical learning.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
task_id: Task that was reflected on.
|
|
|
|
|
evaluation: Critic evaluation dict.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
Tuple of (recommendations, training_suggestions).
|
2026-02-09 21:51:42 -08:00
|
|
|
"""
|
feat: consequence engine, causal world model, metacognition, interpretability, claim verification
Choice → Consequence → Learning:
- ConsequenceEngine tracks every decision point with alternatives,
risk/reward estimates, and actual outcomes
- Consequences feed into AdaptiveEthics for experience-based learning
- FusionAGILoop now wires ethics + consequences into task lifecycle
Causal World Model:
- CausalWorldModel learns state-transition patterns from execution history
- Predicts outcomes based on observed action→effect patterns
- Uncertainty estimates decrease as more evidence accumulates
Metacognition:
- assess_head_outputs() evaluates reasoning quality from head outputs
- Detects knowledge gaps, measures head agreement, identifies uncertainty
- Actively recommends whether to seek more information
Interpretability:
- ReasoningTracer captures full prompt→answer reasoning traces
- Each step records stage, component, input/output, timing
- explain() generates human-readable reasoning explanations
Claim Verification:
- ClaimVerifier cross-checks claims for evidence, consistency, grounding
- Flags high-confidence claims lacking evidence support
- Detects contradictions between claims from different heads
325 tests passing, 0 ruff errors, 0 mypy errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
2026-04-28 06:25:35 +00:00
|
|
|
success = evaluation.get("success", False)
|
|
|
|
|
self._ethics.record_experience(
|
|
|
|
|
action_type="reflection_outcome",
|
|
|
|
|
context_summary=f"Manual reflection on {task_id}",
|
|
|
|
|
advisory_reason="",
|
|
|
|
|
proceeded=True,
|
|
|
|
|
outcome_positive=success,
|
|
|
|
|
task_id=task_id,
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-09 21:51:42 -08:00
|
|
|
recs = self._recommender.recommend(
|
|
|
|
|
task_id=task_id,
|
|
|
|
|
evaluation=evaluation,
|
|
|
|
|
include_lessons=True,
|
|
|
|
|
)
|
|
|
|
|
suggestions = self._trainer.run_auto_training(
|
|
|
|
|
task_id=task_id,
|
|
|
|
|
evaluation=evaluation,
|
|
|
|
|
apply_heuristics=True,
|
|
|
|
|
)
|
|
|
|
|
return recs, suggestions
|
|
|
|
|
|
|
|
|
|
def unsubscribe(self) -> None:
|
|
|
|
|
"""Unsubscribe from event bus (for cleanup)."""
|
|
|
|
|
self._event_bus.unsubscribe("task_state_changed", self._on_task_state_changed)
|
|
|
|
|
self._event_bus.unsubscribe("reflection_done", self._on_reflection_done)
|
|
|
|
|
logger.info("FusionAGILoop: unsubscribed from events")
|