Skip to content

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

Every run names the template it came from, with an opt-out (#40)

Amal Irgashevde9394b9b10b
diff --git a/.env.example b/.env.example
index 32af274..935560b 100644
--- a/.env.example
+++ b/.env.example
@@ -68,6 +68,7 @@ DESIGN_AGENT_ENABLE_STEERING=1
DESIGN_AGENT_TRACE_HOST= # LangSmith UI host for the footer's trace link; unset, no link
DESIGN_AGENT_ENABLE_LEARNING=1
DESIGN_AGENT_ENABLE_TRACES=1 # the agent reads every thread's traces in its LangSmith project
+DESIGN_AGENT_TEMPLATE_TELEMETRY=1 # traces name the template and version; 0 leaves it off
DESIGN_AGENT_ENABLE_TOOL_CLEARING=0
# MDA Slack appearance
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b7221a4..3a4599c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@
### Added
+- Every run's trace names the template it came from: a `template:langchain-ai/design-agent` tag
+ and `ls_template` / `ls_template_version` metadata, on MDA's root run and through the shared
+ trace middleware everywhere else, so a renamed fork still counts. Nothing about the deployment
+ or its people; `DESIGN_AGENT_TEMPLATE_TELEMETRY=0` turns it off.
- 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.
diff --git a/OPERATIONS.md b/OPERATIONS.md
index 947db85..9ad99e3 100644
--- a/OPERATIONS.md
+++ b/OPERATIONS.md
@@ -21,6 +21,10 @@ Settings live in `.env` (Git-ignored); `.env.example` documents every one.
them, `config generate` fills random tokens and passwords. `uv run design-agent doctor` checks the
model for every role, the brand pack, the sandbox and the MDA declarations without printing secrets.
+Every run's trace names the template it came from (`ls_template: langchain-ai/design-agent` and its
+version) so LangChain can count deployments of this repository; nothing about you or your people
+goes with it. `DESIGN_AGENT_TEMPLATE_TELEMETRY=0` turns it off.
+
## The sandbox computer
One recipe (`sandbox/setup.sh`) builds every sandbox: the local Docker image
diff --git a/agent.py b/agent.py
index c62052e..8392f0a 100644
--- a/agent.py
+++ b/agent.py
@@ -7,9 +7,11 @@ from pathlib import Path
from managed_deepagents import define_deep_agent
from design_agent.config import Settings
+from design_agent.middleware.tracing import template_marker
from design_agent.runtime.mda import build_mda_components
-_components = build_mda_components(Settings(), project_root=Path(__file__).parent)
+_settings = Settings()
+_components = build_mda_components(_settings, project_root=Path(__file__).parent)
agent = define_deep_agent(
name="design-agent",
@@ -18,4 +20,5 @@ agent = define_deep_agent(
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,
)
diff --git a/docs/architecture/surfaces.md b/docs/architecture/surfaces.md
index ed20fd7..e007d7c 100644
--- a/docs/architecture/surfaces.md
+++ b/docs/architecture/surfaces.md
@@ -22,8 +22,9 @@ stream) and `src/design_agent/middleware/{progress,footer,steering,tracing}.py`.
the helper reads it before its next model call. While the lead's own turn is busy, it reads new
messages in the thread before each model call and folds them in; "stop", "cancel" or "never mind"
ends the turn at its next step.
-- **Trace tags.** Each run is tagged with its trigger, surface and the kinds of files delivered; no
- user ids by default.
+- **Trace tags.** Each run is tagged with its trigger, surface and the kinds of files delivered, and
+ names the template and version it came from (`DESIGN_AGENT_TEMPLATE_TELEMETRY=0` turns that
+ off); no user ids by default.
The bot token stays on the host: progress and footer call the Slack Web API from middleware, and
the sandbox never sees a token, a Slack URL or a Slack payload.
diff --git a/src/design_agent/assembly.py b/src/design_agent/assembly.py
index 2f2f276..df5903f 100644
--- a/src/design_agent/assembly.py
+++ b/src/design_agent/assembly.py
@@ -47,7 +47,7 @@ from design_agent.middleware.steering import (
SteeringToolsMiddleware,
)
from design_agent.middleware.today import TodayMiddleware, ZoneFor, fixed_zone
-from design_agent.middleware.tracing import RunTagsMiddleware, TraceLinks
+from design_agent.middleware.tracing import RunTagsMiddleware, TraceLinks, template_marker
from design_agent.middleware.watch_tools import WatchToolsMiddleware
from design_agent.middleware.workspace import WorkspaceStagerMiddleware
from design_agent.models.factory import Role, build_chat_model, resolve_model
@@ -211,7 +211,10 @@ def build_agent_components(
),
TodoListMiddleware(),
TodayMiddleware(zone_for=zone_for or fixed_zone(settings.timezone)),
- RunTagsMiddleware(surface=runtime.surface),
+ RunTagsMiddleware(
+ surface=runtime.surface,
+ template=template_marker() if settings.template_telemetry else None,
+ ),
]
slack = runtime.slack
servers = services([s.name for s in mcp_servers])
diff --git a/src/design_agent/config.py b/src/design_agent/config.py
index 54a5ae6..e455687 100644
--- a/src/design_agent/config.py
+++ b/src/design_agent/config.py
@@ -163,6 +163,9 @@ class Settings(BaseSettings):
enable_traces: bool = True
"""`list_traces` and `read_trace`: the agent reads every thread's traces in its own LangSmith
project with the host's credentials. Turn off where people must not see each other's requests."""
+ template_telemetry: bool = True
+ """Every run's trace names the template and its version (`ls_template`), so LangChain can count
+ deployments of this repository. Nothing about the deployment or its people."""
enable_tool_clearing: bool = False
"""Server-side clearing of old tool results in helpers' requests (Anthropic only)."""
timezone: str = "UTC"
diff --git a/src/design_agent/middleware/tracing.py b/src/design_agent/middleware/tracing.py
index 1d2b8aa..75e0124 100644
--- a/src/design_agent/middleware/tracing.py
+++ b/src/design_agent/middleware/tracing.py
@@ -9,7 +9,10 @@ trace's root carries tags (and the same facts as metadata):
approval or a prompt answer), `helper` (a background helper's own trace);
- `surface:<name>`: the channel provider (`slack`), else the runtime's default (`cli`, `api`);
- `delivered:<kind>`: one per kind of file `upload_files` sent (`image`, `video`, `audio`, `pdf`,
- `other`), on the root when it is still running and on the tool call's own run otherwise.
+ `other`), on the root when it is still running and on the tool call's own run otherwise;
+- `template:langchain-ai/design-agent`, with `ls_template` and `ls_template_version` metadata: the
+ repository and version every deployment runs, however it is renamed, so LangChain can count
+ adopters. `DESIGN_AGENT_TEMPLATE_TELEMETRY=0` leaves it off.
No user ids, names, channels or message text go on a trace from here.
@@ -30,6 +33,7 @@ import logging
import mimetypes
from collections.abc import Awaitable, Callable, Iterable, Mapping, Sequence
from dataclasses import dataclass
+from importlib import metadata as package_metadata
from typing import Any
from langchain.agents.middleware import AgentMiddleware, AgentState
@@ -41,6 +45,7 @@ from langgraph.types import Command
from langsmith import RunTree
from langsmith.run_helpers import get_current_run_tree
+from design_agent import __version__
from design_agent.harness import tasks
from design_agent.middleware.background import CHECK_IN_MARK
from design_agent.middleware.quiet import SENTINEL_MARK
@@ -60,6 +65,16 @@ DELIVERED_KINDS = (
)
#: Human messages the runtime writes, not a person: the date note and the running-work note.
NOTE_IDS = (DATE_NOTE, "running:")
+TEMPLATE = "langchain-ai/design-agent"
+
+
+def template_marker() -> dict[str, str]:
+ """The template and its version (module doc): nothing about the deployment or its people."""
+ try:
+ version = package_metadata.version("design-agent")
+ except package_metadata.PackageNotFoundError:
+ version = __version__
+ return {"ls_template": TEMPLATE, "ls_template_version": version}
@dataclass(frozen=True)
@@ -151,12 +166,19 @@ class RunTagsMiddleware(AgentMiddleware[AgentState[Any], Any, Any]):
"""Tag the run's trace with its trigger, surface and deliveries (module doc).
`surface` names runs that come through no platform channel (`cli` locally, `api` on the
- self-hosted API), or is a function of the runtime for adapters that know better.
+ self-hosted API), or is a function of the runtime for adapters that know better. `template`
+ is `template_marker()`, or empty when the operator turned it off.
"""
- def __init__(self, *, surface: str | Callable[[Any], str] = "api") -> None:
+ def __init__(
+ self,
+ *,
+ surface: str | Callable[[Any], str] = "api",
+ template: Mapping[str, str] | None = None,
+ ) -> None:
super().__init__()
self._surface = surface
+ self._template = dict(template or {})
@property
def name(self) -> str:
@@ -174,11 +196,10 @@ class RunTagsMiddleware(AgentMiddleware[AgentState[Any], Any, Any]):
if root is not None:
trigger = trigger_of(runtime, list(state.get("messages") or []))
surface = self._surface_of(runtime)
- stamp(
- root,
- [TRIGGER.format(trigger), SURFACE.format(surface)],
- {"trigger": trigger, "surface": surface},
- )
+ tags = [TRIGGER.format(trigger), SURFACE.format(surface)]
+ if self._template:
+ tags.append(f"template:{self._template['ls_template']}")
+ stamp(root, tags, {"trigger": trigger, "surface": surface, **self._template})
except Exception as error: # noqa: BLE001 - a label is never worth a run
_LOGGER.warning("[trace] run not labeled: %s", type(error).__name__)
return None
diff --git a/tests/unit/test_template_marker.py b/tests/unit/test_template_marker.py
new file mode 100644
index 0000000..ee99939
--- /dev/null
+++ b/tests/unit/test_template_marker.py
@@ -0,0 +1,60 @@
+"""Every run names the template it came from, renamed or not, unless the operator turns it off."""
+
+from __future__ import annotations
+
+import importlib.util
+from pathlib import Path
+from types import ModuleType, SimpleNamespace
+
+import pytest
+from langchain_core.messages import HumanMessage
+from langsmith import RunTree
+
+from design_agent.middleware import tracing
+from design_agent.middleware.tracing import RunTagsMiddleware, template_marker
+
+ROOT = Path(__file__).resolve().parents[2]
+
+
+def mda_definition() -> ModuleType:
+ spec = importlib.util.spec_from_file_location("mda_agent", ROOT / "agent.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
+
+
+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))
+ await middleware.abefore_agent({"messages": [HumanMessage("hi")]}, SimpleNamespace())
+ return run
+
+
+def test_the_marker_is_the_template_and_its_version_only() -> None:
+ marker = template_marker()
+ assert set(marker) == {"ls_template", "ls_template_version"}
+ assert marker["ls_template"] == "langchain-ai/design-agent"
+ assert marker["ls_template_version"]
+
+
+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()
+ 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
+ assert run.metadata["ls_template"] == "langchain-ai/design-agent"
+
+
+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
+ tags = 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)
+ assert "ls_template" not in run.metadata