MCPcopy Create free account
hub / github.com/langchain-ai/deepagents / build_stream_config

Function build_stream_config

libs/code/deepagents_code/config.py:1467–1560  ·  view source on GitHub ↗

Build the LangGraph stream config dict. Stamps the shared `coding-agent-v1` trace-metadata contract (LSEN-277) via `build_coding_agent_metadata` — identity block, plugin/runtime versions, turn markers, and repo/git/cwd attribution — onto `metadata`. Metadata set here propagates trac

(
    thread_id: str,
    assistant_id: str | None,
    *,
    sandbox_type: str | None = None,
    turn_id: str | None = None,
    turn_number: int | None = None,
)

Source from the content-addressed store, hash-verified

1465
1466
1467def build_stream_config(
1468 thread_id: str,
1469 assistant_id: str | None,
1470 *,
1471 sandbox_type: str | None = None,
1472 turn_id: str | None = None,
1473 turn_number: int | None = None,
1474) -> RunnableConfig:
1475 """Build the LangGraph stream config dict.
1476
1477 Stamps the shared `coding-agent-v1` trace-metadata contract (LSEN-277) via
1478 `build_coding_agent_metadata` — identity block, plugin/runtime versions,
1479 turn markers, and repo/git/cwd attribution — onto `metadata`. Metadata set
1480 here propagates trace-wide to every run in the graph (root, llm, tool, and
1481 subagent subgraphs), which is exactly what the contract's "always" and
1482 "where-known" keys require, so the helper output is stamped once here.
1483
1484 Scope-restricted contract keys are deliberately not emitted. `approval_policy`
1485 (root/interrupted only) and `ls_subagent_id` / `ls_subagent_type` (subagent
1486 only) cannot live in this trace-wide metadata: LangGraph propagates each key
1487 to all descendant runs (per-key config merge, langgraph#7926 /
1488 deepagents#3634), so they would leak onto run types outside their contract
1489 `appliesTo` set and fail validation. This runtime exposes no clean
1490 per-run-type metadata seam to scope them, so they are omitted by design
1491 rather than leaked. (Subagent runs still inherit the parent/root `thread_id`
1492 and all required keys, satisfying the contract's grouping rule.)
1493
1494 Also injects the dcode version into `metadata["lc_versions"]` so LangSmith
1495 traces can be correlated with specific releases. `create_deep_agent` supplies
1496 the SDK version through the compiled graph config, and LangChain merges
1497 nested metadata dictionaries so both versions survive at stream time.
1498
1499 Also records `dcode_client_deepagents_version` as a dcode-client diagnostic.
1500 This describes the Deep Agents package installed alongside the TUI, which
1501 can differ from a remote graph's Deep Agents runtime version.
1502
1503 Args:
1504 thread_id: The app session thread identifier. Set both on
1505 `configurable.thread_id` and as the top-level `metadata.thread_id`
1506 used by the contract for grouping turns.
1507 assistant_id: The dcode agent identifier, if any. When set, it is
1508 surfaced in trace metadata under `dcode_agent_name` and
1509 `agent_name`.
1510 sandbox_type: Sandbox provider name for trace metadata, or `None` if no
1511 sandbox is active.
1512 turn_id: Stable per-turn id for the current user prompt, or `None`.
1513 turn_number: 1-based per-thread turn index, or `None`.
1514
1515 Returns:
1516 Config dict with `configurable` and `metadata` keys.
1517 """
1518 from datetime import UTC, datetime
1519
1520 try:
1521 cwd = str(Path.cwd())
1522 except OSError:
1523 logger.warning("Could not determine working directory", exc_info=True)
1524 cwd = ""

Calls 6

_get_git_branchFunction · 0.85
_format_lc_versionFunction · 0.85
_is_editable_installFunction · 0.85
_get_deepagents_versionFunction · 0.85
getMethod · 0.45