dapr-ext-langgraph-dev 1.16.0.dev49__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,30 @@
1
+ Metadata-Version: 2.4
2
+ Name: dapr-ext-langgraph-dev
3
+ Version: 1.16.0.dev49
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
+ Dynamic: description
27
+ Dynamic: license-file
28
+ Dynamic: summary
29
+
30
+ 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,164 @@
1
+ import json
2
+ from typing import Any, Sequence, Tuple
3
+
4
+ from langchain_core.load import dumps
5
+ from langchain_core.runnables import RunnableConfig
6
+
7
+ from dapr.clients import DaprClient
8
+ from langgraph.checkpoint.base import BaseCheckpointSaver, Checkpoint, CheckpointTuple
9
+
10
+
11
+ class DaprCheckpointer(BaseCheckpointSaver[Checkpoint]):
12
+ """
13
+ Dapr-backed LangGraph Checkpointer that persists checkpoints to a Dapr state store.
14
+ Compatible with LangGraph >= 0.3.6 and LangChain Core >= 1.0.0.
15
+ """
16
+
17
+ REGISTRY_KEY = 'dapr_checkpoint_registry'
18
+
19
+ def __init__(self, store_name: str, key_prefix: str):
20
+ self.store_name = store_name
21
+ self.key_prefix = key_prefix
22
+ self.client = DaprClient()
23
+
24
+ # helper: construct Dapr key for a thread
25
+ def _get_key(self, config: RunnableConfig) -> str:
26
+ thread_id = None
27
+
28
+ if isinstance(config, dict):
29
+ thread_id = config.get('configurable', {}).get('thread_id')
30
+
31
+ if not thread_id:
32
+ thread_id = config.get('thread_id')
33
+
34
+ if not thread_id:
35
+ thread_id = 'default'
36
+
37
+ return f'{self.key_prefix}:{thread_id}'
38
+
39
+ # restore a checkpoint
40
+ def get_tuple(self, config: RunnableConfig) -> CheckpointTuple | None:
41
+ key = self._get_key(config)
42
+
43
+ resp = self.client.get_state(store_name=self.store_name, key=key)
44
+ if not resp.data:
45
+ return None
46
+
47
+ wrapper = json.loads(resp.data)
48
+ cp_data = wrapper.get('checkpoint', wrapper)
49
+ metadata = wrapper.get('metadata', {'step': 0})
50
+ if 'step' not in metadata:
51
+ metadata['step'] = 0
52
+
53
+ cp = Checkpoint(**cp_data)
54
+ return CheckpointTuple(
55
+ config=config,
56
+ checkpoint=cp,
57
+ parent_config=None,
58
+ metadata=metadata,
59
+ )
60
+
61
+ # save a full checkpoint snapshot
62
+ def put(
63
+ self,
64
+ config: RunnableConfig,
65
+ checkpoint: Checkpoint,
66
+ parent_config: RunnableConfig | None,
67
+ metadata: dict[str, Any],
68
+ ) -> None:
69
+ key = self._get_key(config)
70
+
71
+ checkpoint_serializable = {
72
+ 'v': checkpoint['v'],
73
+ 'id': checkpoint['id'],
74
+ 'ts': checkpoint['ts'],
75
+ 'channel_values': checkpoint['channel_values'],
76
+ 'channel_versions': checkpoint['channel_versions'],
77
+ 'versions_seen': checkpoint['versions_seen'],
78
+ }
79
+
80
+ wrapper = {'checkpoint': checkpoint_serializable, 'metadata': metadata}
81
+
82
+ self.client.save_state(self.store_name, key, dumps(wrapper))
83
+
84
+ reg_resp = self.client.get_state(store_name=self.store_name, key=self.REGISTRY_KEY)
85
+ registry = json.loads(reg_resp.data) if reg_resp.data else []
86
+
87
+ if key not in registry:
88
+ registry.append(key)
89
+ self.client.save_state(self.store_name, self.REGISTRY_KEY, json.dumps(registry))
90
+
91
+ # incremental persistence (for streamed runs)
92
+ def put_writes(
93
+ self,
94
+ config: RunnableConfig,
95
+ writes: Sequence[Tuple[str, Any]],
96
+ task_id: str,
97
+ task_path: str = '',
98
+ ) -> None:
99
+ _ = task_id, task_path
100
+
101
+ key = self._get_key(config)
102
+
103
+ resp = self.client.get_state(store_name=self.store_name, key=key)
104
+ if not resp.data:
105
+ return
106
+
107
+ wrapper = json.loads(resp.data)
108
+ cp = wrapper.get('checkpoint', {})
109
+
110
+ for field, value in writes:
111
+ cp['channel_values'][field] = value
112
+
113
+ wrapper['checkpoint'] = cp
114
+ self.client.save_state(self.store_name, key, json.dumps(wrapper))
115
+
116
+ # enumerate all saved checkpoints
117
+ def list(self, config: RunnableConfig) -> list[CheckpointTuple]:
118
+ reg_resp = self.client.get_state(store_name=self.store_name, key=self.REGISTRY_KEY)
119
+ if not reg_resp.data:
120
+ return []
121
+
122
+ keys = json.loads(reg_resp.data)
123
+ checkpoints: list[CheckpointTuple] = []
124
+
125
+ for key in keys:
126
+ cp_resp = self.client.get_state(store_name=self.store_name, key=key)
127
+ if not cp_resp.data:
128
+ continue
129
+
130
+ wrapper = json.loads(cp_resp.data)
131
+ cp_data = wrapper.get('checkpoint', {})
132
+ metadata = wrapper.get('metadata', {})
133
+ cp = Checkpoint(**cp_data)
134
+
135
+ checkpoints.append(
136
+ CheckpointTuple(
137
+ config=config,
138
+ checkpoint=cp,
139
+ parent_config=None,
140
+ metadata=metadata,
141
+ )
142
+ )
143
+
144
+ return checkpoints
145
+
146
+ # remove a checkpoint and update the registry
147
+ def delete_thread(self, config: RunnableConfig) -> None:
148
+ key = self._get_key(config)
149
+
150
+ self.client.delete_state(store_name=self.store_name, key=key)
151
+
152
+ reg_resp = self.client.get_state(store_name=self.store_name, key=self.REGISTRY_KEY)
153
+ if not reg_resp.data:
154
+ return
155
+
156
+ registry = json.loads(reg_resp.data)
157
+
158
+ if key in registry:
159
+ registry.remove(key)
160
+ self.client.save_state(
161
+ store_name=self.store_name,
162
+ key=self.REGISTRY_KEY,
163
+ value=json.dumps(registry),
164
+ )
@@ -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,30 @@
1
+ Metadata-Version: 2.4
2
+ Name: dapr-ext-langgraph-dev
3
+ Version: 1.16.0.dev49
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
+ Dynamic: description
27
+ Dynamic: license-file
28
+ Dynamic: summary
29
+
30
+ This is the developmental release for the Dapr Checkpointer extension for LangGraph
@@ -0,0 +1,13 @@
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/version.py
8
+ dapr_ext_langgraph_dev.egg-info/PKG-INFO
9
+ dapr_ext_langgraph_dev.egg-info/SOURCES.txt
10
+ dapr_ext_langgraph_dev.egg-info/dependency_links.txt
11
+ dapr_ext_langgraph_dev.egg-info/requires.txt
12
+ dapr_ext_langgraph_dev.egg-info/top_level.txt
13
+ tests/test_checkpointer.py
@@ -0,0 +1,3 @@
1
+ dapr>=1.16.1rc1
2
+ langgraph>=0.3.6
3
+ langchain>=0.1.17
@@ -0,0 +1,40 @@
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
+
31
+ [options.packages.find]
32
+ include =
33
+ dapr.*
34
+ exclude =
35
+ tests
36
+
37
+ [egg_info]
38
+ tag_build =
39
+ tag_date = 0
40
+
@@ -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,150 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ import json
4
+ import unittest
5
+ from datetime import datetime
6
+ from unittest import mock
7
+
8
+ from dapr.ext.langgraph.dapr_checkpointer import DaprCheckpointer
9
+ from langgraph.checkpoint.base import Checkpoint
10
+
11
+
12
+ @mock.patch('dapr.ext.langgraph.dapr_checkpointer.DaprClient')
13
+ class DaprCheckpointerTest(unittest.TestCase):
14
+ def setUp(self):
15
+ self.store = 'statestore'
16
+ self.prefix = 'lg'
17
+ self.config = {'configurable': {'thread_id': 't1'}}
18
+
19
+ self.checkpoint = Checkpoint(
20
+ v=1,
21
+ id='cp1',
22
+ ts=datetime.now().timestamp(),
23
+ channel_values={'a': 1},
24
+ channel_versions={},
25
+ versions_seen={},
26
+ )
27
+
28
+ def test_get_tuple_returns_checkpoint(self, mock_client_cls):
29
+ mock_client = mock_client_cls.return_value
30
+
31
+ wrapper = {
32
+ 'checkpoint': {
33
+ 'v': self.checkpoint['v'],
34
+ 'id': self.checkpoint['id'],
35
+ 'ts': self.checkpoint['ts'],
36
+ 'channel_values': self.checkpoint['channel_values'],
37
+ 'channel_versions': self.checkpoint['channel_versions'],
38
+ 'versions_seen': self.checkpoint['versions_seen'],
39
+ },
40
+ 'metadata': {'step': 3},
41
+ }
42
+ mock_client.get_state.return_value.data = json.dumps(wrapper)
43
+
44
+ cp = DaprCheckpointer(self.store, self.prefix)
45
+ tup = cp.get_tuple(self.config)
46
+
47
+ assert tup is not None
48
+ assert tup.checkpoint['id'] == 'cp1'
49
+ assert tup.metadata['step'] == 3
50
+
51
+ def test_get_tuple_none_when_missing(self, mock_client_cls):
52
+ mock_client = mock_client_cls.return_value
53
+ mock_client.get_state.return_value.data = None
54
+
55
+ cp = DaprCheckpointer(self.store, self.prefix)
56
+ assert cp.get_tuple(self.config) is None
57
+
58
+ def test_put_saves_checkpoint_and_registry(self, mock_client_cls):
59
+ mock_client = mock_client_cls.return_value
60
+
61
+ mock_client.get_state.return_value.data = json.dumps([])
62
+
63
+ cp = DaprCheckpointer(self.store, self.prefix)
64
+ cp.put(self.config, self.checkpoint, None, {'step': 10})
65
+
66
+ first_call = mock_client.save_state.call_args_list[0][0]
67
+ assert first_call[0] == 'statestore'
68
+ assert first_call[1] == 'lg:t1'
69
+ saved_payload = json.loads(first_call[2])
70
+ assert saved_payload['metadata']['step'] == 10
71
+
72
+ second_call = mock_client.save_state.call_args_list[1][0]
73
+ assert second_call[0] == 'statestore'
74
+ assert second_call[1] == DaprCheckpointer.REGISTRY_KEY
75
+
76
+ def test_put_writes_updates_channel_values(self, mock_client_cls):
77
+ mock_client = mock_client_cls.return_value
78
+
79
+ wrapper = {
80
+ 'checkpoint': {
81
+ 'v': 1,
82
+ 'id': 'cp1',
83
+ 'ts': 1000,
84
+ 'channel_values': {'a': 10},
85
+ 'channel_versions': {},
86
+ 'versions_seen': {},
87
+ },
88
+ 'metadata': {},
89
+ }
90
+ mock_client.get_state.return_value.data = json.dumps(wrapper)
91
+
92
+ cp = DaprCheckpointer(self.store, self.prefix)
93
+ cp.put_writes(self.config, writes=[('a', 99)], task_id='task1')
94
+
95
+ # save_state is called with updated checkpoint
96
+ call = mock_client.save_state.call_args[0]
97
+ saved = json.loads(call[2])
98
+ assert saved['checkpoint']['channel_values']['a'] == 99
99
+
100
+ def test_list_returns_all_checkpoints(self, mock_client_cls):
101
+ mock_client = mock_client_cls.return_value
102
+
103
+ registry = ['lg:t1']
104
+ cp_wrapper = {
105
+ 'checkpoint': {
106
+ 'v': 1,
107
+ 'id': 'cp1',
108
+ 'ts': 1000,
109
+ 'channel_values': {'x': 1},
110
+ 'channel_versions': {},
111
+ 'versions_seen': {},
112
+ },
113
+ 'metadata': {'step': 5},
114
+ }
115
+
116
+ mock_client.get_state.side_effect = [
117
+ mock.Mock(data=json.dumps(registry)),
118
+ mock.Mock(data=json.dumps(cp_wrapper)),
119
+ ]
120
+
121
+ cp = DaprCheckpointer(self.store, self.prefix)
122
+ lst = cp.list(self.config)
123
+
124
+ assert len(lst) == 1
125
+ assert lst[0].checkpoint['id'] == 'cp1'
126
+ assert lst[0].metadata['step'] == 5
127
+
128
+ def test_delete_thread_removes_key_and_updates_registry(self, mock_client_cls):
129
+ mock_client = mock_client_cls.return_value
130
+
131
+ registry = ['lg:t1']
132
+ mock_client.get_state.return_value.data = json.dumps(registry)
133
+
134
+ cp = DaprCheckpointer(self.store, self.prefix)
135
+ cp.delete_thread(self.config)
136
+
137
+ mock_client.delete_state.assert_called_once_with(
138
+ store_name='statestore',
139
+ key='lg:t1',
140
+ )
141
+
142
+ mock_client.save_state.assert_called_with(
143
+ store_name='statestore',
144
+ key=DaprCheckpointer.REGISTRY_KEY,
145
+ value=json.dumps([]),
146
+ )
147
+
148
+
149
+ if __name__ == '__main__':
150
+ unittest.main()