dapr-ext-langgraph-dev 1.16.0.dev56__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,203 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2021 The Dapr Authors.
190
+
191
+ and others that have contributed code to the public domain.
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
@@ -0,0 +1,32 @@
1
+ Metadata-Version: 2.4
2
+ Name: dapr-ext-langgraph-dev
3
+ Version: 1.16.0.dev56
4
+ Summary: The developmental release for the Dapr Checkpointer extension for LangGraph
5
+ Home-page: https://dapr.io/
6
+ Author: Dapr Authors
7
+ Author-email: daprweb@microsoft.com
8
+ License: Apache
9
+ Project-URL: Documentation, https://github.com/dapr/docs
10
+ Project-URL: Source, https://github.com/dapr/python-sdk
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Requires-Python: >=3.10
22
+ License-File: LICENSE
23
+ Requires-Dist: dapr>=1.16.1rc1
24
+ Requires-Dist: langgraph>=0.3.6
25
+ Requires-Dist: langchain>=0.1.17
26
+ Requires-Dist: python-ulid>=3.0.0
27
+ Requires-Dist: msgpack-python>=0.4.5
28
+ Dynamic: description
29
+ Dynamic: license-file
30
+ Dynamic: summary
31
+
32
+ This is the developmental release for the Dapr Checkpointer extension for LangGraph
@@ -0,0 +1,22 @@
1
+ dapr-ext-langgraph extension
2
+ =======================
3
+
4
+ |pypi|
5
+
6
+ .. |pypi| image:: https://badge.fury.io/py/dapr-ext-langgraph.svg
7
+ :target: https://pypi.org/project/dapr-ext-langgraph/
8
+
9
+ This is the Dapr Checkpointer extension for LangGraph
10
+
11
+ Installation
12
+ ------------
13
+
14
+ ::
15
+
16
+ pip install dapr-ext-langgraph
17
+
18
+ References
19
+ ----------
20
+
21
+ * `Dapr <https://github.com/dapr/dapr>`_
22
+ * `Dapr Python-SDK <https://github.com/dapr/python-sdk>`_
@@ -0,0 +1,21 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ """
4
+ Copyright 2025 The Dapr Authors
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ """
15
+
16
+ # Import your main classes here
17
+ from dapr.ext.langgraph.dapr_checkpointer import DaprCheckpointer
18
+
19
+ __all__ = [
20
+ 'DaprCheckpointer',
21
+ ]
@@ -0,0 +1,409 @@
1
+ import base64
2
+ import json
3
+ import time
4
+ from typing import Any, Dict, List, Optional, Sequence, Tuple, cast
5
+
6
+ import msgpack
7
+ from langchain_core.messages import AIMessage, HumanMessage, ToolMessage
8
+ from langchain_core.runnables import RunnableConfig
9
+ from ulid import ULID
10
+
11
+ from dapr.clients import DaprClient
12
+ from langgraph.checkpoint.base import (
13
+ WRITES_IDX_MAP,
14
+ BaseCheckpointSaver,
15
+ ChannelVersions,
16
+ Checkpoint,
17
+ CheckpointMetadata,
18
+ CheckpointTuple,
19
+ )
20
+ from langgraph.checkpoint.serde.jsonplus import JsonPlusSerializer
21
+
22
+
23
+ class DaprCheckpointer(BaseCheckpointSaver[Checkpoint]):
24
+ """
25
+ Dapr-backed LangGraph Checkpointer that persists checkpoints to a Dapr state store.
26
+ Compatible with LangGraph >= 0.3.6 and LangChain Core >= 1.0.0.
27
+ """
28
+
29
+ REGISTRY_KEY = 'dapr_checkpoint_registry'
30
+
31
+ def __init__(self, store_name: str, key_prefix: str):
32
+ self.store_name = store_name
33
+ self.key_prefix = key_prefix
34
+ self.serde = JsonPlusSerializer()
35
+ self.client = DaprClient()
36
+ self._key_cache: Dict[str, str] = {}
37
+
38
+ # helper: construct Dapr key for a thread
39
+ def _get_key(self, config: RunnableConfig) -> str:
40
+ thread_id = None
41
+
42
+ if isinstance(config, dict):
43
+ thread_id = config.get('configurable', {}).get('thread_id')
44
+
45
+ if not thread_id:
46
+ thread_id = config.get('thread_id')
47
+
48
+ if not thread_id:
49
+ thread_id = 'default'
50
+
51
+ return f'{self.key_prefix}:{thread_id}'
52
+
53
+ def put(
54
+ self,
55
+ config: RunnableConfig,
56
+ checkpoint: Checkpoint,
57
+ metadata: CheckpointMetadata,
58
+ new_versions: ChannelVersions,
59
+ ) -> RunnableConfig:
60
+ thread_id = config['configurable']['thread_id']
61
+ checkpoint_ns = config['configurable'].get('checkpoint_ns', '')
62
+ config_checkpoint_id = config['configurable'].get('checkpoint_id', '')
63
+ thread_ts = config['configurable'].get('thread_ts', '')
64
+
65
+ checkpoint_id = config_checkpoint_id or thread_ts or checkpoint.get('id', '')
66
+
67
+ parent_checkpoint_id = None
68
+ if (
69
+ checkpoint.get('id')
70
+ and config_checkpoint_id
71
+ and checkpoint.get('id') != config_checkpoint_id
72
+ ):
73
+ parent_checkpoint_id = config_checkpoint_id
74
+ checkpoint_id = checkpoint['id']
75
+
76
+ storage_safe_thread_id = self._safe_id(thread_id)
77
+ storage_safe_checkpoint_ns = self._safe_ns(checkpoint_ns)
78
+ storage_safe_checkpoint_id = self._safe_id(checkpoint_id)
79
+
80
+ copy = checkpoint.copy()
81
+ next_config = {
82
+ 'configurable': {
83
+ 'thread_id': thread_id,
84
+ 'checkpoint_ns': checkpoint_ns,
85
+ 'checkpoint_id': checkpoint_id,
86
+ }
87
+ }
88
+
89
+ checkpoint_ts = None
90
+ if checkpoint_id:
91
+ try:
92
+ ulid_obj = ULID.from_str(checkpoint_id)
93
+ checkpoint_ts = ulid_obj.timestamp
94
+ except Exception:
95
+ checkpoint_ts = time.time() * 1000
96
+
97
+ checkpoint_data = {
98
+ 'thread_id': storage_safe_thread_id,
99
+ 'checkpoint_ns': storage_safe_checkpoint_ns,
100
+ 'checkpoint_id': storage_safe_checkpoint_id,
101
+ 'parent_checkpoint_id': (
102
+ '00000000-0000-0000-0000-000000000000'
103
+ if (parent_checkpoint_id if parent_checkpoint_id else '') == ''
104
+ else parent_checkpoint_id
105
+ ),
106
+ 'checkpoint_ts': checkpoint_ts,
107
+ 'checkpoint': self._dump_checkpoint(copy),
108
+ 'metadata': self._dump_metadata(metadata),
109
+ 'has_writes': False,
110
+ }
111
+
112
+ # Guard case where metadata is None
113
+ metadata = metadata or {}
114
+
115
+ if all(key in metadata for key in ['source', 'step']):
116
+ checkpoint_data['source'] = metadata['source']
117
+ checkpoint_data['step'] = metadata['step']
118
+
119
+ checkpoint_key = self._make_safe_checkpoint_key(
120
+ thread_id=thread_id, checkpoint_ns=checkpoint_ns, checkpoint_id=checkpoint_id
121
+ )
122
+
123
+ _, data = self.serde.dumps_typed(checkpoint_data)
124
+ self.client.save_state(store_name=self.store_name, key=checkpoint_key, value=data)
125
+
126
+ latest_pointer_key = (
127
+ f'checkpoint_latest:{storage_safe_thread_id}:{storage_safe_checkpoint_ns}'
128
+ )
129
+
130
+ self.client.save_state(
131
+ store_name=self.store_name, key=latest_pointer_key, value=checkpoint_key
132
+ )
133
+
134
+ return next_config
135
+
136
+ def put_writes(
137
+ self,
138
+ config: RunnableConfig,
139
+ writes: Sequence[Tuple[str, Any]],
140
+ task_id: str,
141
+ task_path: str = '',
142
+ ) -> None:
143
+ """Store intermediate writes linked to a checkpoint with integrated key registry."""
144
+ thread_id = config['configurable']['thread_id']
145
+ checkpoint_ns = config['configurable'].get('checkpoint_ns', '')
146
+ checkpoint_id = config['configurable'].get('checkpoint_id', '')
147
+ storage_safe_thread_id = (self._safe_id(thread_id),)
148
+ storage_safe_checkpoint_ns = self._safe_ns(checkpoint_ns)
149
+
150
+ writes_objects: List[Dict[str, Any]] = []
151
+ for idx, (channel, value) in enumerate(writes):
152
+ type_, blob = self.serde.dumps_typed(value)
153
+ write_obj: Dict[str, Any] = {
154
+ 'thread_id': storage_safe_thread_id,
155
+ 'checkpoint_ns': storage_safe_checkpoint_ns,
156
+ 'checkpoint_id': self._safe_id(checkpoint_id),
157
+ 'task_id': task_id,
158
+ 'task_path': task_path,
159
+ 'idx': WRITES_IDX_MAP.get(channel, idx),
160
+ 'channel': channel,
161
+ 'type': type_,
162
+ 'blob': self._encode_blob(blob),
163
+ }
164
+ writes_objects.append(write_obj)
165
+
166
+ for write_obj in writes_objects:
167
+ idx_value = write_obj['idx']
168
+ assert isinstance(idx_value, int)
169
+ key = self._make_safe_checkpoint_key(
170
+ thread_id=thread_id, checkpoint_ns=checkpoint_ns, checkpoint_id=checkpoint_id
171
+ )
172
+
173
+ self.client.save_state(store_name=self.store_name, key=key, value=json.dumps(write_obj))
174
+
175
+ checkpoint_key = self._make_safe_checkpoint_key(
176
+ thread_id=thread_id, checkpoint_ns=checkpoint_ns, checkpoint_id=checkpoint_id
177
+ )
178
+
179
+ latest_pointer_key = (
180
+ f'checkpoint_latest:{storage_safe_thread_id}:{storage_safe_checkpoint_ns}'
181
+ )
182
+
183
+ self.client.save_state(
184
+ store_name=self.store_name, key=latest_pointer_key, value=checkpoint_key
185
+ )
186
+
187
+ def list(self, config: RunnableConfig) -> list[CheckpointTuple]:
188
+ reg_resp = self.client.get_state(store_name=self.store_name, key=self.REGISTRY_KEY)
189
+ if not reg_resp.data:
190
+ return []
191
+
192
+ keys = json.loads(reg_resp.data)
193
+ checkpoints: list[CheckpointTuple] = []
194
+
195
+ for key in keys:
196
+ cp_resp = self.client.get_state(store_name=self.store_name, key=key)
197
+ if not cp_resp.data:
198
+ continue
199
+
200
+ wrapper = json.loads(cp_resp.data)
201
+ cp_data = wrapper.get('checkpoint', {})
202
+ metadata = wrapper.get('metadata', {})
203
+ cp = Checkpoint(**cp_data)
204
+
205
+ checkpoints.append(
206
+ CheckpointTuple(
207
+ config=config,
208
+ checkpoint=cp,
209
+ parent_config=None,
210
+ metadata=metadata,
211
+ )
212
+ )
213
+
214
+ return checkpoints
215
+
216
+ def delete_thread(self, config: RunnableConfig) -> None:
217
+ key = self._get_key(config)
218
+
219
+ self.client.delete_state(store_name=self.store_name, key=key)
220
+
221
+ reg_resp = self.client.get_state(store_name=self.store_name, key=self.REGISTRY_KEY)
222
+ if not reg_resp.data:
223
+ return
224
+
225
+ registry = json.loads(reg_resp.data)
226
+
227
+ if key in registry:
228
+ registry.remove(key)
229
+ self.client.save_state(
230
+ store_name=self.store_name,
231
+ key=self.REGISTRY_KEY,
232
+ value=json.dumps(registry),
233
+ )
234
+
235
+ def get_tuple(self, config: RunnableConfig) -> Optional[CheckpointTuple]:
236
+ thread_id = config['configurable']['thread_id']
237
+ checkpoint_ns = config['configurable'].get('checkpoint_ns', '')
238
+
239
+ storage_safe_thread_id = self._safe_id(thread_id)
240
+ storage_safe_checkpoint_ns = self._safe_ns(checkpoint_ns)
241
+
242
+ key = ':'.join(
243
+ [
244
+ 'checkpoint_latest',
245
+ storage_safe_thread_id,
246
+ storage_safe_checkpoint_ns,
247
+ ]
248
+ )
249
+
250
+ # First we extract the latest checkpoint key
251
+ checkpoint_key = self.client.get_state(store_name=self.store_name, key=key)
252
+ if not checkpoint_key.data:
253
+ return None
254
+
255
+ # To then derive the checkpoint data
256
+ checkpoint_data = self.client.get_state(
257
+ store_name=self.store_name,
258
+ # checkpoint_key.data can either be str or bytes
259
+ key=checkpoint_key.data.decode()
260
+ if isinstance(checkpoint_key.data, bytes)
261
+ else checkpoint_key.data,
262
+ )
263
+
264
+ if not checkpoint_data.data:
265
+ return None
266
+
267
+ if isinstance(checkpoint_data.data, bytes):
268
+ unpacked = msgpack.unpackb(checkpoint_data.data)
269
+
270
+ checkpoint_values = unpacked[b'checkpoint']
271
+ channel_values = checkpoint_values[b'channel_values']
272
+
273
+ decoded_messages = []
274
+ for item in channel_values[b'messages']:
275
+ if isinstance(item, msgpack.ExtType):
276
+ decoded_messages.append(
277
+ self._convert_checkpoint_message(
278
+ self._load_metadata(msgpack.unpackb(item.data))
279
+ )
280
+ )
281
+ else:
282
+ decoded_messages.append(item)
283
+
284
+ checkpoint_values[b'channel_values'][b'messages'] = decoded_messages
285
+
286
+ mdata = unpacked.get(b'metadata')
287
+ if isinstance(mdata, bytes):
288
+ mdata = self._load_metadata(msgpack.unpackb(mdata))
289
+
290
+ metadata = {
291
+ k.decode() if isinstance(k, bytes) else k: v.decode() if isinstance(v, bytes) else v
292
+ for k, v in mdata.items()
293
+ }
294
+
295
+ checkpoint_obj = Checkpoint(
296
+ **{
297
+ key.decode() if isinstance(key, bytes) else key: value
298
+ for key, value in checkpoint_values.items()
299
+ }
300
+ )
301
+
302
+ checkpoint = self._decode_bytes(checkpoint_obj)
303
+ elif isinstance(checkpoint_data.data, str):
304
+ unpacked = json.loads(checkpoint_data.data)
305
+ checkpoint = unpacked.get('checkpoint', None)
306
+ metadata = unpacked.get('metadata', None)
307
+
308
+ if not metadata or not checkpoint:
309
+ return None
310
+ else:
311
+ return None
312
+
313
+ return CheckpointTuple(
314
+ config=config,
315
+ checkpoint=checkpoint,
316
+ metadata=metadata,
317
+ parent_config=None,
318
+ pending_writes=[],
319
+ )
320
+
321
+ def _safe_id(self, id) -> str:
322
+ return '00000000-0000-0000-0000-000000000000' if id == '' else id
323
+
324
+ def _safe_ns(self, ns) -> str:
325
+ return '__empty__' if ns == '' else ns
326
+
327
+ def _convert_checkpoint_message(self, msg_item):
328
+ _, _, data_dict, _ = msg_item
329
+ data_dict = self._decode_bytes(data_dict)
330
+
331
+ msg_type = data_dict.get('type')
332
+
333
+ if msg_type == 'human':
334
+ return HumanMessage(**data_dict)
335
+ elif msg_type == 'ai':
336
+ return AIMessage(**data_dict)
337
+ elif msg_type == 'tool':
338
+ return ToolMessage(**data_dict)
339
+ else:
340
+ raise ValueError(f'Unknown message type: {msg_type}')
341
+
342
+ def _decode_bytes(self, obj):
343
+ if isinstance(obj, bytes):
344
+ try:
345
+ s = obj.decode()
346
+ # Convert to int if it's a number, the unpacked channel_version holds \xa1 which unpacks as strings
347
+ # LangGraph needs Ints for '>' comparison
348
+ if s.isdigit():
349
+ return int(s)
350
+ return s
351
+ except Exception:
352
+ return obj
353
+ if isinstance(obj, dict):
354
+ return {self._decode_bytes(k): self._decode_bytes(v) for k, v in obj.items()}
355
+ if isinstance(obj, list):
356
+ return [self._decode_bytes(v) for v in obj]
357
+ if isinstance(obj, tuple):
358
+ return tuple(self._decode_bytes(v) for v in obj)
359
+ return obj
360
+
361
+ def _encode_blob(self, blob: Any) -> str:
362
+ if isinstance(blob, bytes):
363
+ return base64.b64encode(blob).decode()
364
+ return blob
365
+
366
+ def _dump_checkpoint(self, checkpoint: Checkpoint) -> dict[str, Any]:
367
+ type_, data = self.serde.dumps_typed(checkpoint)
368
+
369
+ if type_ == 'json':
370
+ checkpoint_data = cast(dict, json.loads(data))
371
+ else:
372
+ checkpoint_data = cast(dict, self.serde.loads_typed((type_, data)))
373
+
374
+ if 'channel_values' in checkpoint_data:
375
+ for key, value in checkpoint_data['channel_values'].items():
376
+ if isinstance(value, bytes):
377
+ checkpoint_data['channel_values'][key] = {
378
+ '__bytes__': self._encode_blob(value)
379
+ }
380
+
381
+ if 'channel_versions' in checkpoint_data:
382
+ checkpoint_data['channel_versions'] = {
383
+ k: str(v) for k, v in checkpoint_data['channel_versions'].items()
384
+ }
385
+
386
+ return {'type': type_, **checkpoint_data, 'pending_sends': []}
387
+
388
+ def _load_metadata(self, metadata: dict[str, Any]) -> CheckpointMetadata:
389
+ type_str, data_bytes = self.serde.dumps_typed(metadata)
390
+ return self.serde.loads_typed((type_str, data_bytes))
391
+
392
+ def _dump_metadata(self, metadata: CheckpointMetadata) -> str:
393
+ _, serialized_bytes = self.serde.dumps_typed(metadata)
394
+ return serialized_bytes
395
+
396
+ def _make_safe_checkpoint_key(
397
+ self,
398
+ thread_id: str,
399
+ checkpoint_ns: str,
400
+ checkpoint_id: str,
401
+ ) -> str:
402
+ return ':'.join(
403
+ [
404
+ 'checkpoint',
405
+ thread_id,
406
+ checkpoint_ns,
407
+ checkpoint_id,
408
+ ]
409
+ )
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ """
4
+ Copyright 2025 The Dapr Authors
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ """
15
+
16
+ __version__ = '1.16.0.dev'
@@ -0,0 +1,32 @@
1
+ Metadata-Version: 2.4
2
+ Name: dapr-ext-langgraph-dev
3
+ Version: 1.16.0.dev56
4
+ Summary: The developmental release for the Dapr Checkpointer extension for LangGraph
5
+ Home-page: https://dapr.io/
6
+ Author: Dapr Authors
7
+ Author-email: daprweb@microsoft.com
8
+ License: Apache
9
+ Project-URL: Documentation, https://github.com/dapr/docs
10
+ Project-URL: Source, https://github.com/dapr/python-sdk
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Requires-Python: >=3.10
22
+ License-File: LICENSE
23
+ Requires-Dist: dapr>=1.16.1rc1
24
+ Requires-Dist: langgraph>=0.3.6
25
+ Requires-Dist: langchain>=0.1.17
26
+ Requires-Dist: python-ulid>=3.0.0
27
+ Requires-Dist: msgpack-python>=0.4.5
28
+ Dynamic: description
29
+ Dynamic: license-file
30
+ Dynamic: summary
31
+
32
+ This is the developmental release for the Dapr Checkpointer extension for LangGraph
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ README.rst
3
+ setup.cfg
4
+ setup.py
5
+ dapr/ext/langgraph/__init__.py
6
+ dapr/ext/langgraph/dapr_checkpointer.py
7
+ dapr/ext/langgraph/py.typed
8
+ dapr/ext/langgraph/version.py
9
+ dapr_ext_langgraph_dev.egg-info/PKG-INFO
10
+ dapr_ext_langgraph_dev.egg-info/SOURCES.txt
11
+ dapr_ext_langgraph_dev.egg-info/dependency_links.txt
12
+ dapr_ext_langgraph_dev.egg-info/requires.txt
13
+ dapr_ext_langgraph_dev.egg-info/top_level.txt
14
+ tests/test_checkpointer.py
@@ -0,0 +1,5 @@
1
+ dapr>=1.16.1rc1
2
+ langgraph>=0.3.6
3
+ langchain>=0.1.17
4
+ python-ulid>=3.0.0
5
+ msgpack-python>=0.4.5
@@ -0,0 +1,46 @@
1
+ [metadata]
2
+ url = https://dapr.io/
3
+ author = Dapr Authors
4
+ author_email = daprweb@microsoft.com
5
+ license = Apache
6
+ license_file = LICENSE
7
+ classifiers =
8
+ Development Status :: 5 - Production/Stable
9
+ Intended Audience :: Developers
10
+ License :: OSI Approved :: Apache Software License
11
+ Operating System :: OS Independent
12
+ Programming Language :: Python
13
+ Programming Language :: Python :: 3.10
14
+ Programming Language :: Python :: 3.11
15
+ Programming Language :: Python :: 3.12
16
+ Programming Language :: Python :: 3.13
17
+ Programming Language :: Python :: 3.14
18
+ project_urls =
19
+ Documentation = https://github.com/dapr/docs
20
+ Source = https://github.com/dapr/python-sdk
21
+
22
+ [options]
23
+ python_requires = >=3.10
24
+ packages = find_namespace:
25
+ include_package_data = True
26
+ install_requires =
27
+ dapr >= 1.16.1rc1
28
+ langgraph >= 0.3.6
29
+ langchain >= 0.1.17
30
+ python-ulid >= 3.0.0
31
+ msgpack-python >= 0.4.5
32
+
33
+ [options.packages.find]
34
+ include =
35
+ dapr.*
36
+ exclude =
37
+ tests
38
+
39
+ [options.package_data]
40
+ dapr.ext.langgraph =
41
+ py.typed
42
+
43
+ [egg_info]
44
+ tag_build =
45
+ tag_date = 0
46
+
@@ -0,0 +1,66 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ """
4
+ Copyright 2025 The Dapr Authors
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ """
15
+
16
+ import os
17
+
18
+ from setuptools import setup
19
+
20
+ # Load version in dapr package.
21
+ version_info = {}
22
+ with open('dapr/ext/langgraph/version.py') as fp:
23
+ exec(fp.read(), version_info)
24
+ __version__ = version_info['__version__']
25
+
26
+
27
+ def is_release():
28
+ return '.dev' not in __version__
29
+
30
+
31
+ name = 'dapr-ext-langgraph'
32
+ version = __version__
33
+ description = 'The official release of Dapr Python SDK LangGraph Extension.'
34
+ long_description = """
35
+ This is the Dapr Checkpointer extension for LangGraph.
36
+
37
+ Dapr is a portable, serverless, event-driven runtime that makes it easy for developers to
38
+ build resilient, stateless and stateful microservices that run on the cloud and edge and
39
+ embraces the diversity of languages and developer frameworks.
40
+
41
+ Dapr codifies the best practices for building microservice applications into open,
42
+ independent, building blocks that enable you to build portable applications with the language
43
+ and framework of your choice. Each building block is independent and you can use one, some,
44
+ or all of them in your application.
45
+ """.lstrip()
46
+
47
+ # Get build number from GITHUB_RUN_NUMBER environment variable
48
+ build_number = os.environ.get('GITHUB_RUN_NUMBER', '0')
49
+
50
+ if not is_release():
51
+ name += '-dev'
52
+ version = f'{__version__}{build_number}'
53
+ description = 'The developmental release for the Dapr Checkpointer extension for LangGraph'
54
+ long_description = (
55
+ 'This is the developmental release for the Dapr Checkpointer extension for LangGraph'
56
+ )
57
+
58
+ print(f'package name: {name}, version: {version}', flush=True)
59
+
60
+
61
+ setup(
62
+ name=name,
63
+ version=version,
64
+ description=description,
65
+ long_description=long_description,
66
+ )
@@ -0,0 +1,175 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ import base64
4
+ import json
5
+ import unittest
6
+ from datetime import datetime
7
+ from unittest import mock
8
+
9
+ import msgpack
10
+ from dapr.ext.langgraph.dapr_checkpointer import DaprCheckpointer
11
+ from langgraph.checkpoint.base import Checkpoint
12
+
13
+
14
+ @mock.patch('dapr.ext.langgraph.dapr_checkpointer.DaprClient')
15
+ class DaprCheckpointerTest(unittest.TestCase):
16
+ def setUp(self):
17
+ self.store = 'statestore'
18
+ self.prefix = 'lg'
19
+ self.config = {'configurable': {'thread_id': 't1'}}
20
+
21
+ self.checkpoint = Checkpoint(
22
+ v=1,
23
+ id='cp1',
24
+ ts=datetime.now().timestamp(),
25
+ channel_values={'a': 1},
26
+ channel_versions={},
27
+ versions_seen={},
28
+ )
29
+
30
+ def test_get_tuple_returns_checkpoint(self, mock_client_cls):
31
+ mock_client = mock_client_cls.return_value
32
+
33
+ wrapper = {
34
+ 'checkpoint': {
35
+ 'v': self.checkpoint['v'],
36
+ 'id': self.checkpoint['id'],
37
+ 'ts': self.checkpoint['ts'],
38
+ 'channel_values': self.checkpoint['channel_values'],
39
+ 'channel_versions': self.checkpoint['channel_versions'],
40
+ 'versions_seen': self.checkpoint['versions_seen'],
41
+ },
42
+ 'metadata': {'step': 3},
43
+ }
44
+ mock_client.get_state.return_value.data = json.dumps(wrapper)
45
+
46
+ cp = DaprCheckpointer(self.store, self.prefix)
47
+ tup = cp.get_tuple(self.config)
48
+
49
+ assert tup is not None
50
+ assert tup.checkpoint['id'] == 'cp1'
51
+ assert tup.metadata['step'] == 3
52
+
53
+ def test_get_tuple_none_when_missing(self, mock_client_cls):
54
+ mock_client = mock_client_cls.return_value
55
+ mock_client.get_state.return_value.data = None
56
+
57
+ cp = DaprCheckpointer(self.store, self.prefix)
58
+ assert cp.get_tuple(self.config) is None
59
+
60
+ def test_put_saves_checkpoint_and_registry(self, mock_client_cls):
61
+ mock_client = mock_client_cls.return_value
62
+
63
+ mock_client.get_state.return_value.data = json.dumps([])
64
+
65
+ cp = DaprCheckpointer(self.store, self.prefix)
66
+ cp.put(self.config, self.checkpoint, {'step': 10}, None)
67
+
68
+ first_call = mock_client.save_state.call_args_list[0]
69
+ first_call_kwargs = first_call.kwargs
70
+ assert first_call_kwargs['store_name'] == 'statestore'
71
+ assert first_call_kwargs['key'] == 'checkpoint:t1::cp1'
72
+ unpacked = msgpack.unpackb(first_call_kwargs['value']) # We're packing bytes
73
+ saved_payload = {}
74
+ for k, v in unpacked.items():
75
+ k = k.decode() if isinstance(k, bytes) else k
76
+ if (
77
+ k == 'checkpoint' or k == 'metadata'
78
+ ): # Need to convert b'' on checkpoint/metadata dict key/values
79
+ if k == 'metadata':
80
+ v = msgpack.unpackb(v) # Metadata value is packed
81
+ val = {}
82
+ for sk, sv in v.items():
83
+ sk = sk.decode() if isinstance(sk, bytes) else sk
84
+ sv = sv.decode() if isinstance(sv, bytes) else sv
85
+ val[sk] = sv
86
+ else:
87
+ val = v.decode() if isinstance(v, bytes) else v
88
+ saved_payload[k] = val
89
+ assert saved_payload['metadata']['step'] == 10
90
+
91
+ second_call = mock_client.save_state.call_args_list[1]
92
+ second_call_kwargs = second_call.kwargs
93
+ assert second_call_kwargs['store_name'] == 'statestore'
94
+ assert (
95
+ second_call_kwargs['value'] == 'checkpoint:t1::cp1'
96
+ ) # Here we're testing if the last checkpoint is the first_call above
97
+
98
+ def test_put_writes_updates_channel_values(self, mock_client_cls):
99
+ mock_client = mock_client_cls.return_value
100
+
101
+ wrapper = {
102
+ 'checkpoint': {
103
+ 'v': 1,
104
+ 'id': 'cp1',
105
+ 'ts': 1000,
106
+ 'channel_values': {'a': 10},
107
+ 'channel_versions': {},
108
+ 'versions_seen': {},
109
+ },
110
+ 'metadata': {},
111
+ }
112
+ mock_client.get_state.return_value.data = json.dumps(wrapper)
113
+
114
+ cp = DaprCheckpointer(self.store, self.prefix)
115
+ cp.put_writes(self.config, writes=[('a', 99)], task_id='task1')
116
+
117
+ # save_state is called with updated checkpoint
118
+ call = mock_client.save_state.call_args_list[0]
119
+ # As we're using named input params we've got to fetch through kwargs
120
+ kwargs = call.kwargs
121
+ saved = json.loads(kwargs['value'])
122
+ # As the value obj is base64 encoded in 'blob' we got to unpack it
123
+ assert msgpack.unpackb(base64.b64decode(saved['blob'])) == 99
124
+
125
+ def test_list_returns_all_checkpoints(self, mock_client_cls):
126
+ mock_client = mock_client_cls.return_value
127
+
128
+ registry = ['lg:t1']
129
+ cp_wrapper = {
130
+ 'checkpoint': {
131
+ 'v': 1,
132
+ 'id': 'cp1',
133
+ 'ts': 1000,
134
+ 'channel_values': {'x': 1},
135
+ 'channel_versions': {},
136
+ 'versions_seen': {},
137
+ },
138
+ 'metadata': {'step': 5},
139
+ }
140
+
141
+ mock_client.get_state.side_effect = [
142
+ mock.Mock(data=json.dumps(registry)),
143
+ mock.Mock(data=json.dumps(cp_wrapper)),
144
+ ]
145
+
146
+ cp = DaprCheckpointer(self.store, self.prefix)
147
+ lst = cp.list(self.config)
148
+
149
+ assert len(lst) == 1
150
+ assert lst[0].checkpoint['id'] == 'cp1'
151
+ assert lst[0].metadata['step'] == 5
152
+
153
+ def test_delete_thread_removes_key_and_updates_registry(self, mock_client_cls):
154
+ mock_client = mock_client_cls.return_value
155
+
156
+ registry = ['lg:t1']
157
+ mock_client.get_state.return_value.data = json.dumps(registry)
158
+
159
+ cp = DaprCheckpointer(self.store, self.prefix)
160
+ cp.delete_thread(self.config)
161
+
162
+ mock_client.delete_state.assert_called_once_with(
163
+ store_name='statestore',
164
+ key='lg:t1',
165
+ )
166
+
167
+ mock_client.save_state.assert_called_with(
168
+ store_name='statestore',
169
+ key=DaprCheckpointer.REGISTRY_KEY,
170
+ value=json.dumps([]),
171
+ )
172
+
173
+
174
+ if __name__ == '__main__':
175
+ unittest.main()