wuwei 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.
- wuwei-0.1.0/LICENSE +201 -0
- wuwei-0.1.0/PKG-INFO +155 -0
- wuwei-0.1.0/README.md +129 -0
- wuwei-0.1.0/pyproject.toml +53 -0
- wuwei-0.1.0/setup.cfg +4 -0
- wuwei-0.1.0/tests/test_agent.py +140 -0
- wuwei-0.1.0/tests/test_executor.py +66 -0
- wuwei-0.1.0/tests/test_llm_gateway.py +111 -0
- wuwei-0.1.0/tests/test_plan_agent.py +80 -0
- wuwei-0.1.0/tests/test_plan_runner.py +161 -0
- wuwei-0.1.0/wuwei/__init__.py +30 -0
- wuwei-0.1.0/wuwei/agent/__init__.py +15 -0
- wuwei-0.1.0/wuwei/agent/agent.py +47 -0
- wuwei-0.1.0/wuwei/agent/base.py +93 -0
- wuwei-0.1.0/wuwei/agent/plan_agent.py +73 -0
- wuwei-0.1.0/wuwei/agent/session.py +23 -0
- wuwei-0.1.0/wuwei/llm/__init__.py +13 -0
- wuwei-0.1.0/wuwei/llm/adapters/__init__.py +3 -0
- wuwei-0.1.0/wuwei/llm/adapters/base.py +26 -0
- wuwei-0.1.0/wuwei/llm/adapters/openai.py +109 -0
- wuwei-0.1.0/wuwei/llm/gateway.py +244 -0
- wuwei-0.1.0/wuwei/llm/types.py +32 -0
- wuwei-0.1.0/wuwei/memory/__init__.py +3 -0
- wuwei-0.1.0/wuwei/memory/context.py +36 -0
- wuwei-0.1.0/wuwei/planning/__init__.py +4 -0
- wuwei-0.1.0/wuwei/planning/planner.py +65 -0
- wuwei-0.1.0/wuwei/planning/task.py +26 -0
- wuwei-0.1.0/wuwei/runtime/__init__.py +4 -0
- wuwei-0.1.0/wuwei/runtime/agent_runner.py +114 -0
- wuwei-0.1.0/wuwei/runtime/planner_executor_runner.py +291 -0
- wuwei-0.1.0/wuwei/tools/__init__.py +10 -0
- wuwei-0.1.0/wuwei/tools/executor.py +97 -0
- wuwei-0.1.0/wuwei/tools/registry.py +104 -0
- wuwei-0.1.0/wuwei/tools/tool.py +42 -0
- wuwei-0.1.0/wuwei.egg-info/PKG-INFO +155 -0
- wuwei-0.1.0/wuwei.egg-info/SOURCES.txt +37 -0
- wuwei-0.1.0/wuwei.egg-info/dependency_links.txt +1 -0
- wuwei-0.1.0/wuwei.egg-info/requires.txt +8 -0
- wuwei-0.1.0/wuwei.egg-info/top_level.txt +1 -0
wuwei-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
|
|
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 [2026] [xiaojiaenen]
|
|
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.
|
wuwei-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wuwei
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Wuwei - 无为而治的 AI 智能体框架
|
|
5
|
+
Author-email: xiaojiaenen <xiaojiaenen@163.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/xiaojiaenen/wuwei
|
|
8
|
+
Project-URL: Repository, https://github.com/xiaojiaenen/wuwei
|
|
9
|
+
Project-URL: Documentation, https://github.com/xiaojiaenen/wuwei
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: openai>=1.0.0
|
|
19
|
+
Requires-Dist: pydantic>=2.0.0
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
22
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
|
|
23
|
+
Requires-Dist: black>=23.0; extra == "dev"
|
|
24
|
+
Requires-Dist: ruff>=0.0.280; extra == "dev"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# Wuwei
|
|
28
|
+
|
|
29
|
+
Wuwei 是一个轻量、可扩展的 Python Agent 框架,目标是把模型调用、会话管理、工具注册与执行、plan-and-execute 拆成边界清晰的模块,方便学习和继续扩展。
|
|
30
|
+
|
|
31
|
+
## 当前目录结构
|
|
32
|
+
|
|
33
|
+
```text
|
|
34
|
+
wuwei/
|
|
35
|
+
├─ examples/ # 可直接运行的示例
|
|
36
|
+
├─ tests/ # pytest 测试
|
|
37
|
+
├─ wuwei/ # 框架源码
|
|
38
|
+
│ ├─ agent/ # Agent、PlanAgent、Session、基础抽象
|
|
39
|
+
│ ├─ runtime/ # AgentRunner、PlannerExecutorRunner
|
|
40
|
+
│ ├─ planning/ # Planner、Task
|
|
41
|
+
│ ├─ memory/ # Context
|
|
42
|
+
│ ├─ llm/ # Gateway、Types、Adapters
|
|
43
|
+
│ └─ tools/ # Tool、Registry、Executor
|
|
44
|
+
├─ pyproject.toml
|
|
45
|
+
└─ README.md
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
这次目录调整的核心是:
|
|
49
|
+
|
|
50
|
+
- `tests/` 只放测试
|
|
51
|
+
- `examples/` 只放示例
|
|
52
|
+
- `agent/` 只放门面对象和会话
|
|
53
|
+
- `runtime/` 单独承接执行器
|
|
54
|
+
- `planning/` 单独承接规划相关模型
|
|
55
|
+
- `memory/` 单独承接上下文
|
|
56
|
+
|
|
57
|
+
## 安装
|
|
58
|
+
|
|
59
|
+
要求:
|
|
60
|
+
|
|
61
|
+
- Python `>=3.10`
|
|
62
|
+
|
|
63
|
+
使用 `pip`:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install -e .
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
安装开发依赖:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install -e ".[dev]"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
如果你使用 `uv`:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
uv sync
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## 核心模块
|
|
82
|
+
|
|
83
|
+
- `wuwei.agent`
|
|
84
|
+
- `Agent`:普通单 agent 门面
|
|
85
|
+
- `PlanAgent`:plan-and-execute 门面
|
|
86
|
+
- `AgentSession`:会话对象
|
|
87
|
+
- `BaseAgent / BaseSessionAgent`:基础抽象
|
|
88
|
+
|
|
89
|
+
- `wuwei.runtime`
|
|
90
|
+
- `AgentRunner`:普通 agent 执行器
|
|
91
|
+
- `PlannerExecutorRunner`:plan-and-execute 执行器
|
|
92
|
+
|
|
93
|
+
- `wuwei.planning`
|
|
94
|
+
- `Planner`:任务规划器
|
|
95
|
+
- `Task / TaskList`:任务模型
|
|
96
|
+
|
|
97
|
+
- `wuwei.memory`
|
|
98
|
+
- `Context`:消息上下文
|
|
99
|
+
|
|
100
|
+
- `wuwei.llm`
|
|
101
|
+
- `LLMGateway`:统一模型调用入口
|
|
102
|
+
- `Message / ToolCall / LLMResponse / LLMResponseChunk`:统一类型定义
|
|
103
|
+
|
|
104
|
+
- `wuwei.tools`
|
|
105
|
+
- `ToolRegistry`:工具注册
|
|
106
|
+
- `ToolExecutor`:工具执行
|
|
107
|
+
- `Tool / ToolParameters`:工具 schema
|
|
108
|
+
|
|
109
|
+
## 快速开始
|
|
110
|
+
|
|
111
|
+
最简单的方式是直接运行 `examples/` 里的示例。
|
|
112
|
+
|
|
113
|
+
离线示例:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
python examples/tool_executor_minimal.py
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
在线示例:
|
|
120
|
+
|
|
121
|
+
```powershell
|
|
122
|
+
$env:WUWEI_API_KEY="your_key"
|
|
123
|
+
python examples/agent_minimal.py
|
|
124
|
+
python examples/agent_session_minimal.py
|
|
125
|
+
python examples/plan_agent_minimal.py
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
更详细的说明可以看:
|
|
129
|
+
|
|
130
|
+
- [examples/README.md](examples/README.md)
|
|
131
|
+
|
|
132
|
+
## 示例目录
|
|
133
|
+
|
|
134
|
+
- [tool_executor_minimal.py](examples/tool_executor_minimal.py)
|
|
135
|
+
- 完全离线可运行,适合先理解工具系统
|
|
136
|
+
|
|
137
|
+
- [agent_minimal.py](examples/agent_minimal.py)
|
|
138
|
+
- 最小 `Agent` 示例,演示流式输出和工具调用
|
|
139
|
+
|
|
140
|
+
- [agent_session_minimal.py](examples/agent_session_minimal.py)
|
|
141
|
+
- 演示 session 多轮复用
|
|
142
|
+
|
|
143
|
+
- [plan_agent_minimal.py](examples/plan_agent_minimal.py)
|
|
144
|
+
- 演示 `PlanAgent` 的“先规划、再执行”
|
|
145
|
+
|
|
146
|
+
## 当前建议的扩展方向
|
|
147
|
+
|
|
148
|
+
- 先完善 `PlanAgent / PlannerExecutorRunner`
|
|
149
|
+
- 比如 task 并行执行、失败恢复、重规划
|
|
150
|
+
|
|
151
|
+
- 再增强 `ToolExecutor`
|
|
152
|
+
- 比如更丰富的执行事件、超时控制、重试策略
|
|
153
|
+
|
|
154
|
+
- 最后再考虑可观测和 Web 可视化
|
|
155
|
+
- 这样不会过早把主链路搞复杂
|
wuwei-0.1.0/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Wuwei
|
|
2
|
+
|
|
3
|
+
Wuwei 是一个轻量、可扩展的 Python Agent 框架,目标是把模型调用、会话管理、工具注册与执行、plan-and-execute 拆成边界清晰的模块,方便学习和继续扩展。
|
|
4
|
+
|
|
5
|
+
## 当前目录结构
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
wuwei/
|
|
9
|
+
├─ examples/ # 可直接运行的示例
|
|
10
|
+
├─ tests/ # pytest 测试
|
|
11
|
+
├─ wuwei/ # 框架源码
|
|
12
|
+
│ ├─ agent/ # Agent、PlanAgent、Session、基础抽象
|
|
13
|
+
│ ├─ runtime/ # AgentRunner、PlannerExecutorRunner
|
|
14
|
+
│ ├─ planning/ # Planner、Task
|
|
15
|
+
│ ├─ memory/ # Context
|
|
16
|
+
│ ├─ llm/ # Gateway、Types、Adapters
|
|
17
|
+
│ └─ tools/ # Tool、Registry、Executor
|
|
18
|
+
├─ pyproject.toml
|
|
19
|
+
└─ README.md
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
这次目录调整的核心是:
|
|
23
|
+
|
|
24
|
+
- `tests/` 只放测试
|
|
25
|
+
- `examples/` 只放示例
|
|
26
|
+
- `agent/` 只放门面对象和会话
|
|
27
|
+
- `runtime/` 单独承接执行器
|
|
28
|
+
- `planning/` 单独承接规划相关模型
|
|
29
|
+
- `memory/` 单独承接上下文
|
|
30
|
+
|
|
31
|
+
## 安装
|
|
32
|
+
|
|
33
|
+
要求:
|
|
34
|
+
|
|
35
|
+
- Python `>=3.10`
|
|
36
|
+
|
|
37
|
+
使用 `pip`:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install -e .
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
安装开发依赖:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install -e ".[dev]"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
如果你使用 `uv`:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
uv sync
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## 核心模块
|
|
56
|
+
|
|
57
|
+
- `wuwei.agent`
|
|
58
|
+
- `Agent`:普通单 agent 门面
|
|
59
|
+
- `PlanAgent`:plan-and-execute 门面
|
|
60
|
+
- `AgentSession`:会话对象
|
|
61
|
+
- `BaseAgent / BaseSessionAgent`:基础抽象
|
|
62
|
+
|
|
63
|
+
- `wuwei.runtime`
|
|
64
|
+
- `AgentRunner`:普通 agent 执行器
|
|
65
|
+
- `PlannerExecutorRunner`:plan-and-execute 执行器
|
|
66
|
+
|
|
67
|
+
- `wuwei.planning`
|
|
68
|
+
- `Planner`:任务规划器
|
|
69
|
+
- `Task / TaskList`:任务模型
|
|
70
|
+
|
|
71
|
+
- `wuwei.memory`
|
|
72
|
+
- `Context`:消息上下文
|
|
73
|
+
|
|
74
|
+
- `wuwei.llm`
|
|
75
|
+
- `LLMGateway`:统一模型调用入口
|
|
76
|
+
- `Message / ToolCall / LLMResponse / LLMResponseChunk`:统一类型定义
|
|
77
|
+
|
|
78
|
+
- `wuwei.tools`
|
|
79
|
+
- `ToolRegistry`:工具注册
|
|
80
|
+
- `ToolExecutor`:工具执行
|
|
81
|
+
- `Tool / ToolParameters`:工具 schema
|
|
82
|
+
|
|
83
|
+
## 快速开始
|
|
84
|
+
|
|
85
|
+
最简单的方式是直接运行 `examples/` 里的示例。
|
|
86
|
+
|
|
87
|
+
离线示例:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
python examples/tool_executor_minimal.py
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
在线示例:
|
|
94
|
+
|
|
95
|
+
```powershell
|
|
96
|
+
$env:WUWEI_API_KEY="your_key"
|
|
97
|
+
python examples/agent_minimal.py
|
|
98
|
+
python examples/agent_session_minimal.py
|
|
99
|
+
python examples/plan_agent_minimal.py
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
更详细的说明可以看:
|
|
103
|
+
|
|
104
|
+
- [examples/README.md](examples/README.md)
|
|
105
|
+
|
|
106
|
+
## 示例目录
|
|
107
|
+
|
|
108
|
+
- [tool_executor_minimal.py](examples/tool_executor_minimal.py)
|
|
109
|
+
- 完全离线可运行,适合先理解工具系统
|
|
110
|
+
|
|
111
|
+
- [agent_minimal.py](examples/agent_minimal.py)
|
|
112
|
+
- 最小 `Agent` 示例,演示流式输出和工具调用
|
|
113
|
+
|
|
114
|
+
- [agent_session_minimal.py](examples/agent_session_minimal.py)
|
|
115
|
+
- 演示 session 多轮复用
|
|
116
|
+
|
|
117
|
+
- [plan_agent_minimal.py](examples/plan_agent_minimal.py)
|
|
118
|
+
- 演示 `PlanAgent` 的“先规划、再执行”
|
|
119
|
+
|
|
120
|
+
## 当前建议的扩展方向
|
|
121
|
+
|
|
122
|
+
- 先完善 `PlanAgent / PlannerExecutorRunner`
|
|
123
|
+
- 比如 task 并行执行、失败恢复、重规划
|
|
124
|
+
|
|
125
|
+
- 再增强 `ToolExecutor`
|
|
126
|
+
- 比如更丰富的执行事件、超时控制、重试策略
|
|
127
|
+
|
|
128
|
+
- 最后再考虑可观测和 Web 可视化
|
|
129
|
+
- 这样不会过早把主链路搞复杂
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "wuwei"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Wuwei - 无为而治的 AI 智能体框架"
|
|
9
|
+
authors = [{name = "xiaojiaenen", email = "xiaojiaenen@163.com"}]
|
|
10
|
+
license = "Apache-2.0" # 改为简单字符串(SPDX 表达式)
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.10" # 放宽到 3.10(openai 支持)
|
|
13
|
+
dependencies = [
|
|
14
|
+
"openai>=1.0.0", # 最新稳定版是 1.x,2.x 不存在
|
|
15
|
+
"pydantic>=2.0.0",
|
|
16
|
+
]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 3 - Alpha",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
dev = [
|
|
27
|
+
"pytest>=7.0",
|
|
28
|
+
"pytest-asyncio>=0.21",
|
|
29
|
+
"black>=23.0",
|
|
30
|
+
"ruff>=0.0.280",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://github.com/xiaojiaenen/wuwei"
|
|
35
|
+
Repository = "https://github.com/xiaojiaenen/wuwei"
|
|
36
|
+
Documentation = "https://github.com/xiaojiaenen/wuwei"
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.packages.find]
|
|
39
|
+
where = ["."]
|
|
40
|
+
include = ["wuwei*"] # 只打包 wuwei 及其子包
|
|
41
|
+
exclude = ["tests*", "examples*"]
|
|
42
|
+
|
|
43
|
+
[tool.black]
|
|
44
|
+
line-length = 100
|
|
45
|
+
target-version = ['py310']
|
|
46
|
+
|
|
47
|
+
[tool.ruff]
|
|
48
|
+
line-length = 100
|
|
49
|
+
select = ["E", "F", "W", "I", "N", "UP", "B", "C4", "SIM"]
|
|
50
|
+
|
|
51
|
+
[tool.pytest.ini_options]
|
|
52
|
+
asyncio_mode = "auto"
|
|
53
|
+
testpaths = ["tests"]
|
wuwei-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
|
|
5
|
+
from wuwei.agent import Agent
|
|
6
|
+
from wuwei.llm.types import FunctionCall, LLMResponse, LLMResponseChunk, Message, ToolCall
|
|
7
|
+
from wuwei.tools import ToolRegistry
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DummyModelOutput(BaseModel):
|
|
11
|
+
value: int
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class NonStreamLLM:
|
|
15
|
+
def __init__(self):
|
|
16
|
+
self.calls = 0
|
|
17
|
+
|
|
18
|
+
async def generate(self, messages, tools=None, stream=False, **kwargs):
|
|
19
|
+
self.calls += 1
|
|
20
|
+
if self.calls == 1:
|
|
21
|
+
return LLMResponse(
|
|
22
|
+
message=Message(
|
|
23
|
+
role="assistant",
|
|
24
|
+
content=None,
|
|
25
|
+
tool_calls=[
|
|
26
|
+
ToolCall(
|
|
27
|
+
id="call_1",
|
|
28
|
+
type="function",
|
|
29
|
+
function=FunctionCall(name="make_payload", arguments={}),
|
|
30
|
+
)
|
|
31
|
+
],
|
|
32
|
+
),
|
|
33
|
+
finish_reason="tool_calls",
|
|
34
|
+
usage={"prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0},
|
|
35
|
+
model="dummy",
|
|
36
|
+
latency_ms=0,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
return LLMResponse(
|
|
40
|
+
message=Message(role="assistant", content="done"),
|
|
41
|
+
finish_reason="stop",
|
|
42
|
+
usage={"prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0},
|
|
43
|
+
model="dummy",
|
|
44
|
+
latency_ms=0,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class StreamLLM:
|
|
49
|
+
def __init__(self):
|
|
50
|
+
self.calls = 0
|
|
51
|
+
|
|
52
|
+
async def generate(self, messages, tools=None, stream=False, **kwargs):
|
|
53
|
+
self.calls += 1
|
|
54
|
+
|
|
55
|
+
async def first_stream():
|
|
56
|
+
yield LLMResponseChunk(
|
|
57
|
+
content="",
|
|
58
|
+
tool_calls_complete=[
|
|
59
|
+
ToolCall(
|
|
60
|
+
id="call_1",
|
|
61
|
+
type="function",
|
|
62
|
+
function=FunctionCall(name="boom", arguments={}),
|
|
63
|
+
)
|
|
64
|
+
],
|
|
65
|
+
finish_reason="tool_calls",
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
async def second_stream():
|
|
69
|
+
yield LLMResponseChunk(content="done", finish_reason="stop")
|
|
70
|
+
|
|
71
|
+
return first_stream() if self.calls == 1 else second_stream()
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_agent_create_session_uses_agent_defaults():
|
|
75
|
+
agent = Agent(
|
|
76
|
+
llm=NonStreamLLM(),
|
|
77
|
+
default_system_prompt="system",
|
|
78
|
+
default_max_steps=3,
|
|
79
|
+
default_parallel_tool_calls=True,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
session = agent.create_session(session_id="session-1")
|
|
83
|
+
|
|
84
|
+
assert session.session_id == "session-1"
|
|
85
|
+
assert session.system_prompt == "system"
|
|
86
|
+
assert session.max_steps == 3
|
|
87
|
+
assert session.parallel_tool_calls is True
|
|
88
|
+
assert session.context.get_messages()[0].content == "system"
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_agent_serializes_tool_outputs_before_adding_to_session_context():
|
|
92
|
+
registry = ToolRegistry()
|
|
93
|
+
|
|
94
|
+
@registry.tool()
|
|
95
|
+
async def make_payload():
|
|
96
|
+
return DummyModelOutput(value=7)
|
|
97
|
+
|
|
98
|
+
agent = Agent(llm=NonStreamLLM(), tools=registry)
|
|
99
|
+
session = agent.create_session(session_id="session-1")
|
|
100
|
+
result = asyncio.run(agent.run("hello", session=session))
|
|
101
|
+
|
|
102
|
+
assert result == "done"
|
|
103
|
+
|
|
104
|
+
tool_messages = [message for message in session.context.get_messages() if message.role == "tool"]
|
|
105
|
+
assert len(tool_messages) == 1
|
|
106
|
+
assert tool_messages[0].content == '{"value":7}'
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_stream_mode_only_yields_response_chunks_even_when_tool_execution_fails():
|
|
110
|
+
registry = ToolRegistry()
|
|
111
|
+
|
|
112
|
+
@registry.tool()
|
|
113
|
+
async def boom():
|
|
114
|
+
raise RuntimeError("boom")
|
|
115
|
+
|
|
116
|
+
agent = Agent(llm=StreamLLM(), tools=registry)
|
|
117
|
+
session = agent.create_session(session_id="session-1")
|
|
118
|
+
|
|
119
|
+
async def collect():
|
|
120
|
+
items = []
|
|
121
|
+
async for chunk in await agent.run("hello", session=session, stream=True):
|
|
122
|
+
items.append(chunk)
|
|
123
|
+
return items
|
|
124
|
+
|
|
125
|
+
chunks = asyncio.run(collect())
|
|
126
|
+
|
|
127
|
+
assert chunks
|
|
128
|
+
assert all(isinstance(chunk, LLMResponseChunk) for chunk in chunks)
|
|
129
|
+
assert any("boom" in chunk.content for chunk in chunks)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def test_reusing_session_preserves_history_across_runs():
|
|
133
|
+
agent = Agent(llm=NonStreamLLM())
|
|
134
|
+
session = agent.create_session(session_id="session-1")
|
|
135
|
+
|
|
136
|
+
asyncio.run(agent.run("first", session=session))
|
|
137
|
+
asyncio.run(agent.run("second", session=session))
|
|
138
|
+
|
|
139
|
+
user_messages = [message.content for message in session.context.get_messages() if message.role == "user"]
|
|
140
|
+
assert user_messages == ["first", "second"]
|