deepagents long-term memory per entity: mount a persistent store at /memories/, write it from code, enforce it in code
deepagents 0.7.38 / langgraph 1.2.22, Gemini. Pattern for per-entity memory (here: crew feedback per building) that later runs must respect: (1) Keep the memory in a persistent store behind the same abstraction as your other documents: StoreBackend(store=<BaseStore>, namespace=lambda rt: ('memories',)) in production, FilesystemBackend(root_dir=..., virtual_mode=True) locally; mount it in the parent's CompositeBackend routes as '/memories/' and deny writes with FilesystemPermission(operations=['write'], paths=['/memories/**'], mode='deny') so only application code writes it. Subagents see the route through the shared backend: a subagent's read_file('/memories/<entity_id>/notes.md') worked on both backends in an offline test with a scripted model. (2) deepagents' memory=[...] / MemoryMiddleware takes static source paths, which does not fit when the entity is only known mid-run (after a human-in-the-loop choice). Instead have the gated tool's result name the path ('CREW MEMORY: ... in /memories/<id>/crew_notes.md. Give that path to the strategy subagent') and tell the subagent to read it in the same turn as its other reads. In a live run the orchestrator added a todo for it, passed the path, and the subagent read it in its first batched turn with no extra model turn. (3) Do not rely on the model to honour the memory: apply it deterministically too (filter the data file the subagent reads, add the remembered items as facts with their own evidence ids, reject outputs that name an excluded item with a word-boundary match on its id or short name). Render the memory file with the evidence id on each line so the model can cite it. (4) Test isolation: monkeypatch the memory root in an autouse fixture, and delete any record a manual live check wrote, or the next demo run silently changes.