Build the shared coding-agent-v1 trace-metadata block. Implements the `coding-agent-v1` contract (LSEN-277) for Deep Agents Code: one helper that stamps the identity block, plugin/runtime versions, turn markers, and repo/git/cwd attribution. The seven identity/version keys and `thre
(
*,
thread_id: str,
turn_id: str | None,
turn_number: int | None,
cwd: str,
git_branch: str | None,
sandbox_type: str | None,
user_id: str | None,
)
| 1381 | |
| 1382 | |
| 1383 | def build_coding_agent_metadata( |
| 1384 | *, |
| 1385 | thread_id: str, |
| 1386 | turn_id: str | None, |
| 1387 | turn_number: int | None, |
| 1388 | cwd: str, |
| 1389 | git_branch: str | None, |
| 1390 | sandbox_type: str | None, |
| 1391 | user_id: str | None, |
| 1392 | ) -> dict[str, Any]: |
| 1393 | """Build the shared coding-agent-v1 trace-metadata block. |
| 1394 | |
| 1395 | Implements the `coding-agent-v1` contract (LSEN-277) for Deep Agents Code: |
| 1396 | one helper that stamps the identity block, plugin/runtime versions, turn |
| 1397 | markers, and repo/git/cwd attribution. The seven identity/version keys and |
| 1398 | `thread_id` are always present; the optional keys whose value is unknown are |
| 1399 | omitted (per the contract), so callers can pass `None` for any of them. |
| 1400 | |
| 1401 | Because Deep Agents Code is itself the runtime — there is no separate CLI |
| 1402 | package — `ls_integration_version` and `ls_agent_runtime_version` both come |
| 1403 | from the `deepagents-code` package version (`__version__`). The underlying |
| 1404 | `deepagents` SDK version is surfaced separately as |
| 1405 | `dcode_client_deepagents_version` by `build_stream_config`. |
| 1406 | |
| 1407 | Scope-restricted contract keys are intentionally NOT produced here: |
| 1408 | `approval_policy` (root/interrupted only) and `ls_subagent_id` / |
| 1409 | `ls_subagent_type` (subagent only). This metadata propagates trace-wide |
| 1410 | through the LangGraph stream config (and, for subagents, the per-key config |
| 1411 | merge of langgraph#7926 / deepagents#3634), so any key placed here lands on |
| 1412 | every descendant run. Emitting a run-type-scoped key would therefore leak it |
| 1413 | onto run types outside its contract `appliesTo` set — a hard validator |
| 1414 | failure — and the LangGraph runtime exposes no clean per-run-type metadata |
| 1415 | seam to scope them. See `build_stream_config` for the full rationale. |
| 1416 | |
| 1417 | Args: |
| 1418 | thread_id: Stable conversation id; also set as top-level `thread_id`. |
| 1419 | turn_id: Per-turn id (uuid4 / message id), or `None`. |
| 1420 | turn_number: 1-based per-thread turn index, or `None`. |
| 1421 | cwd: Current working directory, or empty string when unavailable. |
| 1422 | git_branch: Current branch name, or `None`. |
| 1423 | sandbox_type: Sandbox provider name, or `None`/`"none"` when inactive. |
| 1424 | user_id: Stable pseudonymous user id, or `None`. |
| 1425 | |
| 1426 | Returns: |
| 1427 | The contract metadata dict with unknown keys omitted. |
| 1428 | """ |
| 1429 | metadata: dict[str, Any] = { |
| 1430 | "ls_agent_kind": CODING_AGENT_KIND, |
| 1431 | "ls_integration": CODING_AGENT_INTEGRATION, |
| 1432 | "ls_agent_runtime": CODING_AGENT_RUNTIME, |
| 1433 | "thread_id": thread_id, |
| 1434 | "ls_trace_schema_version": CODING_AGENT_TRACE_SCHEMA_VERSION, |
| 1435 | "ls_integration_version": __version__, |
| 1436 | "ls_agent_runtime_version": __version__, |
| 1437 | } |
| 1438 | |
| 1439 | if turn_id: |
| 1440 | metadata["turn_id"] = turn_id |