mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-13 21:27:52 +02:00
feat(checkpoint/serde): serialize DiffDelta as 'diff' type tag
Add serde support for DiffDelta by implementing dump/load for the "diff" type tag.
This allows the checkpoint system to efficiently store delta objects by serializing
them as msgpack-encoded dicts with {"d": delta, "p": prev_version} structure.
The implementation uses runtime type checking to avoid circular imports and
leverages the existing msgpack ext hooks for proper deserialization of complex
types like LangChain messages.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.5
parent
4d1f4086eb
commit
9e40dee07f
@@ -983,3 +983,35 @@ def test_msgpack_nested_pydantic_serializes_as_dict(
|
||||
# No blocking should occur - inner is serialized as dict, not ext
|
||||
assert "blocked" not in caplog.text.lower()
|
||||
assert result == obj
|
||||
|
||||
|
||||
def test_diff_delta_serde_round_trip() -> None:
|
||||
from langgraph.checkpoint.base import DiffDelta
|
||||
|
||||
serde = JsonPlusSerializer()
|
||||
prev = "00000000000000000000000000000001.1234567890123456"
|
||||
delta = DiffDelta(
|
||||
delta=[HumanMessage(content="hello", id="msg-1")],
|
||||
prev_version=prev,
|
||||
)
|
||||
type_tag, blob = serde.dumps_typed(delta)
|
||||
assert type_tag == "diff"
|
||||
|
||||
result = serde.loads_typed(("diff", blob))
|
||||
assert isinstance(result, dict)
|
||||
assert result["p"] == prev
|
||||
assert len(result["d"]) == 1
|
||||
assert result["d"][0].content == "hello"
|
||||
|
||||
|
||||
def test_diff_delta_serde_root_blob() -> None:
|
||||
from langgraph.checkpoint.base import DiffDelta
|
||||
|
||||
serde = JsonPlusSerializer()
|
||||
delta = DiffDelta(delta=[], prev_version=None)
|
||||
type_tag, blob = serde.dumps_typed(delta)
|
||||
assert type_tag == "diff"
|
||||
|
||||
result = serde.loads_typed(("diff", blob))
|
||||
assert result["p"] is None
|
||||
assert result["d"] == []
|
||||
|
||||
Reference in New Issue
Block a user