Open-source design agent: on-brand stills, decks, diagrams, charts and motion graphics from a chat thread, built on Deep Agents.
JavaScript agentagentsai-agentdeepagentsdesignhyperframeslanggraphmanaged-agentsmotion-graphicspaperslackvideo
Memory: select layers per run instead of the deprecated allow policy (#54)
Amal Irgashev8ca97254acf5
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex ee0da48..7140e94 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -37,7 +37,7 @@ jobs:- name: Vendored skills match skills-lock.jsonrun: uv run --frozen design-agent skills verify- name: MDA definition import smoke- run: uv run --frozen python -c "import agent; print(agent.agent.config['name'])"+ run: uv run --frozen python -c "import agent, types; print(agent.agent(types.SimpleNamespace(channel=None)).config['name'])"- name: MDA compiles the project as it is (what `mda deploy` ships)run: uv run --frozen mda build .diff --git a/CHANGELOG.md b/CHANGELOG.mdindex dfac7c7..18d9788 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -42,6 +42,9 @@### Changed+- Personal memory reaches Slack channel threads through MDA's per-run layer selection: `agent.py`+ is a factory that selects both memory layers for every Slack run, replacing the `allow(context)`+ policy MDA deprecated in 0.9.0. Who gets which layer where is unchanged.- A plain `mda deploy` deploys the project, and `mda dev` runs it: vendored skills' binary files(fonts) live in `skill-binaries/`, so `skills/` syncs to Context Hub as it is. The `deploy` and`dev` wrappers are gone; `doctor` checks what would make `mda deploy` fail or ship the wrongdiff --git a/agent.py b/agent.pyindex 8392f0a..de44a11 100644--- a/agent.py+++ b/agent.py@@ -1,24 +1,43 @@-"""Managed Deep Agents entry. Thin: it only hands the shared components to `define_deep_agent`."""+"""Managed Deep Agents entry. Thin: it hands the shared components to `define_deep_agent`.++`agent` is a factory MDA calls at the start of each run, so a Slack run can select both memory+layers (`memory.py`); every other run keeps the declaration. The components are built once, here.+"""from __future__ import annotationsfrom pathlib import Path+from typing import TypedDict-from managed_deepagents import define_deep_agent+from managed_deepagents import (+ DeepAgentDefinition,+ ManagedServerRuntime,+ MemoryDefinition,+ define_deep_agent,+)from design_agent.config import Settingsfrom design_agent.middleware.tracing import template_markerfrom design_agent.runtime.mda import build_mda_components+from memory import memory, slack_run_settings = Settings()_components = build_mda_components(_settings, project_root=Path(__file__).parent)-agent = define_deep_agent(- name="design-agent",- model=_components.model,- tools=list(_components.tools),- middleware=list(_components.middleware),- subagents=list(_components.subagents) or None,- interrupt_on=dict(_components.interrupt_on) or None,- metadata=template_marker() if _settings.template_telemetry else None,-)++class _Selection(TypedDict, total=False):+ memory: MemoryDefinition+++def agent(runtime: ManagedServerRuntime) -> DeepAgentDefinition:+ selection: _Selection = {"memory": memory} if slack_run(runtime) else {}+ return define_deep_agent(+ name="design-agent",+ model=_components.model,+ tools=list(_components.tools),+ middleware=list(_components.middleware),+ subagents=list(_components.subagents) or None,+ interrupt_on=dict(_components.interrupt_on) or None,+ metadata=template_marker() if _settings.template_telemetry else None,+ **selection,+ )diff --git a/docs/architecture/README.md b/docs/architecture/README.mdindex 0d0166a..0f72ad6 100644--- a/docs/architecture/README.md+++ b/docs/architecture/README.md@@ -89,7 +89,7 @@ keep the keys, and drop their results in as files:| | Managed Deep Agents | Self-hosted || --- | --- | --- |-| Agent | `agent.py` (`define_deep_agent`), `identity.py`, `memory.py`, `tools/mcp.py` | the same assembly in a FastAPI app |+| Agent | `agent.py` (a `define_deep_agent` factory), `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 |diff --git a/docs/deploy-mda.md b/docs/deploy-mda.mdindex 5511529..a832383 100644--- a/docs/deploy-mda.md+++ b/docs/deploy-mda.md@@ -123,9 +123,11 @@ follow-ups while a job runs ([surfaces](architecture/surfaces.md)).and tidies expired schedules, with no model call.- **Memory.** `memory.py` turns on two layers. `/memories/agent/` is the team's: anyone whomentions 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.+ belongs to the person asking; MDA mounts it only when a verified person is behind the run. By+ MDA's default that is their DM and Studio; `agent.py` is a factory that selects both layers for+ every Slack run, so personal memory follows people into channel threads. Each layer's `AGENTS.md`+ loads on every turn. To keep personal memory to DMs, return the definition without `memory` on+ Slack runs too; to turn memory off, delete `memory.py` and that selection.- **MCP servers** come from `config/mcp.toml` through `tools/mcp.py`. A server that needscredentials names an agent-owned workspace connection (`connection = "slug"`); header values arenever compiled into the deployment.diff --git a/docs/sources/official-links.md b/docs/sources/official-links.mdindex 6345dfe..aad9cd2 100644--- a/docs/sources/official-links.md+++ b/docs/sources/official-links.md@@ -48,8 +48,10 @@ Verified against the installed 0.9.3 package while building (its README ships in`managed_deepagents-0.9.3.dist-info/METADATA`): `mda build` reads declarations statically, so`sandbox/__init__.py` and `schedules/*.py` hold literals or top-level constants; a static agentdeclares MCP servers in `tools/mcp.py` as a module-level `mcp` (passing `mcp=` to-`define_deep_agent` is refused); connector tools are named `{server}_{tool}`; schedule delivery is-an `after_agent` hook installed ahead of authored middleware.+`define_deep_agent` is refused); an `agent` factory may select `mcp`, `memory` and the other managed+resources per run (0.9.4), keeps the project's declaration for any it leaves out, and cannot give a+selected memory layer the `allow(context)` policy (deprecated in 0.9.0); connector tools are named+`{server}_{tool}`; schedule delivery is an `after_agent` hook installed ahead of authored middleware.Confirm each URL still resolves when you move a pin forward; the docs site renames pages.diff --git a/docs/spec.md b/docs/spec.mdindex 07bd1b8..bcea195 100644--- a/docs/spec.md+++ b/docs/spec.md@@ -419,8 +419,9 @@ default when a store exists.### 7.13 Memory (on for MDA)-`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 →+`memory.py` declares MDA native memory: a team layer for every caller and a personal layer per person.+The `agent.py` factory selects both layers for every Slack run, so the personal layer mounts anywhere+in Slack (MDA's default is the person's DM and Studio 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 hotfile 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 aprimary value driver for design work; observations (§7.12) carry most of the learning.diff --git a/memory.py b/memory.pyindex 246426b..b3f62d6 100644--- a/memory.py+++ b/memory.py@@ -1,21 +1,24 @@"""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.-"""+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.-from managed_deepagents import ManagedChannelContext, MemoryLayer, define_memory+Declared here, the personal layer mounts where MDA's defaults put it: the person's Slack DM and+Studio. People ask for work in channel threads, so `agent.py` selects both layers for every Slack+run (`slack_run`) and their preferences follow them there. The cost: their hot `AGENTS.md` is in+context in a shared thread, which is why `instructions.md` says never to repeat it there.+"""+from managed_deepagents import ManagedServerRuntime, 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).+memory = define_memory(agent=MemoryLayer(), user=MemoryLayer())- 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"+def slack_run(runtime: ManagedServerRuntime) -> bool:+ """A run a Slack event started (a mention, a DM, a thread reply or an approval click).-memory = define_memory(agent=MemoryLayer(), user=MemoryLayer(allow=personal_memory_in_slack))+ MDA sets the runtime's channel only for a channel run, from its own routing, never from the+ context a caller sends; inspection, Studio, API and scheduled runs have none.+ """+ return runtime.channel is not None and runtime.channel.provider == "slack"diff --git a/src/design_agent/runtime/mda.py b/src/design_agent/runtime/mda.pyindex 74f28ae..d677b58 100644--- a/src/design_agent/runtime/mda.py+++ b/src/design_agent/runtime/mda.py@@ -2,7 +2,7 @@`agent.py` hands these components to `define_deep_agent`. Only public `managed_deepagents`names are used anywhere in this package. MCP servers declared in `config/mcp.toml` reach MDA through-`tools/mcp.py` (MDA's convention for a static agent); MDA loads their tools at runtime, so the+`tools/mcp.py` (MDA's project declaration, which the `agent.py` factory leaves unselected); MDA loads their tools at runtime, so thecomponents only need the server names (for disclosure and the call-time boundary)."""diff --git a/tests/unit/test_mda_memory.py b/tests/unit/test_mda_memory.pyindex 6cb2acf..fdd09a3 100644--- a/tests/unit/test_mda_memory.py+++ b/tests/unit/test_mda_memory.py@@ -1,37 +1,62 @@-"""MDA memory (`memory.py`): a team layer for every caller, a personal layer anywhere in Slack."""+"""MDA memory: a team layer for every caller, a personal layer that follows a person anywhere in Slack.++`memory.py` declares both layers with no policy, so MDA's defaults apply (personal memory in the+person's DM and Studio); the `agent.py` factory selects both for every Slack run.+"""from __future__ import annotationsimport importlib.utilfrom pathlib import Path-from types import ModuleType+from types import ModuleType, SimpleNamespace+from typing import Any-from managed_deepagents import ManagedChannelContext+import pytestROOT = Path(__file__).resolve().parents[2]-def declaration() -> ModuleType:- spec = importlib.util.spec_from_file_location("mda_memory", ROOT / "memory.py")+def load(name: str, monkeypatch: pytest.MonkeyPatch) -> ModuleType:+ monkeypatch.syspath_prepend(str(ROOT))+ spec = importlib.util.spec_from_file_location(f"mda_{name}", ROOT / f"{name}.py")assert spec is not None and spec.loader is not Nonemodule = 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 run_from(provider: str | None) -> Any:+ """The part of MDA's factory runtime the selection reads: the channel a run arrived on."""+ return SimpleNamespace(channel=None if provider is None else SimpleNamespace(provider=provider))++def layer_types(memory: Any) -> list[str]:+ return [layer["type"] for layer in memory.config["scope"]]-def test_both_layers_are_mounted_and_the_team_layer_is_open_to_every_caller() -> None:- layers = declaration().memory.config["scope"]++def test_both_layers_are_declared_with_no_policy(monkeypatch: pytest.MonkeyPatch) -> None:+ layers = load("memory", monkeypatch).memory.config["scope"]assert [layer["type"] for layer in layers] == ["agent", "user"]- assert "allow" not in layers[0]+ assert not any("allow" in layer for layer in layers)+++def test_a_slack_run_selects_both_layers(monkeypatch: pytest.MonkeyPatch) -> None:+ selected = load("agent", monkeypatch).agent(run_from("slack")).config["memory"]+ assert layer_types(selected) == ["agent", "user"]+ assert not any("allow" in layer for layer in selected.config["scope"])++[email protected]("provider", [None, "teams"])+def test_every_other_run_keeps_the_declaration(+ provider: str | None, monkeypatch: pytest.MonkeyPatch+) -> None:+ definition = load("agent", monkeypatch).agent(run_from(provider))+ assert definition.config["name"] == "design-agent"+ assert "memory" not in definition.config-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+def test_the_selection_changes_nothing_but_memory(monkeypatch: pytest.MonkeyPatch) -> None:+ """MDA calls the factory again on resume, so what can interrupt a run must not depend on it."""+ agent = load("agent", monkeypatch).agent+ slack, studio = agent(run_from("slack")).config, agent(run_from(None)).config+ assert {key: value for key, value in slack.items() if key != "memory"} == studiodiff --git a/tests/unit/test_template_marker.py b/tests/unit/test_template_marker.pyindex ee99939..99cd068 100644--- a/tests/unit/test_template_marker.py+++ b/tests/unit/test_template_marker.py@@ -16,7 +16,8 @@ from design_agent.middleware.tracing import RunTagsMiddleware, template_markerROOT = Path(__file__).resolve().parents[2]-def mda_definition() -> ModuleType:+def mda_definition(monkeypatch: pytest.MonkeyPatch) -> ModuleType:+ monkeypatch.syspath_prepend(str(ROOT))spec = importlib.util.spec_from_file_location("mda_agent", ROOT / "agent.py")assert spec is not None and spec.loader is not Nonemodule = importlib.util.module_from_spec(spec)@@ -24,6 +25,11 @@ def mda_definition() -> ModuleType:return module+def root_metadata(module: ModuleType) -> object:+ """What the factory gives a run with no channel (Studio, the API, inspection)."""+ return module.agent(SimpleNamespace(channel=None)).config.get("metadata")++async def tags_on_a_run(middleware: RunTagsMiddleware, monkeypatch: pytest.MonkeyPatch) -> RunTree:run = RunTree(name="renamed-agent", run_type="chain", session_name="renamed-agent")monkeypatch.setattr(tracing, "trace_runs", lambda: (run, run))@@ -42,8 +48,8 @@ async def test_the_mda_root_run_and_every_run_carry_the_marker(monkeypatch: pytest.MonkeyPatch,) -> None:monkeypatch.setenv("DESIGN_AGENT_TEMPLATE_TELEMETRY", "1")- module = mda_definition()- assert module.agent.config["metadata"] == template_marker()+ module = mda_definition(monkeypatch)+ assert root_metadata(module) == template_marker()tags = next(m for m in module._components.middleware if isinstance(m, RunTagsMiddleware))run = await tags_on_a_run(tags, monkeypatch)assert "template:langchain-ai/design-agent" in run.tags@@ -52,8 +58,8 @@ async def test_the_mda_root_run_and_every_run_carry_the_marker(async def test_the_operator_can_turn_it_off(monkeypatch: pytest.MonkeyPatch) -> None:monkeypatch.setenv("DESIGN_AGENT_TEMPLATE_TELEMETRY", "0")- module = mda_definition()- assert module.agent.config.get("metadata") is None+ module = mda_definition(monkeypatch)+ assert root_metadata(module) is Nonetags = next(m for m in module._components.middleware if isinstance(m, RunTagsMiddleware))run = await tags_on_a_run(tags, monkeypatch)assert not any(tag.startswith("template:") for tag in run.tags)