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

MethodEffect
load() / save(data)Whole-file read / write.
update(category, key, value) -> strMerge-semantic update; returns sync message describing canonical mapping.
delete(category, key) -> strRemove key; status string.
get_context_string() -> strFormat for LLM injection.