bumaren-agent-workflow 0.1.6__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.
- bumaren_agent_workflow-0.1.6/.github/workflows/publish-pypi.yml +48 -0
- bumaren_agent_workflow-0.1.6/.gitignore +4 -0
- bumaren_agent_workflow-0.1.6/CHANGELOG.md +26 -0
- bumaren_agent_workflow-0.1.6/CODE_OF_CONDUCT.md +82 -0
- bumaren_agent_workflow-0.1.6/CONTRIBUTING.md +54 -0
- bumaren_agent_workflow-0.1.6/LICENSE +21 -0
- bumaren_agent_workflow-0.1.6/PKG-INFO +161 -0
- bumaren_agent_workflow-0.1.6/README.md +115 -0
- bumaren_agent_workflow-0.1.6/agent/__init__.py +20 -0
- bumaren_agent_workflow-0.1.6/agent/agent.py +203 -0
- bumaren_agent_workflow-0.1.6/agent/memory.py +108 -0
- bumaren_agent_workflow-0.1.6/agent/toolset.py +45 -0
- bumaren_agent_workflow-0.1.6/bumaren_agent_workflow.egg-info/PKG-INFO +161 -0
- bumaren_agent_workflow-0.1.6/bumaren_agent_workflow.egg-info/SOURCES.txt +93 -0
- bumaren_agent_workflow-0.1.6/bumaren_agent_workflow.egg-info/dependency_links.txt +1 -0
- bumaren_agent_workflow-0.1.6/bumaren_agent_workflow.egg-info/requires.txt +4 -0
- bumaren_agent_workflow-0.1.6/bumaren_agent_workflow.egg-info/scm_file_list.json +90 -0
- bumaren_agent_workflow-0.1.6/bumaren_agent_workflow.egg-info/scm_version.json +8 -0
- bumaren_agent_workflow-0.1.6/bumaren_agent_workflow.egg-info/top_level.txt +5 -0
- bumaren_agent_workflow-0.1.6/engine/__init__.py +21 -0
- bumaren_agent_workflow-0.1.6/engine/context.py +129 -0
- bumaren_agent_workflow-0.1.6/engine/primitives/__init__.py +34 -0
- bumaren_agent_workflow-0.1.6/engine/primitives/breaker.py +49 -0
- bumaren_agent_workflow-0.1.6/engine/primitives/checkpoint.py +61 -0
- bumaren_agent_workflow-0.1.6/engine/primitives/continuer.py +59 -0
- bumaren_agent_workflow-0.1.6/engine/primitives/foreach.py +126 -0
- bumaren_agent_workflow-0.1.6/engine/primitives/loop.py +201 -0
- bumaren_agent_workflow-0.1.6/engine/primitives/sequence.py +28 -0
- bumaren_agent_workflow-0.1.6/engine/stage.py +99 -0
- bumaren_agent_workflow-0.1.6/engine/workflow.py +110 -0
- bumaren_agent_workflow-0.1.6/llm/__init__.py +14 -0
- bumaren_agent_workflow-0.1.6/llm/client.py +123 -0
- bumaren_agent_workflow-0.1.6/llm/image_client.py +66 -0
- bumaren_agent_workflow-0.1.6/llm/logging_client.py +94 -0
- bumaren_agent_workflow-0.1.6/llm/message.py +38 -0
- bumaren_agent_workflow-0.1.6/llm/providers/__init__.py +17 -0
- bumaren_agent_workflow-0.1.6/llm/providers/anthropic.py +213 -0
- bumaren_agent_workflow-0.1.6/llm/providers/openai.py +203 -0
- bumaren_agent_workflow-0.1.6/llm/providers/zhipu.py +263 -0
- bumaren_agent_workflow-0.1.6/pyproject.toml +41 -0
- bumaren_agent_workflow-0.1.6/requirements.txt +4 -0
- bumaren_agent_workflow-0.1.6/scenarios/development-guide.md +443 -0
- bumaren_agent_workflow-0.1.6/scenarios/example/nodes/__init__.py +5 -0
- bumaren_agent_workflow-0.1.6/scenarios/example/nodes/common.py +22 -0
- bumaren_agent_workflow-0.1.6/scenarios/example/nodes/first_draft.py +21 -0
- bumaren_agent_workflow-0.1.6/scenarios/example/nodes/redraft.py +21 -0
- bumaren_agent_workflow-0.1.6/scenarios/example/nodes/requirement_parse.py +18 -0
- bumaren_agent_workflow-0.1.6/scenarios/example/nodes/review.py +31 -0
- bumaren_agent_workflow-0.1.6/scenarios/example/nodes/testcase_output.py +28 -0
- bumaren_agent_workflow-0.1.6/scenarios/example/prompts.py +122 -0
- bumaren_agent_workflow-0.1.6/scenarios/example/run.py +240 -0
- bumaren_agent_workflow-0.1.6/scenarios/example/schemas/state.py +73 -0
- bumaren_agent_workflow-0.1.6/scenarios/example/workflow.md +87 -0
- bumaren_agent_workflow-0.1.6/scenarios/example/workflow.py +70 -0
- bumaren_agent_workflow-0.1.6/setup.cfg +4 -0
- bumaren_agent_workflow-0.1.6/state/__init__.py +14 -0
- bumaren_agent_workflow-0.1.6/state/backends/__init__.py +12 -0
- bumaren_agent_workflow-0.1.6/state/backends/json_file.py +65 -0
- bumaren_agent_workflow-0.1.6/state/backends/memory.py +224 -0
- bumaren_agent_workflow-0.1.6/state/schema.py +283 -0
- bumaren_agent_workflow-0.1.6/state/store.py +51 -0
- bumaren_agent_workflow-0.1.6/tests/__init__.py +0 -0
- bumaren_agent_workflow-0.1.6/tests/agent/__init__.py +0 -0
- bumaren_agent_workflow-0.1.6/tests/agent/test_agent.py +260 -0
- bumaren_agent_workflow-0.1.6/tests/agent/test_memory.py +108 -0
- bumaren_agent_workflow-0.1.6/tests/agent/test_toolset.py +37 -0
- bumaren_agent_workflow-0.1.6/tests/engine/__init__.py +0 -0
- bumaren_agent_workflow-0.1.6/tests/engine/test_breaker.py +179 -0
- bumaren_agent_workflow-0.1.6/tests/engine/test_checkpoint.py +58 -0
- bumaren_agent_workflow-0.1.6/tests/engine/test_continuer.py +39 -0
- bumaren_agent_workflow-0.1.6/tests/engine/test_foreach.py +124 -0
- bumaren_agent_workflow-0.1.6/tests/engine/test_loop.py +328 -0
- bumaren_agent_workflow-0.1.6/tests/engine/test_sequence.py +36 -0
- bumaren_agent_workflow-0.1.6/tests/engine/test_stage.py +82 -0
- bumaren_agent_workflow-0.1.6/tests/engine/test_workflow.py +110 -0
- bumaren_agent_workflow-0.1.6/tests/llm/__init__.py +0 -0
- bumaren_agent_workflow-0.1.6/tests/llm/test_anthropic_provider.py +93 -0
- bumaren_agent_workflow-0.1.6/tests/llm/test_image_client.py +26 -0
- bumaren_agent_workflow-0.1.6/tests/llm/test_logging_client.py +85 -0
- bumaren_agent_workflow-0.1.6/tests/llm/test_message.py +29 -0
- bumaren_agent_workflow-0.1.6/tests/llm/test_openai_provider.py +54 -0
- bumaren_agent_workflow-0.1.6/tests/llm/test_zhipu_provider.py +168 -0
- bumaren_agent_workflow-0.1.6/tests/scenarios/__init__.py +0 -0
- bumaren_agent_workflow-0.1.6/tests/state/__init__.py +0 -0
- bumaren_agent_workflow-0.1.6/tests/state/test_json_file_backend.py +67 -0
- bumaren_agent_workflow-0.1.6/tests/state/test_memory_backend.py +123 -0
- bumaren_agent_workflow-0.1.6/tests/state/test_schema.py +214 -0
- bumaren_agent_workflow-0.1.6/tests/tools/__init__.py +0 -0
- bumaren_agent_workflow-0.1.6/tests/tools/test_executor.py +57 -0
- bumaren_agent_workflow-0.1.6/tests/tools/test_registry.py +65 -0
- bumaren_agent_workflow-0.1.6/tests/tools/test_schema.py +78 -0
- bumaren_agent_workflow-0.1.6/tools/__init__.py +15 -0
- bumaren_agent_workflow-0.1.6/tools/executor.py +47 -0
- bumaren_agent_workflow-0.1.6/tools/registry.py +72 -0
- bumaren_agent_workflow-0.1.6/tools/schema.py +122 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
id-token: write
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
name: Build distribution
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
with:
|
|
19
|
+
fetch-depth: 0
|
|
20
|
+
|
|
21
|
+
- uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: "3.12"
|
|
24
|
+
|
|
25
|
+
- name: Build package
|
|
26
|
+
run: python -m pip install --upgrade build && python -m build
|
|
27
|
+
|
|
28
|
+
- uses: actions/upload-artifact@v4
|
|
29
|
+
with:
|
|
30
|
+
name: python-package-distributions
|
|
31
|
+
path: dist/
|
|
32
|
+
|
|
33
|
+
publish:
|
|
34
|
+
name: Publish to PyPI
|
|
35
|
+
needs: build
|
|
36
|
+
runs-on: ubuntu-latest
|
|
37
|
+
environment:
|
|
38
|
+
name: pypi
|
|
39
|
+
url: https://pypi.org/p/bumaren-agent-workflow
|
|
40
|
+
permissions:
|
|
41
|
+
id-token: write
|
|
42
|
+
steps:
|
|
43
|
+
- uses: actions/download-artifact@v4
|
|
44
|
+
with:
|
|
45
|
+
name: python-package-distributions
|
|
46
|
+
path: dist/
|
|
47
|
+
|
|
48
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# 更新日志
|
|
2
|
+
|
|
3
|
+
本项目的版本记录遵循 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/) 格式,
|
|
4
|
+
版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
|
|
5
|
+
|
|
6
|
+
## [未发布]
|
|
7
|
+
|
|
8
|
+
## [0.1.1] - 2026-08-20
|
|
9
|
+
|
|
10
|
+
### 修复
|
|
11
|
+
- 同步 `pyproject.toml` 中的包版本到 `0.1.1`,使 PyPI 发布工作流的标签校验与发布标签一致。
|
|
12
|
+
|
|
13
|
+
## [0.1.0] - 2026-08-06
|
|
14
|
+
|
|
15
|
+
### 新增
|
|
16
|
+
- 框架层:`engine`(工作流引擎)、`agent`(能力挂载层)、`state`(共享状态)、
|
|
17
|
+
`llm`(LLM 抽象层)、`tools`(工具系统)。
|
|
18
|
+
- 控制流原语:`Sequence`、`Loop`、`ForEach`、`Checkpoint`、`Breaker`(提前终止)、
|
|
19
|
+
`Continuer`(驱动 Loop 重开下一轮)。
|
|
20
|
+
- 场景层挂载点 `scenarios/`,含 `scenarios/example/`(测试用例设计工作流)示例场景。
|
|
21
|
+
- 场景开发指南 [`scenarios/development-guide.md`](scenarios/development-guide.md)。
|
|
22
|
+
- 开源合规文件:`LICENSE`(MIT)、`CONTRIBUTING.md`、`CODE_OF_CONDUCT.md`。
|
|
23
|
+
|
|
24
|
+
[未发布]: https://github.com/BuMaRen/miniagent/compare/v0.1.1...HEAD
|
|
25
|
+
[0.1.1]: https://github.com/BuMaRen/miniagent/releases/tag/v0.1.1
|
|
26
|
+
[0.1.0]: https://github.com/BuMaRen/miniagent/releases/tag/v0.1.0
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# 贡献者公约(Contributor Covenant)行为准则
|
|
2
|
+
|
|
3
|
+
## 我们的承诺
|
|
4
|
+
|
|
5
|
+
身为社区成员、贡献者与维护者,我们承诺让每个人都能在无骚扰的环境下参与本项目,无论其年龄、体型、
|
|
6
|
+
可见或不可见的残疾、族裔、性别特征、性别认同与表达、经验水平、教育程度、社会经济地位、国籍、
|
|
7
|
+
个人外貌、种族、宗教信仰,或性取向与性认同为何。
|
|
8
|
+
|
|
9
|
+
我们承诺以有助于建立开放、友善、多元、包容、健康社区的方式行事和互动。
|
|
10
|
+
|
|
11
|
+
## 我们的准则
|
|
12
|
+
|
|
13
|
+
有助于营造积极环境的行为包括:
|
|
14
|
+
|
|
15
|
+
- 展现同理心与善意
|
|
16
|
+
- 尊重不同的观点、立场与经验
|
|
17
|
+
- 给予并优雅地接受建设性反馈
|
|
18
|
+
- 为自己的错误承担责任、向受影响者道歉,并从中学习
|
|
19
|
+
- 关注对社区整体最有利的事,而不仅是个人利益
|
|
20
|
+
|
|
21
|
+
不可接受的行为包括:
|
|
22
|
+
|
|
23
|
+
- 使用与性有关的语言或图像,以及任何形式的性骚扰
|
|
24
|
+
- 挑衅、侮辱性或贬损性的言论,以及人身或政治攻击
|
|
25
|
+
- 公开或私下的骚扰
|
|
26
|
+
- 未经明确许可,发布他人的私人信息(如实际地址或电子邮件地址)
|
|
27
|
+
- 在专业场合中可被合理认定为不当的其他行为
|
|
28
|
+
|
|
29
|
+
## 执行责任
|
|
30
|
+
|
|
31
|
+
项目维护者负责阐明并执行我们对可接受行为的标准,并会针对任何被认为不当、具威胁性、冒犯性或
|
|
32
|
+
有害的行为采取适当且公正的纠正措施。
|
|
33
|
+
|
|
34
|
+
维护者有权且有责任移除、编辑或拒绝与本准则不符的评论、提交(commit)、代码、wiki 编辑、
|
|
35
|
+
Issue 及其他贡献,并在适当时说明理由。
|
|
36
|
+
|
|
37
|
+
## 适用范围
|
|
38
|
+
|
|
39
|
+
本准则适用于项目所有的空间,也适用于个人在公共场合代表社区时的行为,例如使用官方邮箱、
|
|
40
|
+
通过官方社交媒体账号发帖,或在线上/线下活动中担任指定代表。
|
|
41
|
+
|
|
42
|
+
## 执行方式
|
|
43
|
+
|
|
44
|
+
如遇辱骂、骚扰或其他不可接受的行为,可通过 <masha961110@gmail.com> 向项目维护者举报。
|
|
45
|
+
所有投诉都将被及时、公正地审查与调查。
|
|
46
|
+
|
|
47
|
+
所有维护者都有义务尊重举报人的隐私与安全。
|
|
48
|
+
|
|
49
|
+
## 执行准则
|
|
50
|
+
|
|
51
|
+
项目维护者在判定违反本准则的行为后果时,将参考以下社区影响准则:
|
|
52
|
+
|
|
53
|
+
### 1. 纠正
|
|
54
|
+
|
|
55
|
+
**社区影响**:使用不当言语或其他被认为不专业或不受欢迎的行为。
|
|
56
|
+
|
|
57
|
+
**后果**:由维护者私下书面警告,说明违规性质并解释为何该行为不当,可能会要求公开道歉。
|
|
58
|
+
|
|
59
|
+
### 2. 警告
|
|
60
|
+
|
|
61
|
+
**社区影响**:单次或多次事件违规。
|
|
62
|
+
|
|
63
|
+
**后果**:警告并附带后续行为的相应后果。在指定时间内,不得与相关人员互动,包括主动与执行准则者
|
|
64
|
+
互动。违反此条款可能导致临时或永久封禁。
|
|
65
|
+
|
|
66
|
+
### 3. 临时封禁
|
|
67
|
+
|
|
68
|
+
**社区影响**:严重违反社区准则,包括持续的不当行为。
|
|
69
|
+
|
|
70
|
+
**后果**:在指定时间内,暂时禁止与社区进行任何形式的互动或公开交流。违反此条款可能导致永久封禁。
|
|
71
|
+
|
|
72
|
+
### 4. 永久封禁
|
|
73
|
+
|
|
74
|
+
**社区影响**:表现出违反社区准则的行为模式,包括持续的不当行为、骚扰个人,或对某类个人的攻击
|
|
75
|
+
或贬低。
|
|
76
|
+
|
|
77
|
+
**后果**:永久禁止在项目社区内进行任何形式的公开互动。
|
|
78
|
+
|
|
79
|
+
## 出处
|
|
80
|
+
|
|
81
|
+
本准则改编自 [Contributor Covenant](https://www.contributor-covenant.org) 2.1 版,
|
|
82
|
+
原文见 <https://www.contributor-covenant.org/version/2/1/code_of_conduct.html>。
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# 贡献指南
|
|
2
|
+
|
|
3
|
+
感谢你对 MiniAgent 感兴趣!在提交 Issue 或 PR 之前,请花几分钟阅读本指南。
|
|
4
|
+
|
|
5
|
+
## 项目定位
|
|
6
|
+
|
|
7
|
+
在动手之前,建议先读一遍 [README.md](README.md),
|
|
8
|
+
理解框架层(`engine`/`agent`/`state`/`llm`/`tools`)与场景层(`scenarios/`)的边界:
|
|
9
|
+
|
|
10
|
+
- **框架层**的改动应保持场景无关,任何看起来像"为了某个场景而加"的字段/分支,通常说明设计错了地方。
|
|
11
|
+
- **场景层**的改动(新增/扩展场景)不需要动框架结构,只需要拼装既有原语、开发对应 ToolSet。
|
|
12
|
+
|
|
13
|
+
## 开发环境
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
git clone https://github.com/BuMaRen/miniagent.git
|
|
17
|
+
cd miniagent
|
|
18
|
+
pip install -r requirements.txt
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
框架层测试仅依赖标准库 `unittest`:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
python3 -m unittest discover -s tests -t .
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 提交 Issue
|
|
28
|
+
|
|
29
|
+
- Bug 报告请附上复现步骤、期望行为与实际行为。
|
|
30
|
+
- 功能建议请先说明用例,尤其是"这属于框架层还是场景层",方便判断是否符合项目定位。
|
|
31
|
+
|
|
32
|
+
## 提交 Pull Request
|
|
33
|
+
|
|
34
|
+
1. Fork 仓库,基于 `main` 创建分支(建议命名 `feat/xxx`、`fix/xxx`)。
|
|
35
|
+
2. 改动前先确认涉及范围:框架结构改动请附带设计理由;场景/ToolSet 改动尽量自包含。
|
|
36
|
+
3. 提交前本地跑一遍测试,新增功能请补充对应的单元测试。
|
|
37
|
+
4. Commit message 遵循 [Conventional Commits](https://www.conventionalcommits.org/),例如:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
feat(engine): add retry policy to Loop primitive
|
|
41
|
+
fix(state): correct patch merge for nested paths
|
|
42
|
+
docs: update framework design doc section 8
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
5. PR 描述中说明改动动机(why)而不仅是改动内容(what),并关联相关 Issue。
|
|
46
|
+
|
|
47
|
+
## 代码风格
|
|
48
|
+
|
|
49
|
+
- Python 代码遵循项目现有风格,无强制 linter 配置时以可读性和与相邻代码一致为准。
|
|
50
|
+
- 避免为假设中的未来需求做设计;框架层的抽象改动请先在 Issue 中讨论。
|
|
51
|
+
|
|
52
|
+
## 许可
|
|
53
|
+
|
|
54
|
+
提交贡献即表示你同意你的代码以本项目的 [MIT License](LICENSE) 授权发布。
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BuMaRen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bumaren-agent-workflow
|
|
3
|
+
Version: 0.1.6
|
|
4
|
+
Summary: A reusable, scenario-agnostic AI workflow framework.
|
|
5
|
+
Author: BuMaRen
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 BuMaRen
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/BuMaRen/miniagent
|
|
29
|
+
Project-URL: Repository, https://github.com/BuMaRen/miniagent
|
|
30
|
+
Project-URL: Issues, https://github.com/BuMaRen/miniagent/issues
|
|
31
|
+
Classifier: Development Status :: 3 - Alpha
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Programming Language :: Python :: 3
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
38
|
+
Requires-Python: >=3.10
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
License-File: LICENSE
|
|
41
|
+
Requires-Dist: openai==1.68.2
|
|
42
|
+
Requires-Dist: anthropic==0.120.0
|
|
43
|
+
Requires-Dist: zai-sdk==0.2.3
|
|
44
|
+
Requires-Dist: pyyaml==6.0.3
|
|
45
|
+
Dynamic: license-file
|
|
46
|
+
|
|
47
|
+
# MiniAgent
|
|
48
|
+
|
|
49
|
+
[](LICENSE)
|
|
50
|
+
|
|
51
|
+
一个**与场景无关**的可复用 AI 工作流框架:提供 Stage(阶段)、ToolSet(能力挂载)、State Store(共享状态)、Loop(评审-修订循环)、ForEach(遍历子流程)、Checkpoint(人工断点)等通用构件。二次开发一个具体场景,通常只需要"定义 State Schema + 拼装这些原语 + 挂载/开发对应 ToolSet",而不需要重新设计流程结构。
|
|
52
|
+
|
|
53
|
+
当前已有一个示例场景用于验证这套抽象是否好用,具体内容见 [scenarios/development-guide.md](scenarios/development-guide.md)。二次开发/专业化某个场景时,预期的改动方式是打磨/扩充对应 Stage 上挂载的 ToolSet,而不是改动引擎结构。
|
|
54
|
+
|
|
55
|
+
## 项目定位
|
|
56
|
+
|
|
57
|
+
- **框架层**:Stage、ToolSet、State Store、Loop、ForEach、Checkpoint、Breaker、Continuer 等通用构件,不绑定任何具体场景,理论上可复用于代码审查、报告撰写等其他多阶段生成任务。这是二次开发时应该复用、不应该改动结构的部分。
|
|
58
|
+
- **场景层**:`scenarios/example/`(测试用例设计工作流)是当前用来验证这套抽象是否好用的具体实例——用框架原语拼出流程,并挂载场景专属的 ToolSet 与 State Schema。
|
|
59
|
+
|
|
60
|
+
## 项目结构
|
|
61
|
+
|
|
62
|
+
框架层(`engine`/`agent`/`state`/`llm`/`tools`)不含任何场景语义,场景层内容全部落在 `scenarios/` 下。
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
miniagent/
|
|
66
|
+
├── engine/ # 工作流引擎(框架核心,场景无关)
|
|
67
|
+
│ ├── stage.py # Stage:输入→输出契约 + Node 统一协议
|
|
68
|
+
│ ├── context.py # RunContext:运行期共享上下文 + 生命周期 hook
|
|
69
|
+
│ ├── workflow.py # Workflow:顶层节点编排 + 失败续跑(WorkflowFailure)
|
|
70
|
+
│ └── primitives/ # 控制流原语
|
|
71
|
+
│ ├── sequence.py # 顺序执行
|
|
72
|
+
│ ├── loop.py # 迭代:同一份输入反复跑 body,配合 Breaker/Continuer 判定退出/重开(含超限策略)
|
|
73
|
+
│ ├── foreach.py # 遍历子流程
|
|
74
|
+
│ ├── checkpoint.py # 人工断点(同步问答)
|
|
75
|
+
│ ├── breaker.py # 提前终止 Loop/ForEach(相当于 break)
|
|
76
|
+
│ └── continuer.py # 跳过本轮、从 body 头重开下一轮(仅对 Loop 生效,相当于 continue)
|
|
77
|
+
│
|
|
78
|
+
├── agent/ # 能力挂载层
|
|
79
|
+
│ ├── agent.py # Agent = LLM + 工具 + 工具集 + 记忆(agentic loop)
|
|
80
|
+
│ ├── toolset.py # ToolSet:一组 (func, schema)
|
|
81
|
+
│ └── memory.py # 对话记忆(短期,区别于 State Store)
|
|
82
|
+
│
|
|
83
|
+
├── state/ # 共享状态
|
|
84
|
+
│ ├── store.py # StateStore 抽象:get/patch/append/slice/snapshot
|
|
85
|
+
│ ├── schema.py # StateSchema:场景方定义字段与校验
|
|
86
|
+
│ └── backends/ # 内存后端 + JSON 文件后端(断点恢复)
|
|
87
|
+
│
|
|
88
|
+
├── llm/ # LLM 抽象层
|
|
89
|
+
│ ├── client.py # LLMClient 接口 + ChatResponse
|
|
90
|
+
│ ├── message.py # Message / ToolCall 标准结构
|
|
91
|
+
│ └── providers/ # OpenAI / Anthropic / 智谱(zai-sdk)实现
|
|
92
|
+
│
|
|
93
|
+
├── tools/ # 工具系统
|
|
94
|
+
│ ├── schema.py # ToolSchema + schema_from_func(自动生成)
|
|
95
|
+
│ ├── registry.py # ToolRegistry
|
|
96
|
+
│ └── executor.py # ToolExecutor(安全执行 + 异常回填)
|
|
97
|
+
│
|
|
98
|
+
└── scenarios/ # 场景层:二次开发挂载点(见 scenarios/development-guide.md)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
场景方直接用 Python 组合 `Stage` 与 `engine/primitives/` 下的控制流原语拼出
|
|
102
|
+
`Workflow`(见 `scenarios/example/workflow.py`),
|
|
103
|
+
不存在从 YAML 等声明式定义编译节点这一层——详见 [scenarios/development-guide.md](scenarios/development-guide.md)。
|
|
104
|
+
|
|
105
|
+
## 关键设计点
|
|
106
|
+
|
|
107
|
+
1. **Node 统一协议** — Stage 和各控制流原语都实现 `run(ctx, inputs)`,因此能任意嵌套(`ForEach` 的 body 可以是 `Loop`)。这是"用少量原语组合出任意流程"的基础。
|
|
108
|
+
2. **reads/writes 声明式** — Stage 显式声明需要读写的状态切片,既能只向 LLM 注入相关上下文(控制成本),又能做依赖分析(判断哪些 Stage 可并行)。
|
|
109
|
+
3. **Loop 的退出与超限策略** — 是否重开下一轮/提前结束由放进 body 里的普通 Node 决定:`Continuer` 相当于 `continue`(跳过本轮剩余节点,从 body 头重开),`Breaker` 相当于 `break`(终止最近的外层 Loop/ForEach)。判定逻辑放在场景自己的 Node 里,引擎不认识任何业务字段名;超限则有 `accept_last / escalate_to_checkpoint / raise` 三种策略,杜绝死循环。
|
|
110
|
+
4. **两种记忆分离** — `agent/memory.py` 是单次 Agent 运行内的短期对话记忆;`state/` 是跨 Stage 的长期结构化事实。用摘要保证连贯,用结构化状态保证事实一致,职责分开。
|
|
111
|
+
5. **能力通过 ToolSet 挂载,而非改结构** — 换场景/做专业化的预期改动是"换一套 ToolSet + 换一份 State Schema",Stage/Loop/ForEach 的骨架不动。
|
|
112
|
+
|
|
113
|
+
## 运行测试
|
|
114
|
+
|
|
115
|
+
框架层的单元测试在 `tests/`(镜像 `engine`/`agent`/`state`/`llm`/`tools` 的目录结构),只用标准库 `unittest`,无需额外依赖即可跑:
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
python3 -m unittest discover -s tests -t .
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`tests/llm/test_openai_provider.py`、`tests/llm/test_anthropic_provider.py`、`tests/llm/test_zhipu_provider.py` 覆盖三个 Provider 的消息格式转换;若未安装对应的 `openai`/`anthropic`/`zai-sdk`(`requirements.txt` 里的三个依赖),对应的文件会自动跳过而非报错。
|
|
122
|
+
|
|
123
|
+
## 安装
|
|
124
|
+
|
|
125
|
+
发布到 PyPI 后,在其他项目中安装:
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
pip install bumaren-agent-workflow
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
版本由 Git 标签自动生成;发布时推送形如 `v0.1.3` 的新标签即可:
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
git tag v0.1.3
|
|
135
|
+
git push origin v0.1.3
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
首次发布前,在 PyPI 的 `Publishing` 页面添加一个 pending Trusted Publisher:
|
|
139
|
+
owner 为 `BuMaRen`, repository 为 `miniagent`, workflow 为 `publish-pypi.yml`, environment
|
|
140
|
+
为 `pypi`。后续发布无需保存 PyPI token 到 GitHub Secrets。
|
|
141
|
+
|
|
142
|
+
## 二次开发一个新场景
|
|
143
|
+
|
|
144
|
+
参见 [scenarios/development-guide.md](scenarios/development-guide.md)。典型步骤:
|
|
145
|
+
|
|
146
|
+
1. 定义 `state_schema.py`(该场景要跨步骤追踪哪些事实,用 `state.schema.StateSchema` 直接构造)。
|
|
147
|
+
2. 开发 `toolsets/`(每个 Stage 需要的工具集,**主要工作量所在**)。
|
|
148
|
+
3. 写 `prompts.py`(每个 Agent 的提示词;共享片段提成模块级常量复用)。
|
|
149
|
+
4. 在 `nodes/` 下按业务分组,每个模块提供 `build_xxx_stage()` 函数:声明节点的 executor / reads / writes / output_schema / tools / prompt。
|
|
150
|
+
5. 在 `workflow.py` 的 `build_workflow()` 里用 `Sequence`/`Loop`/`ForEach`/`Checkpoint` 直接拼出流程。
|
|
151
|
+
6. 在 `run.py` 里组装 LLMClient / StateStore / RunContext 并运行。
|
|
152
|
+
|
|
153
|
+
参见 `scenarios/example/` 这一个完整范例。
|
|
154
|
+
|
|
155
|
+
## 文档
|
|
156
|
+
|
|
157
|
+
- [scenarios/development-guide.md](scenarios/development-guide.md) — **场景开发指南**:动手向导,一步步把框架构件拼成一个新场景
|
|
158
|
+
|
|
159
|
+
## 状态
|
|
160
|
+
|
|
161
|
+
v0.1.1:框架层(`tools/` → `llm/` → `state/` → `agent/` → `engine/`)与首个场景 `scenarios/example/`(测试用例设计工作流)均已实现,`tests/` 下有对应单元测试覆盖。
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# MiniAgent
|
|
2
|
+
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
|
|
5
|
+
一个**与场景无关**的可复用 AI 工作流框架:提供 Stage(阶段)、ToolSet(能力挂载)、State Store(共享状态)、Loop(评审-修订循环)、ForEach(遍历子流程)、Checkpoint(人工断点)等通用构件。二次开发一个具体场景,通常只需要"定义 State Schema + 拼装这些原语 + 挂载/开发对应 ToolSet",而不需要重新设计流程结构。
|
|
6
|
+
|
|
7
|
+
当前已有一个示例场景用于验证这套抽象是否好用,具体内容见 [scenarios/development-guide.md](scenarios/development-guide.md)。二次开发/专业化某个场景时,预期的改动方式是打磨/扩充对应 Stage 上挂载的 ToolSet,而不是改动引擎结构。
|
|
8
|
+
|
|
9
|
+
## 项目定位
|
|
10
|
+
|
|
11
|
+
- **框架层**:Stage、ToolSet、State Store、Loop、ForEach、Checkpoint、Breaker、Continuer 等通用构件,不绑定任何具体场景,理论上可复用于代码审查、报告撰写等其他多阶段生成任务。这是二次开发时应该复用、不应该改动结构的部分。
|
|
12
|
+
- **场景层**:`scenarios/example/`(测试用例设计工作流)是当前用来验证这套抽象是否好用的具体实例——用框架原语拼出流程,并挂载场景专属的 ToolSet 与 State Schema。
|
|
13
|
+
|
|
14
|
+
## 项目结构
|
|
15
|
+
|
|
16
|
+
框架层(`engine`/`agent`/`state`/`llm`/`tools`)不含任何场景语义,场景层内容全部落在 `scenarios/` 下。
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
miniagent/
|
|
20
|
+
├── engine/ # 工作流引擎(框架核心,场景无关)
|
|
21
|
+
│ ├── stage.py # Stage:输入→输出契约 + Node 统一协议
|
|
22
|
+
│ ├── context.py # RunContext:运行期共享上下文 + 生命周期 hook
|
|
23
|
+
│ ├── workflow.py # Workflow:顶层节点编排 + 失败续跑(WorkflowFailure)
|
|
24
|
+
│ └── primitives/ # 控制流原语
|
|
25
|
+
│ ├── sequence.py # 顺序执行
|
|
26
|
+
│ ├── loop.py # 迭代:同一份输入反复跑 body,配合 Breaker/Continuer 判定退出/重开(含超限策略)
|
|
27
|
+
│ ├── foreach.py # 遍历子流程
|
|
28
|
+
│ ├── checkpoint.py # 人工断点(同步问答)
|
|
29
|
+
│ ├── breaker.py # 提前终止 Loop/ForEach(相当于 break)
|
|
30
|
+
│ └── continuer.py # 跳过本轮、从 body 头重开下一轮(仅对 Loop 生效,相当于 continue)
|
|
31
|
+
│
|
|
32
|
+
├── agent/ # 能力挂载层
|
|
33
|
+
│ ├── agent.py # Agent = LLM + 工具 + 工具集 + 记忆(agentic loop)
|
|
34
|
+
│ ├── toolset.py # ToolSet:一组 (func, schema)
|
|
35
|
+
│ └── memory.py # 对话记忆(短期,区别于 State Store)
|
|
36
|
+
│
|
|
37
|
+
├── state/ # 共享状态
|
|
38
|
+
│ ├── store.py # StateStore 抽象:get/patch/append/slice/snapshot
|
|
39
|
+
│ ├── schema.py # StateSchema:场景方定义字段与校验
|
|
40
|
+
│ └── backends/ # 内存后端 + JSON 文件后端(断点恢复)
|
|
41
|
+
│
|
|
42
|
+
├── llm/ # LLM 抽象层
|
|
43
|
+
│ ├── client.py # LLMClient 接口 + ChatResponse
|
|
44
|
+
│ ├── message.py # Message / ToolCall 标准结构
|
|
45
|
+
│ └── providers/ # OpenAI / Anthropic / 智谱(zai-sdk)实现
|
|
46
|
+
│
|
|
47
|
+
├── tools/ # 工具系统
|
|
48
|
+
│ ├── schema.py # ToolSchema + schema_from_func(自动生成)
|
|
49
|
+
│ ├── registry.py # ToolRegistry
|
|
50
|
+
│ └── executor.py # ToolExecutor(安全执行 + 异常回填)
|
|
51
|
+
│
|
|
52
|
+
└── scenarios/ # 场景层:二次开发挂载点(见 scenarios/development-guide.md)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
场景方直接用 Python 组合 `Stage` 与 `engine/primitives/` 下的控制流原语拼出
|
|
56
|
+
`Workflow`(见 `scenarios/example/workflow.py`),
|
|
57
|
+
不存在从 YAML 等声明式定义编译节点这一层——详见 [scenarios/development-guide.md](scenarios/development-guide.md)。
|
|
58
|
+
|
|
59
|
+
## 关键设计点
|
|
60
|
+
|
|
61
|
+
1. **Node 统一协议** — Stage 和各控制流原语都实现 `run(ctx, inputs)`,因此能任意嵌套(`ForEach` 的 body 可以是 `Loop`)。这是"用少量原语组合出任意流程"的基础。
|
|
62
|
+
2. **reads/writes 声明式** — Stage 显式声明需要读写的状态切片,既能只向 LLM 注入相关上下文(控制成本),又能做依赖分析(判断哪些 Stage 可并行)。
|
|
63
|
+
3. **Loop 的退出与超限策略** — 是否重开下一轮/提前结束由放进 body 里的普通 Node 决定:`Continuer` 相当于 `continue`(跳过本轮剩余节点,从 body 头重开),`Breaker` 相当于 `break`(终止最近的外层 Loop/ForEach)。判定逻辑放在场景自己的 Node 里,引擎不认识任何业务字段名;超限则有 `accept_last / escalate_to_checkpoint / raise` 三种策略,杜绝死循环。
|
|
64
|
+
4. **两种记忆分离** — `agent/memory.py` 是单次 Agent 运行内的短期对话记忆;`state/` 是跨 Stage 的长期结构化事实。用摘要保证连贯,用结构化状态保证事实一致,职责分开。
|
|
65
|
+
5. **能力通过 ToolSet 挂载,而非改结构** — 换场景/做专业化的预期改动是"换一套 ToolSet + 换一份 State Schema",Stage/Loop/ForEach 的骨架不动。
|
|
66
|
+
|
|
67
|
+
## 运行测试
|
|
68
|
+
|
|
69
|
+
框架层的单元测试在 `tests/`(镜像 `engine`/`agent`/`state`/`llm`/`tools` 的目录结构),只用标准库 `unittest`,无需额外依赖即可跑:
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
python3 -m unittest discover -s tests -t .
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`tests/llm/test_openai_provider.py`、`tests/llm/test_anthropic_provider.py`、`tests/llm/test_zhipu_provider.py` 覆盖三个 Provider 的消息格式转换;若未安装对应的 `openai`/`anthropic`/`zai-sdk`(`requirements.txt` 里的三个依赖),对应的文件会自动跳过而非报错。
|
|
76
|
+
|
|
77
|
+
## 安装
|
|
78
|
+
|
|
79
|
+
发布到 PyPI 后,在其他项目中安装:
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
pip install bumaren-agent-workflow
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
版本由 Git 标签自动生成;发布时推送形如 `v0.1.3` 的新标签即可:
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
git tag v0.1.3
|
|
89
|
+
git push origin v0.1.3
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
首次发布前,在 PyPI 的 `Publishing` 页面添加一个 pending Trusted Publisher:
|
|
93
|
+
owner 为 `BuMaRen`, repository 为 `miniagent`, workflow 为 `publish-pypi.yml`, environment
|
|
94
|
+
为 `pypi`。后续发布无需保存 PyPI token 到 GitHub Secrets。
|
|
95
|
+
|
|
96
|
+
## 二次开发一个新场景
|
|
97
|
+
|
|
98
|
+
参见 [scenarios/development-guide.md](scenarios/development-guide.md)。典型步骤:
|
|
99
|
+
|
|
100
|
+
1. 定义 `state_schema.py`(该场景要跨步骤追踪哪些事实,用 `state.schema.StateSchema` 直接构造)。
|
|
101
|
+
2. 开发 `toolsets/`(每个 Stage 需要的工具集,**主要工作量所在**)。
|
|
102
|
+
3. 写 `prompts.py`(每个 Agent 的提示词;共享片段提成模块级常量复用)。
|
|
103
|
+
4. 在 `nodes/` 下按业务分组,每个模块提供 `build_xxx_stage()` 函数:声明节点的 executor / reads / writes / output_schema / tools / prompt。
|
|
104
|
+
5. 在 `workflow.py` 的 `build_workflow()` 里用 `Sequence`/`Loop`/`ForEach`/`Checkpoint` 直接拼出流程。
|
|
105
|
+
6. 在 `run.py` 里组装 LLMClient / StateStore / RunContext 并运行。
|
|
106
|
+
|
|
107
|
+
参见 `scenarios/example/` 这一个完整范例。
|
|
108
|
+
|
|
109
|
+
## 文档
|
|
110
|
+
|
|
111
|
+
- [scenarios/development-guide.md](scenarios/development-guide.md) — **场景开发指南**:动手向导,一步步把框架构件拼成一个新场景
|
|
112
|
+
|
|
113
|
+
## 状态
|
|
114
|
+
|
|
115
|
+
v0.1.1:框架层(`tools/` → `llm/` → `state/` → `agent/` → `engine/`)与首个场景 `scenarios/example/`(测试用例设计工作流)均已实现,`tests/` 下有对应单元测试覆盖。
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Agent 与 ToolSet —— 场景能力的挂载点。
|
|
2
|
+
|
|
3
|
+
Agent = LLM Client + ToolRegistry + ToolSets(工具集) + Memory。
|
|
4
|
+
它是 Stage 的典型执行体(executor)。给同一个抽象 Stage 挂载不同 ToolSet,
|
|
5
|
+
就得到不同场景下的能力——这正是"二次开发只需装 ToolSet"的核心机制。
|
|
6
|
+
|
|
7
|
+
注意:这里的 ToolSet 是代码装配期显示挂载的一组 (tool_func, schema),
|
|
8
|
+
与 Claude/OpenAI 的 "Skill"(运行时由模型自主发现/渐进式加载的磁盘目录)
|
|
9
|
+
是不同层次的概念,不要混用。
|
|
10
|
+
|
|
11
|
+
Agent —— 执行体:驱动一次 LLM + 工具调用循环完成 Stage
|
|
12
|
+
ToolSet —— 一组 (tool_func, schema),可加载进 Agent
|
|
13
|
+
ConversationMemory —— Agent 的对话记忆
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from agent.agent import Agent
|
|
17
|
+
from agent.toolset import ToolSet
|
|
18
|
+
from agent.memory import ConversationMemory
|
|
19
|
+
|
|
20
|
+
__all__ = ["Agent", "ToolSet", "ConversationMemory"]
|