# build_stream_config

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/config/build_stream_config)

Build the LangGraph stream config dict.

Stamps the shared `coding-agent-v1` trace-metadata contract via
`build_coding_agent_metadata` — identity block, plugin/runtime versions,
turn markers, and repo/git/cwd attribution — onto `metadata`. Metadata set
here propagates trace-wide to every run in the graph (root, llm, tool, and
subagent subgraphs), which is exactly what the contract's "always" and
"where-known" keys require, so the helper output is stamped once here.

Scope-restricted contract keys are deliberately not emitted. `approval_policy`
(root/interrupted only) and `ls_subagent_id` / `ls_subagent_type` (subagent
only) cannot live in this trace-wide metadata: LangGraph propagates each key
to all descendant runs (per-key config merge, langgraph#7926 /
deepagents#3634), so they would leak onto run types outside their contract
`appliesTo` set and fail validation. This runtime exposes no clean
per-run-type metadata seam to scope them, so they are omitted by design
rather than leaked. (Subagent runs still inherit the parent/root `thread_id`
and all required keys, satisfying the contract's grouping rule.)

Also injects the dcode version into `metadata["lc_versions"]` so LangSmith
traces can be correlated with specific releases. `create_deep_agent` supplies
the SDK version through the compiled graph config, and LangChain merges
nested metadata dictionaries so both versions survive at stream time.

Also records `dcode_client_deepagents_version` as a dcode-client diagnostic.
This describes the Deep Agents package installed alongside the TUI, which
can differ from a remote graph's Deep Agents runtime version. Editable
installs carry an `+editable` suffix, matching how the SDK stamps
`lc_versions["deepagents"]`; for sibling monorepo packages that suffix
identifies workspace HEAD relative to the pinned published SDK baseline.

Also records `editable` as an always-present boolean so editable dcode installs
can be filtered without parsing the `lc_versions["deepagents-code"]` suffix.

Also records `dcode_experimental=True` when `DEEPAGENTS_CODE_EXPERIMENTAL`
is enabled, so experimental runs are filterable in trace metadata.

Also records `dcode_auto_approve=True` when auto-approve ("YOLO") mode is
active, so runs that ran tools without HITL approval are filterable in trace
metadata. This is a diagnostic key, not the contract-scoped `approval_policy`
key (see above), so it is safe to stamp trace-wide.

Also records `dcode_term_program` from `TERM_PROGRAM` when that is non-empty
after stripping, so traces are groupable by launch environment (e.g.
"iTerm.app", "vscode", "Apple_Terminal"). Blank values are treated as unset
to match every other reader of this variable — some shells export
`TERM_PROGRAM=""` rather than leaving it unset, and terminals that never set
it (Windows Terminal, ssh, the Linux console) omit the key entirely rather
than forming a junk grouping bucket. This is a diagnostic key, not part of
the contract.

## Signature

```python
build_stream_config(
    thread_id: str,
    assistant_id: str | None,
    *,
    sandbox_type: str | None = None,
    turn_id: str | None = None,
    turn_number: int | None = None,
    auto_approve: bool = False,
    skill_name: str | None = None,
) -> RunnableConfig
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `thread_id` | `str` | Yes | The app session thread identifier. Set both on `configurable.thread_id` and as the top-level `metadata.thread_id` used by the contract for grouping turns. |
| `assistant_id` | `str \| None` | Yes | The dcode agent identifier, if any. When set, it is surfaced in trace metadata under `dcode_agent_name` and `agent_name`. |
| `sandbox_type` | `str \| None` | No | Sandbox provider name for trace metadata, or `None` if no sandbox is active. (default: `None`) |
| `turn_id` | `str \| None` | No | Stable per-turn id for the current user prompt, or `None`. (default: `None`) |
| `turn_number` | `int \| None` | No | 1-based per-thread turn index, or `None`. (default: `None`) |
| `auto_approve` | `bool` | No | Whether auto-approve ("YOLO") mode is active for this turn. When `True`, `dcode_auto_approve=True` is recorded in trace metadata. (default: `False`) |
| `skill_name` | `str \| None` | No | Invoked skill name to record in trace metadata, or `None`. (default: `None`) |

## Returns

`RunnableConfig`

Config dict with `configurable` and `metadata` keys, plus
`recursion_limit` when one is configured.

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/3812967c84d90619848f3185f22470204fc88bd8/libs/code/deepagents_code/config.py#L2137)