feat(langgraph): more robust pydantic + dataclass support for StateGraph#6963
Draft
Sydney Runkle (sydney-runkle) wants to merge 8 commits into1.1from
Draft
feat(langgraph): more robust pydantic + dataclass support for StateGraph#6963Sydney Runkle (sydney-runkle) wants to merge 8 commits into1.1from
StateGraph#6963Sydney Runkle (sydney-runkle) wants to merge 8 commits into1.1from
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
More robust Pydantic support for v2 streaming
When using
stream_version="v2", stream data and invoke results now respect the graph's output/state schema types (Pydantic models, dataclasses, etc.) instead of always returning raw dicts. This makes working with typed state much more natural — no more manualModel(**chunk)calls scattered through your code.Values stream coercion
valuesstream parts coerce data through the graph's output schema mapper, so you get Pydantic models (or dataclasses) back directly:This also works for dataclass-based state schemas. TypedDict state stays as plain dicts (no change needed).
Interrupts on stream parts
valuesstream parts now carry aninterruptsfield directly, removing the need to cross-reference theupdatesstream:Checkpoint/debug coercion
Checkpoint and debug stream payloads also coerce their
valuesthrough the state schema mapper, sostream_mode="checkpoints"andstream_mode="debug"return typed state too.Generic stream types
StreamPart,ValuesStreamPart,CheckpointPayload, etc. are now generic overStateT/OutputT, enabling better static type checking across the board.GraphOutputwrapper (experimental — may not ship)invoke(stream_version="v2")returns aGraphOutput[OutputT]dataclass with.valueand.interruptsfields:The concern: this changes the return type of
invoke()in a way that existing code patterns likeresult["key"]still work (via__getitem__), butisinstance(result, dict)checks would break. Worth discussing whether the ergonomic benefit justifies the migration cost.