feat(code): trace experimental mode in metadata (#4705)

Deep Agents Code traces now include `dcode_experimental: true` when
`DEEPAGENTS_CODE_EXPERIMENTAL` is enabled.

---

`DEEPAGENTS_CODE_EXPERIMENTAL` changes agent behavior, but traces
currently do not record whether that mode was active. This adds
`dcode_experimental: true` to trace-wide metadata whenever the
environment flag resolves to a truthy value. The key remains absent
otherwise, so default trace metadata is unchanged.
This commit is contained in:
Mason Daugherty
2026-07-13 18:19:12 -04:00
committed by GitHub
parent f77eeb0a03
commit 22d5045632
3 changed files with 29 additions and 2 deletions
+8 -1
View File
@@ -1676,6 +1676,9 @@ def build_stream_config(
This describes the Deep Agents package installed alongside the TUI, which
can differ from a remote graph's Deep Agents runtime version.
Also records `dcode_experimental=True` when `DEEPAGENTS_CODE_EXPERIMENTAL`
is enabled, so experimental runs are filterable in trace metadata.
Args:
thread_id: The app session thread identifier. Set both on
`configurable.thread_id` and as the top-level `metadata.thread_id`
@@ -1699,7 +1702,7 @@ def build_stream_config(
logger.warning("Could not determine working directory", exc_info=True)
cwd = ""
from deepagents_code._env_vars import USER_ID
from deepagents_code._env_vars import EXPERIMENTAL, USER_ID
metadata: dict[str, Any] = build_coding_agent_metadata(
thread_id=thread_id,
@@ -1711,6 +1714,10 @@ def build_stream_config(
user_id=os.environ.get(USER_ID) or None,
)
# Mark experimental runs so they are filterable in trace metadata.
if is_env_truthy(EXPERIMENTAL):
metadata["dcode_experimental"] = True
# Legacy / diagnostic keys preserved for backward-compatibility during the
# coding-agent-v1 rollout (not part of the contract).
metadata["lc_versions"] = {
@@ -200,7 +200,7 @@ class TestScrollDrivenHydration:
# Archive the newest rows below the window (the state after the user
# has scrolled up and older history was mounted in their place).
monkeypatch.setattr(app._message_store, "WINDOW_SIZE", 3)
monkeypatch.setattr(app._message_store, "HYDRATE_BUFFER", 2)
monkeypatch.setattr(app._message_store, "HYDRATE_BUFFER", 20)
messages = app.query_one("#messages", Container)
await app._prune_messages_below_window(messages)
await pilot.pause()
@@ -1092,6 +1092,26 @@ class TestBuildStreamConfig:
config = build_stream_config("t-nouid", assistant_id=None)
assert "user_id" not in config["metadata"]
def test_experimental_included_when_enabled(self) -> None:
"""Experimental runs should be identifiable in trace metadata."""
with patch.dict("os.environ", {"DEEPAGENTS_CODE_EXPERIMENTAL": "true"}):
config = build_stream_config("t-experimental", assistant_id=None)
assert config["metadata"]["dcode_experimental"] is True
def test_experimental_absent_when_disabled(self) -> None:
"""Default runs should not be labeled experimental."""
with patch.dict("os.environ", {"DEEPAGENTS_CODE_EXPERIMENTAL": "false"}):
config = build_stream_config("t-stable", assistant_id=None)
assert "dcode_experimental" not in config["metadata"]
def test_experimental_absent_when_unset(
self, monkeypatch: pytest.MonkeyPatch
) -> None:
"""The default path (env var unset) is not labeled experimental."""
monkeypatch.delenv("DEEPAGENTS_CODE_EXPERIMENTAL", raising=False)
config = build_stream_config("t-default", assistant_id=None)
assert "dcode_experimental" not in config["metadata"]
class TestGetGitBranch:
"""Tests for `_get_git_branch` caching."""