feat(langchain): add context_schema
support to init_chat_model
#33040
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add support for configuring init_chat_model through context_schema,
aligning with LangGraph v0.6+ recommendations for static runtime context.
Fixes #32954
Description: Add support for configuring
init_chat_model
throughcontext_schema
, aligning with LangGraph v0.6+ recommendations for static runtime context. This addresses the configuration inconsistency where model parameters had to be passed viaconfig["configurable"]
while other static runtime context usedcontext_schema
, making project configuration management more complex.The implementation adds a
context_schema
parameter toinit_chat_model
that allows model parameters (model, temperature, max_tokens, etc.) to be passed via runtime context instead of the configurable pattern. This enables unified configuration management whereall static runtime context can be managed consistently in one place.
Key Changes:
context_schema
parameter toinit_chat_model
function signature_ConfigurableModel
class to extract parameters from runtime context in addition to configurable fieldsconfigurable
approachIssue: Fixes #32954
Dependencies: None - this change uses existing dependencies and maintains backward compatibility
This PR description:
init_chat_model
viacontext_schema
#32954")