Skip to content

fix(langchain): pass conversation_id as LangGraph thread_id#2074

Open
Rahulreddy1020 wants to merge 2 commits into
NVIDIA:developfrom
Rahulreddy1020:fix/langgraph-thread-id
Open

fix(langchain): pass conversation_id as LangGraph thread_id#2074
Rahulreddy1020 wants to merge 2 commits into
NVIDIA:developfrom
Rahulreddy1020:fix/langgraph-thread-id

Conversation

@Rahulreddy1020

@Rahulreddy1020 Rahulreddy1020 commented Jun 15, 2026

Copy link
Copy Markdown

Description

The langgraph_wrapper invoked the wrapped graph without a RunnableConfig, so any graph compiled with a checkpointer raised:

ValueError: Checkpointer requires one or more of the following 'configurable' keys: thread_id, checkpoint_ns, checkpoint_id

As a result, checkpoint-backed thread memory never worked when a LangGraph agent was served through NAT (per #1994).

This maps NAT's conversation_id to LangGraph's thread_id and passes it to all ainvoke/astream calls, following the existing zep_cloud plugin convention (zep_editor.py uses Context.get().conversation_id as the thread id). When no conversation_id is in context, the config is None, preserving the current behavior for stateless graphs.

Verified empirically against langgraph 1.x:

  • With a checkpointer + thread_id: memory persists across turns and threads are isolated.
  • Without a checkpointer: passing a thread_id is a harmless no-op, so the change is safe for all graphs.

Open questions for maintainers

  1. Should the thread_id be namespaced by user_id (e.g. f"{user_id}:{conversation_id}") for stronger multi-user isolation? I followed the conversation_id-only convention already used by zep_cloud, but happy to change.
  2. When no conversation_id is present, the current behavior (no thread id, no persistence) is preserved. Let me know if a synthesized fallback is preferred.

Closes #1994

By Submitting this PR I confirm:

  • I am familiar with the Contributing Guidelines.
  • We require that all contributors "sign-off" on their commits. This certifies that the contribution is your original work, or you have rights to submit it under the same license, or a compatible license. (Commit is signed off.)
  • When the PR is ready for review, new or existing tests cover these changes. (Added TestBuildRunnableConfig; full file: 19 passed.)
  • When the PR is ready for review, the documentation is up to date with these changes. (No user-facing doc/API change; behavior fix only.)

Summary by CodeRabbit

  • Bug Fixes
    • Improved LangGraph workflow continuity by ensuring invocations use consistent conversation/thread identifiers when available.
  • Tests
    • Added coverage to verify runnable configuration is generated correctly when a conversation ID is present, and omitted when absent.

The langgraph_wrapper invoked the wrapped graph without a RunnableConfig,
so any graph compiled with a checkpointer raised "Checkpointer requires
one or more of the following 'configurable' keys: thread_id, ..." and
checkpoint-backed thread memory never worked when served through NAT.

Map NAT's conversation_id (following the existing zep_cloud plugin
convention) to LangGraph's thread_id and pass it to ainvoke/astream.
When no conversation_id is present, config is None, preserving the prior
behavior for stateless graphs.

Closes NVIDIA#1994

Signed-off-by: Rahul Reddy <Rahulreddy1020@users.noreply.github.com>
@Rahulreddy1020 Rahulreddy1020 requested a review from a team as a code owner June 15, 2026 04:20
@copy-pr-bot

copy-pr-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 091c7c30-2267-4965-876a-3a293635421d

📥 Commits

Reviewing files that changed from the base of the PR and between 7127138 and b7857ce.

📒 Files selected for processing (2)
  • packages/nvidia_nat_langchain/src/nat/plugins/langchain/langgraph_workflow.py
  • packages/nvidia_nat_langchain/tests/test_langgraph_workflow.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/nvidia_nat_langchain/tests/test_langgraph_workflow.py
  • packages/nvidia_nat_langchain/src/nat/plugins/langchain/langgraph_workflow.py

Walkthrough

LanggraphWrapperFunction gains a static _build_runnable_config() helper that reads Context.get().conversation_id and maps it to a LangGraph RunnableConfig with configurable.thread_id, returning None when no conversation ID exists. Both _ainvoke() and _astream() (including the async-context-manager variant) are updated to forward this config. Two unit tests cover the present and absent conversation ID cases.

Changes

Conversation-scoped RunnableConfig for LangGraph

Layer / File(s) Summary
RunnableConfig helper, invocation wiring, and unit tests
packages/nvidia_nat_langchain/src/nat/plugins/langchain/langgraph_workflow.py, packages/nvidia_nat_langchain/tests/test_langgraph_workflow.py
Imports Context and patch for testing, adds static _build_runnable_config() that returns a RunnableConfig with configurable.thread_id set to conversation_id or None when absent, updates all ainvoke/astream call sites to pass the config, and adds TestBuildRunnableConfig tests mocking Context to verify both conversation_id present and absent branches.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the core change: passing conversation_id as LangGraph thread_id to enable checkpoint-backed thread memory in the langgraph wrapper.
Linked Issues check ✅ Passed The PR implementation directly addresses issue #1994 by mapping conversation_id to thread_id via RunnableConfig in ainvoke/astream calls, with backward compatibility for stateless graphs.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the issue: adding _build_runnable_config() helper, updating _ainvoke/_astream calls, and adding comprehensive tests for the new functionality.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@packages/nvidia_nat_langchain/src/nat/plugins/langchain/langgraph_workflow.py`:
- Around line 111-115: The docstrings at two locations contain the reject-list
term "NAT" which violates coding guidelines for documentation vocabulary. In
packages/nvidia_nat_langchain/src/nat/plugins/langchain/langgraph_workflow.py
lines 111-115, reword the _build_runnable_config method's docstring to remove
"NAT's" while maintaining the focus on the conversation_id to thread_id mapping
concept. In packages/nvidia_nat_langchain/tests/test_langgraph_workflow.py line
209, update the test class docstring to remove the reference to "NAT" while
preserving the description of the mapping behavior being tested. Ensure both
locations remain clear and accurate in describing the functionality without
using the reject-list term.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 382b0da7-59ac-4f58-8bd6-b971f05f2394

📥 Commits

Reviewing files that changed from the base of the PR and between 6bacce9 and 7127138.

📒 Files selected for processing (2)
  • packages/nvidia_nat_langchain/src/nat/plugins/langchain/langgraph_workflow.py
  • packages/nvidia_nat_langchain/tests/test_langgraph_workflow.py

Comment thread packages/nvidia_nat_langchain/src/nat/plugins/langchain/langgraph_workflow.py Outdated
Address CodeRabbit review: remove the reject-list term from the
_build_runnable_config and TestBuildRunnableConfig docstrings while
preserving the conversation_id -> thread_id mapping description.

Signed-off-by: Rahul Reddy <Rahulreddy1020@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NAT langgraph_wrapper does not pass LangGraph thread_id, breaking checkpoint-backed thread memory

1 participant