Auto-commit via make git (triggered by NFDOS)
This commit is contained in:
parent
64becf9cf7
commit
95cc2d9bc7
@ -18,6 +18,7 @@ from pathlib import Path
|
||||
from neurotron.logbus import logbus
|
||||
from .state import TRMState
|
||||
from .agents import GuardianAgent, ExplorerAgent, ArchaeologistAgent
|
||||
from .thought_agent import ThoughtAgent
|
||||
from .events import make_trm_snapshot_payload
|
||||
|
||||
|
||||
@ -43,6 +44,7 @@ class TRMEngine:
|
||||
self.guardian = GuardianAgent()
|
||||
self.explorer = ExplorerAgent()
|
||||
self.archaeologist = ArchaeologistAgent(self.ctx)
|
||||
self.thought_agent = ThoughtAgent(self.ctx)
|
||||
|
||||
|
||||
# histórico curto de estados do TRM (para futuro TRM v2)
|
||||
@ -134,6 +136,13 @@ class TRMEngine:
|
||||
st2 = self.explorer.step(st1, telemetry)
|
||||
st3 = self.archaeologist.step(st2, telemetry)
|
||||
|
||||
# pensamentos simbólicos
|
||||
try:
|
||||
self.thought_agent.step(st3, telemetry)
|
||||
except Exception as e:
|
||||
self._dbg(f"thought_agent erro: {e}")
|
||||
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Custo energético + modo de operação
|
||||
# ----------------------------------------------------------
|
||||
|
||||
144
src/neurotron/trm/thought_agent.py
Normal file
144
src/neurotron/trm/thought_agent.py
Normal file
@ -0,0 +1,144 @@
|
||||
"""
|
||||
thought_agent.py — TRM v1 Thought Generator
|
||||
-------------------------------------------
|
||||
|
||||
Gera pensamentos minimalistas, analíticos e contextuais com base na
|
||||
telemetria e no estado interno do TRM.
|
||||
|
||||
Estilo:
|
||||
- curto
|
||||
- técnico
|
||||
- orientado a deltas
|
||||
- simbólico, mas não emocional
|
||||
|
||||
Exemplos:
|
||||
"Δcpu alto — reduzir profundidade"
|
||||
"mem estável — tendência favorável"
|
||||
"jitter elevado — cautela sugerida"
|
||||
"stress detectado — foco conservador"
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
from typing import Dict, Any
|
||||
from neurotron.logbus import logbus
|
||||
|
||||
|
||||
class ThoughtAgent:
|
||||
name = "trm.thought"
|
||||
|
||||
def __init__(self, cortex):
|
||||
self.ctx = cortex
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# helper seguro
|
||||
# -----------------------------------------------------------
|
||||
def _safe(self, x, default=0.0):
|
||||
try:
|
||||
return float(x)
|
||||
except:
|
||||
return default
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# função principal
|
||||
# -----------------------------------------------------------
|
||||
def step(self, state, tele: Dict[str, Any]) -> None:
|
||||
"""
|
||||
Recebe TRMState + telemetria e gera 0..N pensamentos.
|
||||
Cada pensamento é um dict com:
|
||||
{ "thought": "...", "ts": ... }
|
||||
gravado via Hippocampus como "trm.thought".
|
||||
"""
|
||||
thoughts = []
|
||||
|
||||
raw = tele.get("raw", {}) or {}
|
||||
delta = tele.get("delta", {}) or {}
|
||||
accel = tele.get("accel", {}) or {}
|
||||
temp = self._safe(tele.get("temp"))
|
||||
jitter = self._safe(tele.get("jitter"))
|
||||
events = tele.get("events", []) or []
|
||||
|
||||
cpu = self._safe(raw.get("cpu"))
|
||||
mem = self._safe(raw.get("mem"))
|
||||
load = self._safe(raw.get("load"))
|
||||
d_cpu = self._safe(delta.get("cpu"))
|
||||
d_mem = self._safe(delta.get("mem"))
|
||||
d_load = self._safe(delta.get("load"))
|
||||
|
||||
# -------------------------------------------------------
|
||||
# CPU
|
||||
# -------------------------------------------------------
|
||||
if d_cpu > 10:
|
||||
thoughts.append(f"Δcpu elevado ({d_cpu:+.1f}) — reduzir complexidade")
|
||||
elif d_cpu > 3:
|
||||
thoughts.append(f"cpu a subir ({d_cpu:+.1f}) — monitorizar")
|
||||
|
||||
if accel.get("cpu", 0) > 10:
|
||||
thoughts.append("aceleração cpu brusca — possível stress interno")
|
||||
|
||||
# -------------------------------------------------------
|
||||
# MEM
|
||||
# -------------------------------------------------------
|
||||
if mem > 80:
|
||||
thoughts.append("memória alta — foco conservador")
|
||||
elif d_mem > 5:
|
||||
thoughts.append(f"Δmem {d_mem:+.1f} — carga crescente")
|
||||
elif abs(d_mem) < 1:
|
||||
thoughts.append("mem estável — tendência favorável")
|
||||
|
||||
# -------------------------------------------------------
|
||||
# LOAD
|
||||
# -------------------------------------------------------
|
||||
if load > 2.0:
|
||||
thoughts.append(f"load {load:.2f} — sistema pesado")
|
||||
elif d_load > 0.5:
|
||||
thoughts.append(f"Δload {d_load:+.2f} — possível transição")
|
||||
|
||||
# -------------------------------------------------------
|
||||
# Temperatura
|
||||
# -------------------------------------------------------
|
||||
if temp > 60:
|
||||
thoughts.append("temperatura alta — priorizar eficiência")
|
||||
elif temp > 40:
|
||||
thoughts.append("temperatura moderada — ajuste recomendado")
|
||||
elif temp < 10:
|
||||
thoughts.append("sistema frio — margem para explorar")
|
||||
|
||||
# -------------------------------------------------------
|
||||
# Jitter
|
||||
# -------------------------------------------------------
|
||||
if jitter > 1.5:
|
||||
thoughts.append(f"jitter elevado ({jitter:.2f}s) — cautela sugerida")
|
||||
|
||||
# -------------------------------------------------------
|
||||
# Eventos diretos
|
||||
# -------------------------------------------------------
|
||||
if "enter_stress_zone" in events:
|
||||
thoughts.append("stress detectado — reduzir profundidade")
|
||||
|
||||
if "fs_warning" in events:
|
||||
thoughts.append("FS warning — evitar operações pesadas")
|
||||
|
||||
if "loop_suspect" in events:
|
||||
thoughts.append("padrão repetitivo — vigiar loop")
|
||||
|
||||
# -------------------------------------------------------
|
||||
# Valência
|
||||
# -------------------------------------------------------
|
||||
if state.valence < -3:
|
||||
thoughts.append("valência baixa — evitar exploração")
|
||||
elif state.valence > 2:
|
||||
thoughts.append("valência positiva — aprofundar análise")
|
||||
|
||||
# -------------------------------------------------------
|
||||
# Gravar pensamentos no Hippocampus
|
||||
# -------------------------------------------------------
|
||||
for t in thoughts:
|
||||
payload = {"thought": t}
|
||||
try:
|
||||
self.ctx.memory.remember("trm.thought", payload)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
logbus.debug(f"[trm.thought] {t}")
|
||||
|
||||
return None
|
||||
Loading…
Reference in New Issue
Block a user