Spaces:
Sleeping
Sleeping
Upload jarvis_core/episodic.py with huggingface_hub
Browse files- jarvis_core/episodic.py +41 -0
jarvis_core/episodic.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""jarvis_core.episodic — mission/episodic memory (Firebase: jarvis_episodes).
|
| 2 |
+
|
| 3 |
+
Remembers work, not just facts: {mission, decision, reason, outcome, next_step}.
|
| 4 |
+
Answers: "What did we try before?" / "Why did we choose this?" / "What failed?"
|
| 5 |
+
"""
|
| 6 |
+
import time
|
| 7 |
+
|
| 8 |
+
from .store import get_store, redact
|
| 9 |
+
|
| 10 |
+
COL = "jarvis_episodes"
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def record_episode(mission, decision="", reason="", outcome="", next_step=""):
|
| 14 |
+
eid = get_store().add(COL, {
|
| 15 |
+
"mission": mission, "decision": redact(decision)[:500],
|
| 16 |
+
"reason": redact(reason)[:500], "outcome": redact(outcome)[:500],
|
| 17 |
+
"next_step": redact(next_step)[:500], "ts": time.time(),
|
| 18 |
+
})
|
| 19 |
+
return get_store().get(COL, eid)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def recall_episodes(mission="", limit=5):
|
| 23 |
+
items = get_store().all(COL)
|
| 24 |
+
if mission:
|
| 25 |
+
m = mission.lower()
|
| 26 |
+
items = [e for e in items if m in (e.get("mission") or "").lower()]
|
| 27 |
+
return sorted(items, key=lambda e: e.get("ts", 0), reverse=True)[:limit]
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def failures(mission="", limit=5):
|
| 31 |
+
items = recall_episodes(mission, 200)
|
| 32 |
+
bad = [e for e in items
|
| 33 |
+
if any(w in ((e.get("outcome") or "") + (e.get("decision") or "")).lower()
|
| 34 |
+
for w in ["fail", "error", "broke", "wrong", "blocked"])]
|
| 35 |
+
return bad[:limit]
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def format_episode(e):
|
| 39 |
+
return (f"{e.get('mission')}: decided '{e.get('decision')}' because "
|
| 40 |
+
f"'{e.get('reason')}'. Outcome: '{e.get('outcome')}'. "
|
| 41 |
+
f"Next: '{e.get('next_step')}'.")
|