AsyncRedisSaver raises TypeError: Object of type HumanMessage is not JSON serializable during checkpoint writes
Hello!
Environment
- Python: 3.12.3
- langgraph: 1.1.2
- langgraph-checkpoint: 4.0.1
- langgraph-checkpoint-redis: 0.4.0
- redisvl: 0.16.0
- Redis: Redis 8.6.1 Stack (RedisJSON + RediSearch enabled)
Bug Description
When using AsyncRedisSaver as the checkpointer for a graph whose state includes a messages channel with LangChain message objects (HumanMessage, AIMessage), checkpoint writes fail with:
TypeError: Object of type HumanMessage is not JSON serializable
The error originates inside redisvl's storage layer during client.json().set(), meaning the message objects are reaching RedisJSON without being serialized through JsonPlusRedisSerializer first.
Key observations:
- Removing
checkpointer=checkpointer from graph.compile() eliminates the error entirely.
- The same graph works correctly with
InMemorySaver, confirming the graph logic and state shape are valid.
Full Traceback
ERROR:redisvl.index.index:Error while loading data to Redis
Traceback (most recent call last):
File ".../redisvl/index/index.py", line 1833, in load
return await self._storage.awrite(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../redisvl/index/storage.py", line 503, in awrite
await self._aset(pipe, key, obj)
File ".../redisvl/index/storage.py", line 705, in _aset
client.json().set(key, "$", obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../redis/commands/json/commands.py", line 243, in set
pieces = [name, str(path), self._encode(obj)]
^^^^^^^^^^^^^^^^^
File ".../redis/commands/json/__init__.py", line 102, in _encode
return self.__encoder__.encode(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/json/encoder.py", line 200, in encode
chunks = self.iterencode(o, _one_shot=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/json/encoder.py", line 258, in iterencode
return _iterencode(o, 0)
^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/json/encoder.py", line 180, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type HumanMessage is not JSON serializable
Expected Behavior
AsyncRedisSaver should serialize HumanMessage and AIMessage objects in all checkpoint paths (channel values, pending writes, pending sends, and metadata) using JsonPlusRedisSerializer, the same way the first-party AsyncPostgresSaver and InMemorySaver handle them via JsonPlusSerializer.
Thanks for looking into this!
AsyncRedisSaverraisesTypeError: Object of type HumanMessage is not JSON serializableduring checkpoint writesHello!
Environment
Bug Description
When using
AsyncRedisSaveras the checkpointer for a graph whose state includes amessageschannel with LangChain message objects (HumanMessage,AIMessage), checkpoint writes fail with:The error originates inside
redisvl's storage layer duringclient.json().set(), meaning the message objects are reaching RedisJSON without being serialized throughJsonPlusRedisSerializerfirst.Key observations:
checkpointer=checkpointerfromgraph.compile()eliminates the error entirely.InMemorySaver, confirming the graph logic and state shape are valid.Full Traceback
Expected Behavior
AsyncRedisSavershould serializeHumanMessageandAIMessageobjects in all checkpoint paths (channel values, pending writes, pending sends, and metadata) usingJsonPlusRedisSerializer, the same way the first-partyAsyncPostgresSaverandInMemorySaverhandle them viaJsonPlusSerializer.Thanks for looking into this!