Skip to content

feat(core,partners): add package version tracking to tracing metadata - #35295

Merged
Mason Daugherty (mdrxy) merged 33 commits into
masterfrom
mdrxy/versioning
Jun 11, 2026
Merged

feat(core,partners): add package version tracking to tracing metadata#35295
Mason Daugherty (mdrxy) merged 33 commits into
masterfrom
mdrxy/versioning

Conversation

@mdrxy

@mdrxy Mason Daugherty (mdrxy) commented Feb 18, 2026

Copy link
Copy Markdown
Member

Following on the heels of #35293

TODO:

  • Packages outside of this repo (e.g. LiteLLM, Nvidia, Google, AWS)

Summary

Surface partner package versions in metadata.versions on LangSmith traces. Mirrors the JS SDK's _addVersion() pattern (langchainjs#10106).

Each model constructor records its package version via _add_version() on BaseLanguageModel. The version dict accumulates through the class hierarchy — langchain-core is added in BaseLanguageModel.model_post_init, langchain-openai in BaseChatOpenAI._set_openai_chat_version, and each leaf partner in its uniquely-named model_validator. Traces end up with:

{
  "metadata": {
    "versions": {
      "langchain-core": "1.4.5",
      "langchain-openai": "1.3.0",
      "langchain-xai": "1.2.2"
    }
  }
}

Changes

  • BaseLanguageModel._add_version(pkg, version) — appends to self.metadata["versions"]; accepts any Mapping type; emits a warning if a non-mapping value is found and replaced
  • BaseLanguageModel.model_post_init — adds langchain-core version; calls super() for MRO safety
  • _merge_metadata_dicts — one-level-deep (non-recursive) merge for nested dict metadata keys
  • CallbackManager.add_metadata — uses _merge_metadata_dicts instead of flat dict.update() so nested metadata dicts (like versions) coexist rather than clobber
  • merge_configs — uses _merge_metadata_dicts for config merging

Partners:

  • Each now calls self._add_version("langchain-<pkg>", __version__)

Design decisions

  • Constructor-based, not _get_ls_params-based — versions flow through self.metadata (local metadata on traces), not through LangSmithParams. This matches JS and makes child-class version inheritance automatic (no merge/clobber issues).
  • versions is local (non-inheritable) metadataself.metadata is passed to CallbackManager.configure as local_metadata (add_metadata(..., inherit=False)), so versions is attached once per chat-model run and is not propagated to child runs or duplicated onto every streaming chunk. This is intentionally the opposite of the inheritable-per-chunk metadata that chore(core): reduce streaming metadata / perf #36588 was reducing for performance — versions does not regress that path.
  • add_metadata deep-merge is a correctness fix, not just for versions — previously add_metadata/merge_configs did a flat top-level dict.update/spread, so any nested metadata dict baked into a config (e.g. via .with_config({"metadata": {...}})) would be wholly replaced when a caller also passed metadata. _merge_metadata_dicts merges one level deep so user-provided config.metadata.versions and model-set versions coexist instead of clobbering. The merge runs once per configure (not per chunk), so it is off the streaming hot path.
  • One level deep only_merge_metadata_dicts is deliberately not a recursive deep merge; values nested more than one level are last-writer-wins. This covers the versions case without the ambiguity/cost of arbitrary-depth merging.
  • Warn on non-dict metadata["versions"] — if a user sets metadata={"versions": "some-string"}, _add_version emits a warning and replaces the value with the version dict rather than silently discarding user data or crashing. This is a soft breaking change for anyone who previously stored non-dict values at this key.

Follow-ups (tracked separately, out of scope here)

  • JS mergeConfigs still flat-spreads nested metadata, so metadata.versions can still clobber on the JS side until an equivalent deep-merge lands.

Made by Open SWE

@github-actions github-actions Bot added integration PR made that is related to a provider partner package integration core `langchain-core` package issues & PRs anthropic `langchain-anthropic` package issues & PRs internal feature For PRs that implement a new feature; NOT A FEATURE REQUEST labels Feb 18, 2026
@codspeed-hq

codspeed-hq Bot commented Feb 18, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 84.24%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 8 improved benchmarks
❌ 6 regressed benchmarks
✅ 12 untouched benchmarks
⏩ 14 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime test_import_time[HumanMessage] 232.4 ms 207.3 ms +12.09%
WallTime test_import_time[RunnableLambda] 452.3 ms 394.1 ms +14.77%
WallTime test_import_time[LangChainTracer] 404.5 ms 361.3 ms +11.96%
WallTime test_import_time[tool] 485.6 ms 422.3 ms +14.99%
WallTime test_async_callbacks_in_sync 20.1 ms 14.8 ms +35.15%
WallTime test_import_time[InMemoryVectorStore] 547 ms 496.2 ms +10.23%
WallTime test_import_time[PydanticOutputParser] 495.7 ms 440.5 ms +12.54%
WallTime test_import_time[ChatPromptTemplate] 583.1 ms 490.1 ms +18.97%
WallTime test_init_time 3.6 ms 10.2 ms -65.29%
WallTime test_init_time 3.5 ms 10.3 ms -65.48%
Simulation test_init_time_with_client 3 ms 12.8 ms -76.33%
Simulation test_init_time 1.9 ms 11.8 ms -84.24%
WallTime test_init_time 453.7 ms 529.4 ms -14.29%
Simulation test_init_time 7.3 ms 9.1 ms -19.49%

Comparing mdrxy/versioning (4d77e2b) with master (2f64d80)

