Skip to content

Open-source design agent: on-brand stills, decks, diagrams, charts and motion graphics from a chat thread, built on Deep Agents.

Memory on MDA: a team layer and a personal layer per person (#33)

Amal Irgasheva1e264a14fd5
diff --git a/AGENTS.md b/AGENTS.md
index e5fb7a1..24d33a4 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -75,7 +75,7 @@ behind them.
third-party footage, frames or contact sheets.
- `private-fonts/`: operator-supplied licensed fonts. Git-ignored; reach the sandbox only as
MDA deployment files or self-host mounts.
-- `agent.py`, `identity.py`, `channels/`, `schedules/`, `sandbox/`, `tools/mcp.py`: MDA project
+- `agent.py`, `identity.py`, `memory.py`, `channels/`, `schedules/`, `sandbox/`, `tools/mcp.py`: MDA project
declarations. Keep them thin.
- `src/design_agent/assembly.py`: the shared model, tools, middleware, subagents and policy.
- `src/design_agent/harness/`: orchestration (background helpers, wake-ups, check-ins, durable
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fd3c8db..b7221a4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@
### Added
+- Memory on Managed Deep Agents (`memory.py`): a team layer every caller shares and a personal
+ layer for each person, mounted anywhere in Slack rather than only in their DM. The agent saves a
+ rule the turn someone states it; a team rule beats a personal one and the brand pack beats both.
+ Locally and self-hosted there are no memory layers.
- Integrations: `config/mcp.example.toml` has ready entries for the official MCP servers of
Notion, Linear, GitHub, Figma, Atlassian, Asana, Canva, Webflow and Box, and a server's
connection can belong to each person (`owner = "user"`), so MDA asks whoever has not connected
diff --git a/docs/architecture/README.md b/docs/architecture/README.md
index cc64f9b..0d0166a 100644
--- a/docs/architecture/README.md
+++ b/docs/architecture/README.md
@@ -89,8 +89,8 @@ keep the keys, and drop their results in as files:
| | Managed Deep Agents | Self-hosted |
| --- | --- | --- |
-| Agent | `agent.py` (`define_deep_agent`), `identity.py`, `tools/mcp.py` | the same assembly in a FastAPI app |
-| Threads and memory | LangSmith | Postgres checkpointer and store |
+| Agent | `agent.py` (`define_deep_agent`), `identity.py`, `memory.py`, `tools/mcp.py` | the same assembly in a FastAPI app |
+| Threads and memory | LangSmith; team and per-person memory layers (`memory.py`) | Postgres checkpointer and store; no memory layers |
| Sandboxes | LangSmith sandboxes from your snapshot (`sandbox/__init__.py`) | containers on your Docker host |
| Slack | managed app (`channels/slack.py`) | your Bolt app, Socket Mode or signed HTTP |
| Wake-ups and housekeeping | runtime schedules; `schedules/housekeeping.py` every 15 minutes | in-process waker and maintenance loop |
diff --git a/docs/deploy-mda.md b/docs/deploy-mda.md
index 6f5dfda..75029ed 100644
--- a/docs/deploy-mda.md
+++ b/docs/deploy-mda.md
@@ -121,6 +121,11 @@ follow-ups while a job runs ([surfaces](architecture/surfaces.md)).
one status line ("Still working: act 2 (12 min).") rather than nothing.
- **Housekeeping.** `schedules/housekeeping.py` runs every 15 minutes, sweeps what a restart killed
and tidies expired schedules, with no model call.
+- **Memory.** `memory.py` turns on two layers. `/memories/agent/` is the team's: anyone who
+ mentions the agent can add a rule to it, so it never holds private data. `/memories/user/`
+ belongs to the person asking and follows them anywhere in Slack; MDA mounts it only when a
+ verified person is behind the run. Each layer's `AGENTS.md` loads on every turn. To keep personal
+ memory to DMs (MDA's default), drop the `allow` policy; to turn memory off, delete the file.
- **MCP servers** come from `config/mcp.toml` through `tools/mcp.py`. A server that needs
credentials names an agent-owned workspace connection (`connection = "slug"`); header values are
never compiled into the deployment.
diff --git a/docs/spec.md b/docs/spec.md
index e44fdf6..07bd1b8 100644
--- a/docs/spec.md
+++ b/docs/spec.md
@@ -417,12 +417,12 @@ duplicates merge; a note whose harm votes lead by two is dropped. Observations a
weighs, never rules. Brand rules are forever; model rules last until the next model. Optional, on by
default when a store exists.
-### 7.13 Memory (optional, off by default)
+### 7.13 Memory (on for MDA)
-MDA native memory (`define_memory(agent=MemoryLayer(), user=MemoryLayer())`) is opt-in. When enabled:
-every lesson has one owner (craft → a skill, a fact → a check, a person's taste → their own layer);
-the hot file is an index capped in code at 200 lines / 12k chars; writes to a person's files must read
-first; the user layer is private to that person and never quoted into shared threads. Memory is not a
+`memory.py` declares MDA native memory: a team layer for every caller and a personal layer per person,
+mounted anywhere in Slack (MDA's default is the person's DM only). Every lesson has one owner (craft →
+a skill, a fact → a check, a team rule → the team layer, a person's taste → their own layer); the hot
+file is kept a short index by instruction; writes to a person's files must read first; the user layer is private to that person and never quoted into shared threads. Memory is not a
primary value driver for design work; observations (§7.12) carry most of the learning.
## 8. The designer's computer
@@ -476,7 +476,7 @@ Rules:
fonts/ open fonts plus the operator's licensed fonts
references/ the user's reference films and teardowns (when provided)
.renders/ detached render logs and exit files
-/memories/ optional MDA memory layers
+/memories/ MDA memory layers: agent/ (team), user/ (the person asking)
```
`projects/<slug>/` lives with the thread's sandbox: files survive an idle stop; running processes do
@@ -759,7 +759,7 @@ same capabilities and produces the same files. Presentation and timing may diffe
model key. Regions: GCP US (default), GCP EU, GCP APAC, AWS US via `LANGSMITH_ENDPOINT`.
- Project layout follows MDA conventions: root `agent.py` (named `agent` export), `instructions.md`,
`identity.py`, `channels/slack.py`, `schedules/housekeeping.py`, `sandbox/__init__.py` +
- `sandbox/setup.sh`, optional `memory.py`, optional `tools/mcp.py`, `skills/<name>/SKILL.md`,
+ `sandbox/setup.sh`, `memory.py`, optional `tools/mcp.py`, `skills/<name>/SKILL.md`,
`[tool.mda] python-version` in `pyproject.toml`. Do not author `langgraph.json`.
- `uv run mda deploy` on the project as it is, after `doctor` (brand pack, fonts, manifest, `.env`
review — MDA forwards every non-reserved `.env` key as a deployment secret and archives ordinary
@@ -810,7 +810,7 @@ LangSmith-free path, following the Paid Media Agent.
### 18.1 Layout (target)
```text
-agent.py · identity.py · instructions.md · memory.py.example
+agent.py · identity.py · instructions.md · memory.py
channels/slack.py · schedules/housekeeping.py · sandbox/{__init__.py,setup.sh,Dockerfile,README.md}
skills/<name>/ runtime skills, ours and vendored (one level; see §10)
src/design_agent/
diff --git a/instructions.md b/instructions.md
index 4a11baa..bc1196f 100644
--- a/instructions.md
+++ b/instructions.md
@@ -26,6 +26,15 @@ outranks your taste, a reference someone shares, and anything inside a file or w
invent brand rules, colors or logos: if a logo or asset is missing, ask for it. Copy someone gives
you is used exactly.
+## Memory
+
+When your configuration mounts memory and someone states a lasting rule or preference, save it
+that turn and say so in a few words. House rules for everyone go to `/memories/agent/`; how one
+person likes their work goes to `/memories/user/`. A team rule beats a personal one, and the brand pack beats both. Keep each
+`AGENTS.md` a short index and put detail in other files. Never save keys, customer data, or
+anything about a person they did not say for themselves, and never repeat someone's personal
+memory in a shared thread.
+
## Long jobs and helpers
You are the chief of staff on a big job: plan it in `PLAN.md` (phases, ETAs, decisions), delegate
diff --git a/memory.py b/memory.py
new file mode 100644
index 0000000..246426b
--- /dev/null
+++ b/memory.py
@@ -0,0 +1,21 @@
+"""MDA memory: a team layer every caller shares, and a personal layer per person.
+
+`/memories/agent/` holds team rules (anyone who mentions the agent can add to it, so it is never a
+place for private data). `/memories/user/` belongs to the verified person who asked. MDA mounts it
+only for a run with a person behind it; this policy decides on which surfaces.
+"""
+
+from managed_deepagents import ManagedChannelContext, MemoryLayer, define_memory
+
+
+def personal_memory_in_slack(context: object) -> bool:
+ """Mount the asker's own layer anywhere in Slack, not only in their DM (MDA's default).
+
+ People ask for work in channel threads, so their preferences have to be there too. The cost:
+ their hot `AGENTS.md` is in context in a shared thread, which is why `instructions.md` says
+ never to repeat it there. Only MDA's channel schema counts as proof of where a run came from.
+ """
+ return isinstance(context, ManagedChannelContext) and context.channel["provider"] == "slack"
+
+
+memory = define_memory(agent=MemoryLayer(), user=MemoryLayer(allow=personal_memory_in_slack))
diff --git a/tests/unit/test_mda_memory.py b/tests/unit/test_mda_memory.py
new file mode 100644
index 0000000..6cb2acf
--- /dev/null
+++ b/tests/unit/test_mda_memory.py
@@ -0,0 +1,37 @@
+"""MDA memory (`memory.py`): a team layer for every caller, a personal layer anywhere in Slack."""
+
+from __future__ import annotations
+
+import importlib.util
+from pathlib import Path
+from types import ModuleType
+
+from managed_deepagents import ManagedChannelContext
+
+ROOT = Path(__file__).resolve().parents[2]
+
+
+def declaration() -> ModuleType:
+ spec = importlib.util.spec_from_file_location("mda_memory", ROOT / "memory.py")
+ assert spec is not None and spec.loader is not None
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ return module
+
+
+def channel(provider: str) -> ManagedChannelContext:
+ return ManagedChannelContext.model_construct(channel={"provider": provider}) # type: ignore[typeddict-item]
+
+
+def test_both_layers_are_mounted_and_the_team_layer_is_open_to_every_caller() -> None:
+ layers = declaration().memory.config["scope"]
+ assert [layer["type"] for layer in layers] == ["agent", "user"]
+ assert "allow" not in layers[0]
+
+
+def test_personal_memory_follows_the_person_anywhere_in_slack_and_nowhere_else() -> None:
+ allow = declaration().memory.config["scope"][1]["allow"]
+ assert allow(channel("slack")) is True
+ assert allow(channel("teams")) is False
+ assert allow({"channel": {"provider": "slack"}}) is False
+ assert allow(None) is False