You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(serializer): add dataclass and set serialization support for langmem objects
- Add support for serializing/deserializing dataclass objects (e.g., RunningSummary)
- Add special handling for sets in nested structures
- Prevent loss of type information when dataclasses are serialized
- Fix AttributeError when langmem SummarizationNode stores context in state
Changes:
- Preprocess dataclass instances to LangChain constructor format before serialization
- Add _reconstruct_from_constructor() to rebuild objects from constructor format
- Handle sets with special __set_items__ marker to preserve contents
- Update _revive_if_needed() to detect when parent reviver returns unchanged dict
Tests:
- Add comprehensive test suite in test_langmem_serialization.py
- Test roundtrip serialization of RunningSummary objects
- Test nested dataclasses in dicts and lists
- All 382 tests passing
Fixes the error in create-react-agent-manage-message-history.ipynb where
RunningSummary objects were being deserialized as dicts instead of proper
objects, causing AttributeError: 'dict' object has no attribute 'summarized_message_ids'
"17:25:17 langgraph.checkpoint.redis INFO Redis client is a standalone client\n"
125
+
]
126
+
},
127
+
{
128
+
"name": "stderr",
129
+
"output_type": "stream",
130
+
"text": [
131
+
"/tmp/ipykernel_253/104821471.py:41: LangGraphDeprecatedSinceV10: create_react_agent has been moved to `langchain.agents`. Please update your import to `from langchain.agents import create_agent`. Deprecated in LangGraph V1.0 to be removed in V2.0.\n",
132
+
" graph = create_react_agent(\n"
133
+
]
134
+
}
135
+
],
111
136
"source": [
112
137
"# First we initialize the model we want to use.\n",
113
138
"from langchain_openai import ChatOpenAI\n",
@@ -164,7 +189,7 @@
164
189
},
165
190
{
166
191
"cell_type": "code",
167
-
"execution_count": null,
192
+
"execution_count": 4,
168
193
"id": "16636975-5f2d-4dc7-ab8e-d0bea0830a28",
169
194
"metadata": {},
170
195
"outputs": [],
@@ -181,11 +206,35 @@
181
206
},
182
207
{
183
208
"cell_type": "code",
184
-
"execution_count": null,
209
+
"execution_count": 5,
185
210
"id": "9ffff6c3-a4f5-47c9-b51d-97caaee85cd6",
186
211
"metadata": {},
187
-
"outputs": [],
188
-
"source": "import uuid\n\nconfig = {\"configurable\": {\"thread_id\": str(uuid.uuid4())}}\ninputs = {\"messages\": [(\"user\", \"what is the weather in SF, CA?\")]}\n\nprint_stream(graph.stream(inputs, config, stream_mode=\"values\"))"
212
+
"outputs": [
213
+
{
214
+
"name": "stdout",
215
+
"output_type": "stream",
216
+
"text": [
217
+
"================================\u001b[1m Human Message \u001b[0m=================================\n",
218
+
"\n",
219
+
"what is the weather in SF, CA?\n",
220
+
"17:25:18 httpx INFO HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
221
+
"==================================\u001b[1m Ai Message \u001b[0m==================================\n",
0 commit comments