Skip to content

fix(langchain): preserve recall inputs and context metadata - #6338

Merged
t0saki merged 6 commits into
volcengine:mainfrom
ehz0ah:fix/langchain-recall-context
Oct 20, 2026
Merged

t0saki merged 6 commits into
volcengine:mainfrom
ehz0ah:fix/langchain-recall-context

Conversation

@ehz0ah

@ehz0ah ehz0ah commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Description

Preserve the caller's inputs, system messages and source references through LangChain recall and recording:

  • A configured session_id made the default stateless retriever fail SDK option validation. Forward it only to session-aware search, in both sync and async retrieval.
  • Tuple and single-message inputs could skip recall or use an unrelated prompt field. Normalize these supported forms for query extraction and injection. A configured string input also takes precedence over other prompt fields, independent of dictionary order; scalar prompt interpolation is preserved.
  • Injection rebuilt typed SystemMessage objects from flattened text. Copy the message instead, preserving its ID, name, additional fields and structured content blocks while appending recalled context. Caller inputs are not mutated.
  • Custom retriever metadata prefixes lost the recalled reference's type and abstract. Pass the configured prefix to the existing reference builder so these values survive assembly and recording.

Human Involvement

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

Related Issue

Fixes #6172
Fixes #5856
Fixes #6097
Fixes #6035

Consolidates #6174, #5858, #6098 and #6036.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • Keep each correction in the existing retriever, input-normalization or context-reference owner.
  • Move contributed SDK-option coverage into the adapter's existing test suite.
  • Extend public contracts across sync/async calls, completed streams, tuple/dictionary inputs, structured system messages and default/custom metadata prefixes through recording.

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows
python -m pytest -q -rs --noconftest -p no:cacheprovider -o addopts='' \
  integrations/frameworks/langchain/tests tests/unit/test_langchain_package_boundary.py
ruff check integrations/frameworks/langchain/src integrations/frameworks/langchain/tests \
  tests/unit/test_langchain_package_boundary.py
ruff format --check integrations/frameworks/langchain/src integrations/frameworks/langchain/tests \
  tests/unit/test_langchain_package_boundary.py
mypy --config-file integrations/frameworks/langchain/pyproject.toml \
  integrations/frameworks/langchain/src/langchain_openviking
uv build --offline --sdist --wheel integrations/frameworks/langchain --out-dir "$DIST"
python -m twine check "$DIST"/*
  • Python 3.12, LangChain 1.4.6 / core 1.6.12 / LangGraph 1.2.16: 559 passed, 1 skipped.
  • Python 3.10, LangChain / core / LangGraph 1.0.0: 558 passed, 2 skipped.
  • The 80 focused cases produce 48 failures / 32 passes on main d568563f8. All 80 pass here. Four string-input cases also reproduced after the original cherry-picks, before the additional configured-input correction.
  • Ruff, formatting, mypy (15 source modules), wheel/sdist builds and Twine pass. Fresh base/extra installed-wheel smoke and dependency checks pass; all 15 wheel modules match final source. Bundled sdist tests against the installed wheel outside the checkout: 554 passed, 1 skipped.
  • Actual SDK calls over localhost HTTP: 16 cases pass from source and the installed wheel, checking sync/async find/search requests with configured/absent session IDs and default/custom metadata prefixes. Runnable tests use real LangChain execution and deterministic storage/model fixtures; existing streaming, cancellation and tool-capture tests are included in the full suite.

Skips are the optional SQLite checkpointer and, on Python 3.10, asyncio.timeout. Framework deprecation warnings remain. This validates controlled SDK/HTTP and framework behavior, not a deployed backend, external model or authorization policy.

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

Not applicable.

Additional Notes

Original @ktz03 commits were cherry-picked with -x, preserving authorship:

Test consolidation, broader lifecycle coverage and the configured-string-input correction are separate signed-off commits by Hao Zhe. The source PRs remain open until this combined fix lands.

ktz03 and others added 6 commits October 20, 2026 15:58
(cherry picked from commit d8d0237)
Signed-off-by: Hao Zhe <[email protected]>
…le paths

Keep SDK option coverage in the existing adapter suite. Extend public sync and async contracts for configured metadata through recording, tuple and dictionary policy inputs, and completed streams without mutating caller messages.

Signed-off-by: Hao Zhe <[email protected]>
Prefer the configured current-message string over unrelated prompt fields, independent of dictionary order. Extend the public sync, async and streaming host-history contract to expose the original failure.

Signed-off-by: Hao Zhe <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

3 participants