Checked other resources
Related Issues / PRs
JsonPlusSerializer already supports Decimal, UUID, datetime, Path, IP addresses, etc.; Fraction and complex are the gap.
Reproduction Steps / Example Code (Python)
from decimal import Decimal
from fractions import Fraction
from langgraph.checkpoint.serde.jsonplus import JsonPlusSerializer
s = JsonPlusSerializer()
s.loads_typed(s.dumps_typed(Decimal("1.5"))) # OK -> Decimal('1.5')
s.loads_typed(s.dumps_typed(Fraction(1, 3))) # TypeError: Type is not msgpack serializable: Fraction
s.loads_typed(s.dumps_typed(complex(1, 2))) # TypeError: Type is not msgpack serializable: complex
Error Message and Stack Trace (if applicable)
TypeError: Type is not msgpack serializable: Fraction
TypeError: Type is not msgpack serializable: complex
Description
JsonPlusSerializer special-cases many stdlib types in _msgpack_default (libs/checkpoint/langgraph/checkpoint/serde/jsonplus.py) — including Decimal — but not fractions.Fraction or the builtin complex. Since neither is natively serializable by ormsgpack, both fall through to default and raise TypeError.
The effect: a graph whose checkpointed state contains a Fraction (exact rational arithmetic) or a complex number (scientific / signal-processing agents) cannot be checkpointed at all — put/aput raises. This is an inconsistency with the already-supported Decimal, and both have an obvious lossless representation.
I'm happy to fix this by adding Fraction and complex handlers to _msgpack_default that mirror the existing Decimal handler (encode via constructor args, reconstruct with the standard constructor), with round-trip tests. Glad to align on the approach first.
System Info
langgraph-checkpoint on main; default JsonPlusSerializer (msgpack path). Python 3.12.
Checked other resources
Related Issues / PRs
JsonPlusSerializeralready supportsDecimal,UUID,datetime,Path, IP addresses, etc.;Fractionandcomplexare the gap.Reproduction Steps / Example Code (Python)
Error Message and Stack Trace (if applicable)
Description
JsonPlusSerializerspecial-cases many stdlib types in_msgpack_default(libs/checkpoint/langgraph/checkpoint/serde/jsonplus.py) — includingDecimal— but notfractions.Fractionor the builtincomplex. Since neither is natively serializable byormsgpack, both fall through todefaultand raiseTypeError.The effect: a graph whose checkpointed state contains a
Fraction(exact rational arithmetic) or acomplexnumber (scientific / signal-processing agents) cannot be checkpointed at all —put/aputraises. This is an inconsistency with the already-supportedDecimal, and both have an obvious lossless representation.I'm happy to fix this by adding
Fractionandcomplexhandlers to_msgpack_defaultthat mirror the existingDecimalhandler (encode via constructor args, reconstruct with the standard constructor), with round-trip tests. Glad to align on the approach first.System Info
langgraph-checkpointonmain; defaultJsonPlusSerializer(msgpack path). Python 3.12.