memory / profile.py — ProfileMemory
Canonical user profile with multi-value merge semantics.
Storage
JSON at path/user_profile.json; atomic temp + os.replace; threading.RLock guards reads / writes.
Schema
{
"root": { "name": str },
"relationships": { "wife|husband|son|daughter": str | list[str] },
"interests": { "science|general|...": str | list[str] },
"assets": { "car|...": str | list[str] }
}
Canonicalisation
Common synonyms remap at write time: wife → relationships.wife, vehicle → assets.car, etc. The caller receives the rewritten key in the return message so the agent can keep its mental model synced.
Merge semantics
Scalar → scalar: replace if different, else promote both to a list. Lists are deduped and order-preserved.
API
| Method | Effect |
|---|---|
load() / save(data) | Whole-file read / write. |
update(category, key, value) -> str | Merge-semantic update; returns sync message describing canonical mapping. |
delete(category, key) -> str | Remove key; status string. |
get_context_string() -> str | Format for LLM injection. |