39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
# agent/memory.py
|
|
from pathlib import Path
|
|
from typing import Any, Dict
|
|
import json
|
|
|
|
from .config import settings
|
|
|
|
|
|
class Memory:
|
|
def __init__(self, path: str = "memory.json"):
|
|
print("init memory")
|
|
self.file = Path(path)
|
|
self.data: Dict[str, Any] = {}
|
|
self.load()
|
|
|
|
def load(self) -> None:
|
|
if self.file.exists():
|
|
self.data = json.loads(self.file.read_text(encoding="utf-8"))
|
|
else:
|
|
self.data = {
|
|
"project_root": None,
|
|
"history": [],
|
|
}
|
|
|
|
def save(self) -> None:
|
|
self.file.write_text(
|
|
json.dumps(self.data, indent=2, ensure_ascii=False),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
def get_project_root(self) -> str | None:
|
|
"""Ce qu'on injecte dans le prompt pour le LLM."""
|
|
return self.data.get("project_root")
|
|
|
|
def set_project_root(self, path: str) -> None:
|
|
print('Setting project root in memory to:', path)
|
|
self.data["project_root"] = path
|
|
self.save()
|