Update memory_manager.py
This commit is contained in:
1 parent
57984edc9a
commit
069df9f4b7
1 file changed
+1
-26
@@ -1,10 +1,3 @@
|
|||||||
"""
|
|
||||||
memory_manager.py — JARVIS Long-Term Memory
|
|
||||||
============================================
|
|
||||||
Memory yalnızca Gemini Live'ın save_memory tool call'ı aracılığıyla güncellenir.
|
|
||||||
Ayrı bir Gemini API çağrısı yapılmaz → sıfır 429 hatası.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
@@ -24,9 +17,6 @@ _lock = Lock()
|
|||||||
MAX_VALUE_LENGTH = 380
|
MAX_VALUE_LENGTH = 380
|
||||||
MEMORY_MAX_CHARS = 2200
|
MEMORY_MAX_CHARS = 2200
|
||||||
|
|
||||||
|
|
||||||
# ── Şema ──────────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
def _empty_memory() -> dict:
|
def _empty_memory() -> dict:
|
||||||
return {
|
return {
|
||||||
"identity": {},
|
"identity": {},
|
||||||
@@ -37,9 +27,6 @@ def _empty_memory() -> dict:
|
|||||||
"notes": {},
|
"notes": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ── Yükleme ───────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
def load_memory() -> dict:
|
def load_memory() -> dict:
|
||||||
if not MEMORY_PATH.exists():
|
if not MEMORY_PATH.exists():
|
||||||
return _empty_memory()
|
return _empty_memory()
|
||||||
@@ -57,9 +44,6 @@ def load_memory() -> dict:
|
|||||||
print(f"[Memory] ⚠️ Load error: {e}")
|
print(f"[Memory] ⚠️ Load error: {e}")
|
||||||
return _empty_memory()
|
return _empty_memory()
|
||||||
|
|
||||||
|
|
||||||
# ── Boyut sınırı ──────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
def _all_entries(memory: dict) -> list[tuple]:
|
def _all_entries(memory: dict) -> list[tuple]:
|
||||||
entries = []
|
entries = []
|
||||||
for cat, items in memory.items():
|
for cat, items in memory.items():
|
||||||
@@ -83,9 +67,6 @@ def _trim_to_limit(memory: dict) -> dict:
|
|||||||
print(f"[Memory] 🗑️ Trimmed {cat}/{key}")
|
print(f"[Memory] 🗑️ Trimmed {cat}/{key}")
|
||||||
return memory
|
return memory
|
||||||
|
|
||||||
|
|
||||||
# ── Kaydetme ──────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
def save_memory(memory: dict) -> None:
|
def save_memory(memory: dict) -> None:
|
||||||
if not isinstance(memory, dict):
|
if not isinstance(memory, dict):
|
||||||
return
|
return
|
||||||
@@ -136,9 +117,6 @@ def update_memory(memory_update: dict) -> dict:
|
|||||||
print(f"[Memory] 💾 Saved: {list(memory_update.keys())}")
|
print(f"[Memory] 💾 Saved: {list(memory_update.keys())}")
|
||||||
return memory
|
return memory
|
||||||
|
|
||||||
|
|
||||||
# ── Prompt formatı ────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
def format_memory_for_prompt(memory: dict | None) -> str:
|
def format_memory_for_prompt(memory: dict | None) -> str:
|
||||||
if not memory:
|
if not memory:
|
||||||
return ""
|
return ""
|
||||||
@@ -215,9 +193,6 @@ def format_memory_for_prompt(memory: dict | None) -> str:
|
|||||||
|
|
||||||
return result + "\n"
|
return result + "\n"
|
||||||
|
|
||||||
|
|
||||||
# ── Yardımcı fonksiyonlar ─────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
def remember(key: str, value: str, category: str = "notes") -> str:
|
def remember(key: str, value: str, category: str = "notes") -> str:
|
||||||
valid = {"identity", "preferences", "projects", "relationships", "wishes", "notes"}
|
valid = {"identity", "preferences", "projects", "relationships", "wishes", "notes"}
|
||||||
if category not in valid:
|
if category not in valid:
|
||||||
@@ -237,4 +212,4 @@ def forget(key: str, category: str = "notes") -> str:
|
|||||||
return f"Not found: {category}/{key}"
|
return f"Not found: {category}/{key}"
|
||||||
|
|
||||||
|
|
||||||
forget_memory = forget
|
forget_memory = forget
|
||||||
Reference in new issue
Block a user