File size: 2,059 Bytes
77da5ce | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | # memory.md — LifeStackMemory Reference
`agent/memory.py` — ChromaDB-backed trajectory and human-feedback storage.
---
## Overview
`LifeStackMemory` persists two types of data:
| Collection | What's stored |
|---|---|
| `collection` (trajectories) | Successful episode decisions — action type, reward, reasoning |
| `feedback_collection` | Real-world outcome feedback submitted via the Follow-up tab |
Only trajectories with `total_reward >= 2.0` are stored (threshold prevents noise).
---
## API
### Instantiation
```python
from agent.memory import LifeStackMemory
memory = LifeStackMemory(silent=True) # default path
memory = LifeStackMemory(silent=True, path="./my_memory") # custom path
```
The module-level singleton in `app.py` is named `MEMORY`:
```python
MEMORY = LifeStackMemory(silent=True)
```
### `store_trajectory(...)`
```python
memory.store_trajectory(
conflict_title="Friday 6PM",
route_taken="communicate",
total_reward=2.5,
metrics_diff_str="career.workload: -15.0",
reasoning="Delegating resolved workload spike",
)
```
Silently skips storage if `total_reward < 2.0`.
### `store_feedback(feedback: OutcomeFeedback)`
```python
from core.feedback import OutcomeFeedback
feedback = OutcomeFeedback(
episode_id="A1B2C3D4",
overall_effectiveness=8,
domains_improved=["career", "mental_wellbeing"],
domains_worsened=[],
unexpected_effects="Felt more confident",
resolution_time_hours=2.0,
)
memory.store_feedback(feedback)
```
Used by the **Follow-up** tab in `app.py`.
### `get_stats() -> dict`
```python
stats = memory.get_stats()
# {
# "total_memories": 42,
# "average_reward": 2.71,
# "by_action_type": {"communicate": 18, "delegate": 12, ...}
# }
```
### `query(conflict_description, n_results=3) -> list[dict]`
Retrieves the most semantically similar past decisions for a given situation description.
---
## Change Log
| Date | Change |
|---|---|
| 2026-04-23 | `AGENT_MEMORY` reference in `app.py` corrected to `MEMORY` (the actual singleton) |
|