Open in CodSpeed

Footnotes

  1. 14 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions github-actions Bot added deepseek `langchain-deepseek` package issues & PRs fireworks `langchain-fireworks` package issues & PRs groq `langchain-groq` package issues & PRs mistralai `langchain-mistralai` package issues & PRs ollama `langchain-ollama` package issues & PRs openai `langchain-openai` package issues & PRs xai `langchain-xai` package issues & PRs openrouter `langchain-openrouter` package issues & PRs labels Feb 18, 2026
@github-actions github-actions Bot added the size: M 200-499 LOC label Mar 9, 2026
@github-actions github-actions Bot added github_actions Pull requests that update GitHub Actions code size: XL 1000+ LOC and removed size: M 200-499 LOC labels Mar 22, 2026
@mdrxy Mason Daugherty (mdrxy) removed huggingface `langchain-huggingface` package issues & PRs mistralai `langchain-mistralai` package issues & PRs ollama `langchain-ollama` package issues & PRs openai `langchain-openai` package issues & PRs perplexity `langchain-perplexity` package issues & PRs xai `langchain-xai` package issues & PRs openrouter `langchain-openrouter` package issues & PRs labels Jun 3, 2026
Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
@github-actions github-actions Bot added anthropic `langchain-anthropic` package issues & PRs deepseek `langchain-deepseek` package issues & PRs fireworks `langchain-fireworks` package issues & PRs groq `langchain-groq` package issues & PRs huggingface `langchain-huggingface` package issues & PRs mistralai `langchain-mistralai` package issues & PRs ollama `langchain-ollama` package issues & PRs openai `langchain-openai` package issues & PRs openrouter `langchain-openrouter` package issues & PRs perplexity `langchain-perplexity` package issues & PRs xai `langchain-xai` package issues & PRs labels Jun 11, 2026
Mason Daugherty (mdrxy) and others added 6 commits June 11, 2026 04:22
…ions

- Update test_invocation_params_passed_to_tracer_metadata and syrupy
  snapshots to account for metadata['versions'] now on traces
- Sync stale partner _version.py files with pyproject.toml versions
- Clarify _merge_metadata_dicts docstring (one level deep, not recursive)

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
@mdrxy Mason Daugherty (mdrxy) changed the title feat: add package version tracking to tracing metadata feat(core,partners): add package version tracking to tracing metadata Jun 11, 2026
@mdrxy
Mason Daugherty (mdrxy) merged commit 948f6cc into master Jun 11, 2026
231 of 235 checks passed
@mdrxy
Mason Daugherty (mdrxy) deleted the mdrxy/versioning branch June 11, 2026 06:23
Marcelo5444 pushed a commit to Marcelo5444/deepagents that referenced this pull request Jul 30, 2026
)

Stamp `metadata.versions` on traces to surface the `deepagents` and
`deepagents-cli` versions that produced a run.

Consolidates the duplicated stream config builder from
`textual_adapter.py` and `non_interactive.py` into a single
`build_stream_config` in `config.py`.

Upstream `langchain-core`
[#35295](langchain-ai/langchain#35295) is **not
required** — this PR is self-contained. Once it lands, inner LLM call
traces will additionally carry `langchain-core` / `langchain-anthropic`
/ etc. versions via `_add_version()`, and the `add_metadata` deep-merge
in callbacks will preserve them alongside the graph-level versions set
here.

## Changes
- `build_stream_config` injects both `deepagents-cli` and `deepagents`
SDK versions into `metadata["versions"]` — the CLI must include both
because LangGraph shallow-merges metadata dicts, so the CLI's `versions`
dict replaces the SDK's at stream time
- SDK version is resolved via `importlib.metadata.version("deepagents")`
(not a direct import) to avoid pulling the heavy SDK package into the
CLI's startup path

## How version metadata flows through a trace

`create_deep_agent` bakes `versions: {"deepagents": "X.Y.Z"}` into the
compiled graph via `with_config`. The CLI adds `{"deepagents-cli":
"X.Y.Z"}` via `build_stream_config`. LangGraph propagates this config
metadata down to every node in the graph.

With `langchain-core`
[#35295](langchain-ai/langchain#35295), each
chat model will also stamps its own versions (`langchain-core`,
`langchain-anthropic`, etc.) on `self.metadata` via `_add_version()` in
the constructor. The `add_metadata` deep-merge in callbacks ensures
these survive alongside the inherited graph-level versions. The final
inner LLM call trace carries all versions:

```json
{
  "ls_integration": "deepagents",
  "versions": {
    "deepagents": "0.5.0",
    "deepagents-cli": "0.0.34",
    "langchain-core": "0.3.42",
    "langchain-anthropic": "1.3.3"
  }
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

anthropic `langchain-anthropic` package issues & PRs core `langchain-core` package issues & PRs deepseek `langchain-deepseek` package issues & PRs feature For PRs that implement a new feature; NOT A FEATURE REQUEST fireworks `langchain-fireworks` package issues & PRs github_actions Pull requests that update GitHub Actions code groq `langchain-groq` package issues & PRs huggingface `langchain-huggingface` package issues & PRs integration PR made that is related to a provider partner package integration internal mistralai `langchain-mistralai` package issues & PRs ollama `langchain-ollama` package issues & PRs openai `langchain-openai` package issues & PRs openrouter `langchain-openrouter` package issues & PRs perplexity `langchain-perplexity` package issues & PRs size: XL 1000+ LOC xai `langchain-xai` package issues & PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant