rein-graph 0.1.0__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.
- rein_graph-0.1.0/.github/workflows/test.yml +23 -0
- rein_graph-0.1.0/.gitignore +16 -0
- rein_graph-0.1.0/.pre-commit-config.yaml +15 -0
- rein_graph-0.1.0/CHANGELOG.md +16 -0
- rein_graph-0.1.0/LICENSE +201 -0
- rein_graph-0.1.0/PKG-INFO +61 -0
- rein_graph-0.1.0/README.md +32 -0
- rein_graph-0.1.0/examples/fanout.py +45 -0
- rein_graph-0.1.0/examples/hitl.py +40 -0
- rein_graph-0.1.0/examples/sequential.py +42 -0
- rein_graph-0.1.0/pyproject.toml +76 -0
- rein_graph-0.1.0/src/reingraph/__init__.py +71 -0
- rein_graph-0.1.0/src/reingraph/compiled.py +116 -0
- rein_graph-0.1.0/src/reingraph/config.py +24 -0
- rein_graph-0.1.0/src/reingraph/edges.py +42 -0
- rein_graph-0.1.0/src/reingraph/engine.py +243 -0
- rein_graph-0.1.0/src/reingraph/graph.py +109 -0
- rein_graph-0.1.0/src/reingraph/nodes.py +162 -0
- rein_graph-0.1.0/src/reingraph/py.typed +1 -0
- rein_graph-0.1.0/src/reingraph/result.py +39 -0
- rein_graph-0.1.0/src/reingraph/session.py +55 -0
- rein_graph-0.1.0/src/reingraph/state.py +118 -0
- rein_graph-0.1.0/src/reingraph/store.py +55 -0
- rein_graph-0.1.0/src/reingraph/stream.py +31 -0
- rein_graph-0.1.0/src/reingraph/viz.py +35 -0
- rein_graph-0.1.0/tests/test_checkpoint.py +57 -0
- rein_graph-0.1.0/tests/test_conditional.py +90 -0
- rein_graph-0.1.0/tests/test_engine_sequential.py +64 -0
- rein_graph-0.1.0/tests/test_graph_build.py +60 -0
- rein_graph-0.1.0/tests/test_hitl.py +65 -0
- rein_graph-0.1.0/tests/test_nodes.py +83 -0
- rein_graph-0.1.0/tests/test_observability.py +27 -0
- rein_graph-0.1.0/tests/test_parallel.py +93 -0
- rein_graph-0.1.0/tests/test_state.py +66 -0
- rein_graph-0.1.0/tests/test_stream.py +65 -0
- rein_graph-0.1.0/tests/test_subgraph.py +72 -0
- rein_graph-0.1.0/tests/test_viz.py +48 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, master]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: ${{ matrix.python-version }}
|
|
19
|
+
- run: pip install -e ".[dev]"
|
|
20
|
+
- run: ruff check .
|
|
21
|
+
- run: ruff format --check .
|
|
22
|
+
- run: mypy
|
|
23
|
+
- run: pytest --cov=reingraph
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
3
|
+
rev: v0.6.9
|
|
4
|
+
hooks:
|
|
5
|
+
- id: ruff
|
|
6
|
+
args: [--fix]
|
|
7
|
+
- id: ruff-format
|
|
8
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
9
|
+
rev: v4.6.0
|
|
10
|
+
hooks:
|
|
11
|
+
- id: trailing-whitespace
|
|
12
|
+
- id: end-of-file-fixer
|
|
13
|
+
- id: check-yaml
|
|
14
|
+
- id: check-toml
|
|
15
|
+
- id: check-added-large-files
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
本项目遵循 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/) 与 [语义化版本](https://semver.org/lang/zh-CN/)。
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
### Added(G0–G7 全部完成)
|
|
8
|
+
- **G0 状态与节点骨架**:`GraphState` + channel/reducer(名字注册表 → 可序列化)、`GraphConfig` 熔断四道闸、`GraphInterrupt`/`GraphStep`(复用 rein)、`Node` 协议 + `AgentNode`(中断冒泡)/`FunctionNode`。
|
|
9
|
+
- **G1 顺序引擎**:`StateGraph` 构建器(混合 API)+ 无状态 `superstep` + `GraphSession` 快照 + `CompiledGraph`。
|
|
10
|
+
- **G2 条件分支 + 循环**:`add_conditional_edges` + routing_fn + 循环上限熔断(`max_node_visits`)。
|
|
11
|
+
- **G3 并行扇出/汇合**:汇合屏障(静态前驱)+ reducer 汇合 + 并发安全。
|
|
12
|
+
- **G4 图级 HITL**:中断冒泡 + 进度保留 + `GraphStore`(复用 `SessionStore`)+ `aresume` 分发回 `agent.aresume`。
|
|
13
|
+
- **G5 流式 + 可观测**:`astream`(`GraphEvent` 事件流)+ usage 聚合 + steps 节点归属。
|
|
14
|
+
- **G6 子图**:`SubGraphNode`(图作节点)+ 嵌套 HITL(`sub_sessions` 自引用快照)。
|
|
15
|
+
- **G7 可视化 + examples**:`to_mermaid`(零依赖)+ sequential/fanout/hitl 示例。
|
|
16
|
+
- 工程化:Apache-2.0、ruff + mypy + pytest CI(3.11–3.13)、依赖 `rein-agent>=0.2.0`。
|
rein_graph-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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 Derivative
|
|
95
|
+
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 2026 Rein Authors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rein-graph
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 图编排框架:把多个 rein agent 编排成有状态的图工作流(条件分支/循环/并行/HITL),内核复用 rein
|
|
5
|
+
Project-URL: Homepage, https://github.com/MaLunan/rein-graph
|
|
6
|
+
Project-URL: Repository, https://github.com/MaLunan/rein-graph
|
|
7
|
+
Author: Rein Authors
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: agent,agentic,graph,langgraph,llm,orchestration,rein,workflow
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Requires-Dist: pydantic>=2.0
|
|
21
|
+
Requires-Dist: rein-agent>=0.2.0
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: mypy>=1.11; extra == 'dev'
|
|
24
|
+
Requires-Dist: pre-commit>=3.8; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# reinGraph
|
|
31
|
+
|
|
32
|
+
> **把多个 rein agent 编排成有状态的图工作流** —— 条件分支、循环、并行汇合、人在环路(HITL)。
|
|
33
|
+
|
|
34
|
+
reinGraph 之于 [rein](https://github.com/MaLunan/rein),如同 **LangGraph 之于 LangChain**。
|
|
35
|
+
但根本区别在于 ——【**内核全部复用 rein,而非重造**】:
|
|
36
|
+
|
|
37
|
+
- 图的 checkpoint 复用 rein 的 `SessionStore`;
|
|
38
|
+
- 图的暂停 / 恢复复用 rein 的 `aresume`(喂回状态从断点继续);
|
|
39
|
+
- 节点内执行复用 rein 的 `Agent.arun` / `RunResult`;
|
|
40
|
+
- 图级中断复用 rein 的 `Interrupt`(原样冒泡);
|
|
41
|
+
- 熔断照抄 rein 的 `check_circuit` 纯函数形态。
|
|
42
|
+
|
|
43
|
+
reinGraph 新增的只有「图拓扑」这一维。
|
|
44
|
+
|
|
45
|
+
## 安装
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install rein-graph # 装完即带 rein-agent
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import reingraph
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## 状态
|
|
56
|
+
|
|
57
|
+
**G0–G7 全部完成 ✅**:顺序 / 条件 / 循环 / 并行扇出汇合 / 图级 HITL(可恢复)/ 流式 / 子图嵌套 / 可视化。CI 全套绿(ruff + mypy + pytest,Python 3.11–3.13)。
|
|
58
|
+
|
|
59
|
+
## 许可
|
|
60
|
+
|
|
61
|
+
Apache-2.0
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# reinGraph
|
|
2
|
+
|
|
3
|
+
> **把多个 rein agent 编排成有状态的图工作流** —— 条件分支、循环、并行汇合、人在环路(HITL)。
|
|
4
|
+
|
|
5
|
+
reinGraph 之于 [rein](https://github.com/MaLunan/rein),如同 **LangGraph 之于 LangChain**。
|
|
6
|
+
但根本区别在于 ——【**内核全部复用 rein,而非重造**】:
|
|
7
|
+
|
|
8
|
+
- 图的 checkpoint 复用 rein 的 `SessionStore`;
|
|
9
|
+
- 图的暂停 / 恢复复用 rein 的 `aresume`(喂回状态从断点继续);
|
|
10
|
+
- 节点内执行复用 rein 的 `Agent.arun` / `RunResult`;
|
|
11
|
+
- 图级中断复用 rein 的 `Interrupt`(原样冒泡);
|
|
12
|
+
- 熔断照抄 rein 的 `check_circuit` 纯函数形态。
|
|
13
|
+
|
|
14
|
+
reinGraph 新增的只有「图拓扑」这一维。
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install rein-graph # 装完即带 rein-agent
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
import reingraph
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 状态
|
|
27
|
+
|
|
28
|
+
**G0–G7 全部完成 ✅**:顺序 / 条件 / 循环 / 并行扇出汇合 / 图级 HITL(可恢复)/ 流式 / 子图嵌套 / 可视化。CI 全套绿(ruff + mypy + pytest,Python 3.11–3.13)。
|
|
29
|
+
|
|
30
|
+
## 许可
|
|
31
|
+
|
|
32
|
+
Apache-2.0
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""reinGraph 示例:map-reduce 并行(split 扇出到 3 个视角 worker 并发 → 汇合成稿)。
|
|
2
|
+
|
|
3
|
+
演示用 MockProvider;真实把 provider 换成 model=... 即可。
|
|
4
|
+
跑:python examples/fanout.py
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from rein import Agent, MockProvider
|
|
8
|
+
|
|
9
|
+
from reingraph import AgentNode, StateGraph
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main() -> None:
|
|
13
|
+
g = StateGraph(channels={"drafts": "append"}) # drafts 用 append reducer 汇合多个分支
|
|
14
|
+
|
|
15
|
+
async def split(sv):
|
|
16
|
+
return {}
|
|
17
|
+
|
|
18
|
+
g.add_node("split", split)
|
|
19
|
+
for i, persona in enumerate(["乐观", "谨慎", "创新"]):
|
|
20
|
+
g.add_node(
|
|
21
|
+
f"w{i}",
|
|
22
|
+
AgentNode(
|
|
23
|
+
f"w{i}",
|
|
24
|
+
Agent(provider=MockProvider([f"{persona}视角:这个方案……"])),
|
|
25
|
+
output_key="drafts",
|
|
26
|
+
),
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
async def merge(sv):
|
|
30
|
+
return {"final": " | ".join(sv["drafts"])}
|
|
31
|
+
|
|
32
|
+
g.add_node("merge", merge)
|
|
33
|
+
g.set_entry_point("split")
|
|
34
|
+
for i in range(3):
|
|
35
|
+
g.add_edge("split", f"w{i}")
|
|
36
|
+
g.add_edge(f"w{i}", "merge")
|
|
37
|
+
g.set_finish_point("merge")
|
|
38
|
+
|
|
39
|
+
r = g.compile().invoke({"input": "评估这个方案"})
|
|
40
|
+
print("三个视角并发跑完、汇合:")
|
|
41
|
+
print(r.values["final"])
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
main()
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""reinGraph 示例:人工审批(HITL)—— 危险操作前暂停等批准,可换进程恢复。
|
|
2
|
+
|
|
3
|
+
演示用 MockProvider;真实把 provider 换成 model=... 即可。
|
|
4
|
+
跑:python examples/hitl.py
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from rein import Agent, LoopConfig, MockProvider, ToolCall
|
|
8
|
+
|
|
9
|
+
from reingraph import MemoryGraphStore, StateGraph
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main() -> None:
|
|
13
|
+
agent = Agent(
|
|
14
|
+
provider=MockProvider([[ToolCall(id="1", name="refund", arguments={"amount": 100})]]),
|
|
15
|
+
config=LoopConfig(permission="ask"), # 工具执行前需人工批准
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
@agent.tool
|
|
19
|
+
def refund(amount: int) -> str:
|
|
20
|
+
"给订单退款(危险操作)"
|
|
21
|
+
return f"已退款 {amount} 元"
|
|
22
|
+
|
|
23
|
+
store = MemoryGraphStore() # 真实可换成 FileGraphStore / Redis 等
|
|
24
|
+
g = StateGraph()
|
|
25
|
+
g.add_node("handle", agent)
|
|
26
|
+
g.set_entry_point("handle")
|
|
27
|
+
g.set_finish_point("handle")
|
|
28
|
+
app = g.compile(store=store)
|
|
29
|
+
|
|
30
|
+
r = app.invoke({"input": "给订单退款 100 元"}, thread_id="order-1")
|
|
31
|
+
print("第一次执行状态:", r.status) # interrupted —— 整图存进 store 了
|
|
32
|
+
if r.status == "interrupted":
|
|
33
|
+
print("待审批节点:", r.interrupt.node, "/ 类型:", r.interrupt.inner.type)
|
|
34
|
+
# —— 这里可以换一个进程:store 里有 order-1 的完整快照 ——
|
|
35
|
+
r = app.resume("order-1", approve=True) # 人批准后恢复
|
|
36
|
+
print("批准后恢复状态:", r.status) # done
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if __name__ == "__main__":
|
|
40
|
+
main()
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""reinGraph 示例:顺序流水线(plan → write → END)+ 打印图拓扑。
|
|
2
|
+
|
|
3
|
+
演示用 MockProvider(不烧 key、不联网);真实使用把 `provider=MockProvider([...])`
|
|
4
|
+
换成 `model="anthropic/claude-opus-4-8"` 即可。
|
|
5
|
+
跑:python examples/sequential.py
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from rein import Agent, MockProvider
|
|
9
|
+
|
|
10
|
+
from reingraph import AgentNode, StateGraph
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main() -> None:
|
|
14
|
+
g = StateGraph()
|
|
15
|
+
# plan:读 input,写 output
|
|
16
|
+
g.add_node("plan", Agent(provider=MockProvider(["大纲:1.引子 2.正文 3.结尾"])))
|
|
17
|
+
# write:读上一步的 output,写 article
|
|
18
|
+
g.add_node(
|
|
19
|
+
"write",
|
|
20
|
+
AgentNode(
|
|
21
|
+
"write",
|
|
22
|
+
Agent(provider=MockProvider(["成稿:从前有座山……"])),
|
|
23
|
+
input_key="output",
|
|
24
|
+
output_key="article",
|
|
25
|
+
),
|
|
26
|
+
)
|
|
27
|
+
g.set_entry_point("plan")
|
|
28
|
+
g.add_edge("plan", "write")
|
|
29
|
+
g.set_finish_point("write")
|
|
30
|
+
app = g.compile()
|
|
31
|
+
|
|
32
|
+
print("=== 图拓扑(mermaid)===")
|
|
33
|
+
print(app.to_mermaid())
|
|
34
|
+
|
|
35
|
+
r = app.invoke({"input": "写一篇关于 AI 的短文"})
|
|
36
|
+
print("\n=== 结果 ===")
|
|
37
|
+
print("大纲:", r.values["output"])
|
|
38
|
+
print("成稿:", r.values["article"])
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
main()
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rein-graph"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "图编排框架:把多个 rein agent 编排成有状态的图工作流(条件分支/循环/并行/HITL),内核复用 rein"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Rein Authors" }]
|
|
14
|
+
keywords = ["agent", "llm", "graph", "orchestration", "workflow", "langgraph", "rein", "agentic"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Topic :: Software Development :: Libraries :: Application Frameworks",
|
|
23
|
+
"Typing :: Typed",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"rein-agent>=0.2.0",
|
|
27
|
+
"pydantic>=2.0",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://github.com/MaLunan/rein-graph"
|
|
32
|
+
Repository = "https://github.com/MaLunan/rein-graph"
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
dev = [
|
|
36
|
+
"pytest>=8.0",
|
|
37
|
+
"pytest-cov>=5.0",
|
|
38
|
+
"ruff>=0.6",
|
|
39
|
+
"mypy>=1.11",
|
|
40
|
+
"pre-commit>=3.8",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[tool.hatch.build.targets.wheel]
|
|
44
|
+
packages = ["src/reingraph"]
|
|
45
|
+
|
|
46
|
+
[tool.ruff]
|
|
47
|
+
line-length = 100
|
|
48
|
+
target-version = "py311"
|
|
49
|
+
src = ["src", "tests"]
|
|
50
|
+
|
|
51
|
+
[tool.ruff.lint]
|
|
52
|
+
select = ["E", "F", "W", "I", "UP", "B", "C4"]
|
|
53
|
+
ignore = ["E501"]
|
|
54
|
+
|
|
55
|
+
[tool.ruff.lint.isort]
|
|
56
|
+
known-first-party = ["reingraph"]
|
|
57
|
+
|
|
58
|
+
[tool.pytest.ini_options]
|
|
59
|
+
testpaths = ["tests"]
|
|
60
|
+
addopts = "-q"
|
|
61
|
+
|
|
62
|
+
[tool.coverage.run]
|
|
63
|
+
source = ["reingraph"]
|
|
64
|
+
branch = true
|
|
65
|
+
|
|
66
|
+
[tool.coverage.report]
|
|
67
|
+
show_missing = true
|
|
68
|
+
exclude_lines = ["pragma: no cover", "raise NotImplementedError", "if TYPE_CHECKING:"]
|
|
69
|
+
|
|
70
|
+
[tool.mypy]
|
|
71
|
+
python_version = "3.11"
|
|
72
|
+
files = ["src"]
|
|
73
|
+
ignore_missing_imports = true
|
|
74
|
+
check_untyped_defs = true
|
|
75
|
+
warn_unused_ignores = true
|
|
76
|
+
warn_redundant_casts = true
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""reinGraph —— 图编排框架:把多个 rein agent 编排成有状态的图工作流。
|
|
2
|
+
|
|
3
|
+
定位类比:reinGraph 之于 rein,如同 LangGraph 之于 LangChain。
|
|
4
|
+
但根本区别在于 ——【内核全部复用 rein,而非重造】:
|
|
5
|
+
- 图的 checkpoint 复用 rein 的 SessionStore;
|
|
6
|
+
- 图的暂停/恢复复用 rein 的 aresume(喂回状态从断点继续);
|
|
7
|
+
- 节点内执行复用 rein 的 Agent.arun / RunResult;
|
|
8
|
+
- 图级中断复用 rein 的 Interrupt(原样冒泡);
|
|
9
|
+
- 熔断照抄 rein 的 check_circuit 纯函数形态。
|
|
10
|
+
reinGraph 新增的只有「图拓扑」这一维。
|
|
11
|
+
|
|
12
|
+
最小用法:
|
|
13
|
+
from reingraph import StateGraph
|
|
14
|
+
from rein import Agent
|
|
15
|
+
|
|
16
|
+
g = StateGraph()
|
|
17
|
+
g.add_node("write", Agent(model="anthropic/claude-opus-4-8"))
|
|
18
|
+
g.set_entry_point("write")
|
|
19
|
+
g.set_finish_point("write")
|
|
20
|
+
app = g.compile()
|
|
21
|
+
print(app.invoke({"input": "写一首诗"}).values["output"])
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
__version__ = "0.1.0"
|
|
25
|
+
|
|
26
|
+
from reingraph.config import GraphConfig
|
|
27
|
+
from reingraph.edges import END, START
|
|
28
|
+
from reingraph.graph import StateGraph
|
|
29
|
+
from reingraph.nodes import AgentNode, FunctionNode, Node, NodeResult
|
|
30
|
+
from reingraph.result import GraphInterrupt, GraphStep
|
|
31
|
+
from reingraph.session import GraphResult, GraphSession
|
|
32
|
+
from reingraph.state import (
|
|
33
|
+
Channel,
|
|
34
|
+
GraphState,
|
|
35
|
+
apply_updates,
|
|
36
|
+
make_state,
|
|
37
|
+
register_reducer,
|
|
38
|
+
)
|
|
39
|
+
from reingraph.store import FileGraphStore, GraphStore, MemoryGraphStore
|
|
40
|
+
from reingraph.stream import GraphEvent
|
|
41
|
+
|
|
42
|
+
__all__ = [
|
|
43
|
+
"__version__",
|
|
44
|
+
# 构建 / 执行
|
|
45
|
+
"StateGraph",
|
|
46
|
+
"START",
|
|
47
|
+
"END",
|
|
48
|
+
"GraphConfig",
|
|
49
|
+
# 状态
|
|
50
|
+
"GraphState",
|
|
51
|
+
"Channel",
|
|
52
|
+
"make_state",
|
|
53
|
+
"apply_updates",
|
|
54
|
+
"register_reducer",
|
|
55
|
+
# 节点
|
|
56
|
+
"Node",
|
|
57
|
+
"NodeResult",
|
|
58
|
+
"AgentNode",
|
|
59
|
+
"FunctionNode",
|
|
60
|
+
# 快照 / 结果 / 中断
|
|
61
|
+
"GraphSession",
|
|
62
|
+
"GraphResult",
|
|
63
|
+
"GraphInterrupt",
|
|
64
|
+
"GraphStep",
|
|
65
|
+
# 持久化(复用 rein.SessionStore 形态)
|
|
66
|
+
"GraphStore",
|
|
67
|
+
"MemoryGraphStore",
|
|
68
|
+
"FileGraphStore",
|
|
69
|
+
# 流式
|
|
70
|
+
"GraphEvent",
|
|
71
|
+
]
|