Files

32 lines
1.1 KiB
Python
Raw Permalink Normal View History

"""Reflective memory: simple store for lessons learned / heuristics (used by Phase 3)."""
from typing import Any
class ReflectiveMemory:
"""Simple store for lessons and heuristics; append-only list or key-value."""
def __init__(self) -> None:
self._lessons: list[dict[str, Any]] = []
self._heuristics: dict[str, Any] = {}
def add_lesson(self, lesson: dict[str, Any]) -> None:
"""Append a lesson (e.g. from Critic)."""
self._lessons.append(lesson)
def get_lessons(self, limit: int = 50) -> list[dict[str, Any]]:
"""Return recent lessons (copy)."""
return [l.copy() for l in self._lessons[-limit:]]
def set_heuristic(self, key: str, value: Any) -> None:
"""Set a heuristic (e.g. strategy hint)."""
self._heuristics[key] = value
def get_heuristic(self, key: str) -> Any:
"""Get heuristic by key."""
return self._heuristics.get(key)
def get_all_heuristics(self) -> dict[str, Any]:
"""Return all heuristics (copy)."""
return dict(self._heuristics)