acps-math-multisolver 1.0.0__py3-none-any.whl
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.
- acps_math_multisolver-1.0.0.dist-info/METADATA +187 -0
- acps_math_multisolver-1.0.0.dist-info/RECORD +24 -0
- acps_math_multisolver-1.0.0.dist-info/WHEEL +5 -0
- acps_math_multisolver-1.0.0.dist-info/entry_points.txt +2 -0
- acps_math_multisolver-1.0.0.dist-info/top_level.txt +1 -0
- math_multisolver/__init__.py +6 -0
- math_multisolver/__main__.py +6 -0
- math_multisolver/agents/__init__.py +8 -0
- math_multisolver/agents/algebra.py +40 -0
- math_multisolver/agents/base.py +118 -0
- math_multisolver/agents/geometry.py +40 -0
- math_multisolver/agents/socratic.py +40 -0
- math_multisolver/cli.py +52 -0
- math_multisolver/demo.py +98 -0
- math_multisolver/engine/__init__.py +17 -0
- math_multisolver/engine/quadratic.py +169 -0
- math_multisolver/identity.py +79 -0
- math_multisolver/mesh.py +61 -0
- math_multisolver/models.py +103 -0
- math_multisolver/orchestrator.py +205 -0
- math_multisolver/py.typed +0 -0
- math_multisolver/registry.py +85 -0
- math_multisolver/report.py +90 -0
- math_multisolver/runtime.py +229 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: acps-math-multisolver
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: An acps-sdk 2.1.0 multi-agent workspace for exploring one mathematics problem through complementary paths. Algebra and Geometry agents solve in parallel; a Socratic agent turns both traces into progressive questions rather than premature answers. For Zhongkao/Gaokao finale problems, olympiad exploration and university proof seminars, it builds divergent thinking and auditable solution comparison. Includes a deterministic quadratic-function capstone and a local ACP mesh requiring no LLM API key.
|
|
5
|
+
Author: ACPs Math MultiSolver Engineering
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://pypi.org/project/acps-math-multisolver/
|
|
8
|
+
Keywords: acps-sdk,multi-agent,mathematics,multiple-solutions,socratic-tutoring,divergent-thinking,exam-preparation
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Education
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Education
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
Requires-Dist: acps-sdk==2.1.0
|
|
25
|
+
Requires-Dist: fastapi>=0.100.0
|
|
26
|
+
Requires-Dist: pydantic>=2.0.0
|
|
27
|
+
Requires-Dist: uvicorn>=0.27.0
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
31
|
+
Requires-Dist: ruff>=0.6.0; extra == "dev"
|
|
32
|
+
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
33
|
+
|
|
34
|
+
# acps-math-multisolver
|
|
35
|
+
|
|
36
|
+
**数学一题多解启发多智能体协作工具**:基于 `acps-sdk 2.1.0`,让 Algebra Agent 与 Geometry Agent 并行构造独立解法,再由 Socratic Agent 读取双路径产物,生成“共同表征 → 分岔探索 → 双路径贯通”的连续追问。每次求解都保留 ADP 发现、AIP 任务和结构化产物记录。
|
|
37
|
+
|
|
38
|
+
## 命名与定位
|
|
39
|
+
|
|
40
|
+
**MultiSolver = Multiple + Solver**:不是把同一提示词复制给多个模型,而是用不同数学表征解决同一问题。`acps-` 表示任务分发、能力发现与通信均基于 ACPs SDK;`math` 表明面向数学学习。
|
|
41
|
+
|
|
42
|
+
面向中高考压轴题、竞赛题研讨与大学证明题课堂,它把“看懂标准答案”改造成“比较多种路径、解释路径为何等价、在追问中自己重建关键一步”。苏格拉底导师只给问题与按需支架,不在问题链中直接报最终答案。
|
|
43
|
+
|
|
44
|
+
## 协作机制
|
|
45
|
+
|
|
46
|
+
```text
|
|
47
|
+
┌─ AIP task → Algebra Agent ─┐
|
|
48
|
+
Leader → ADP 能力发现 ───┤ ├─ typed products → Socratic Agent
|
|
49
|
+
└─ AIP task → Geometry Agent ┘ │
|
|
50
|
+
└─ 七轮问题链 → Leader fan-in
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
1. 三个 Agent 各自运行在独立的 loopback FastAPI/AIP v2 JSON-RPC 服务中,拥有合法 AIC 与 ACS 能力描述。
|
|
54
|
+
2. Leader 通过 `DiscoveryRequest` 和 `skills.tags` 过滤发现端点,使用 `AipRpcClient.start_task()` 并行派发给代数与几何 Agent。
|
|
55
|
+
3. 两个 `StructuredDataItem` 解法产品经 Pydantic 校验后,一起进入 Socratic Agent;结论不一致时导师拒绝生成启发,避免把错误路径教给学生。
|
|
56
|
+
4. 最终报告包含双解、启发记录、task ID、完成状态、耗时和在线 Agent,可审计而非单体函数伪装协作。
|
|
57
|
+
|
|
58
|
+
## 安装与一键演示
|
|
59
|
+
|
|
60
|
+
要求 Python 3.10+。在 PowerShell 中:
|
|
61
|
+
|
|
62
|
+
```powershell
|
|
63
|
+
cd acps-math-multisolver
|
|
64
|
+
python -m venv .venv
|
|
65
|
+
.\.venv\Scripts\python -m pip install -e ".[dev]"
|
|
66
|
+
.\.venv\Scripts\python run_demo.py
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
也可使用安装产生的命令:
|
|
70
|
+
|
|
71
|
+
```powershell
|
|
72
|
+
math-multisolver demo
|
|
73
|
+
math-multisolver demo --json # 完整 typed product,便于接入学习系统
|
|
74
|
+
math-multisolver tutor # 真人逐轮作答;:hint 支架,:quit 退出
|
|
75
|
+
math-multisolver --version # 1.0.0
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`run_demo.py` 自动模拟一名学生的七轮回答,但底层三个 Agent、ADP 发现、AIP 请求和结果回传均真实执行;无需 LLM API Key,也不需要外部服务。
|
|
79
|
+
|
|
80
|
+
### 自定义输入
|
|
81
|
+
|
|
82
|
+
```powershell
|
|
83
|
+
math-multisolver solve --problem "已知抛物线 y = -x² + 2x + 3 与 x 轴交于 A、B 两点(A 在 B 左侧),与 y 轴交于点 C。点 P 是抛物线弧 BC 上一动点(不与 B、C 重合)。(1) 求 A、B、C 的坐标;(2) 求 △PBC 面积的最大值及此时 P 的坐标。"
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
v1.0.0 内置经过验证的二次函数动点面积策略,用于可复现演示与协议集成;它不是伪装成通用数学 AI 的提示词包装器。未注册题型会明确报错,不会编造答案。新增题型时可扩展 `engine`,复用现有 ACP 编排与 typed contracts。
|
|
87
|
+
|
|
88
|
+
## 演示题与预期输出摘要
|
|
89
|
+
|
|
90
|
+
输入题:抛物线 `y=-x²+2x+3` 与 x 轴交于 A、B,与 y 轴交于 C;P 在弧 BC 上运动,求三个定点坐标以及 `△PBC` 面积最大值和对应 P。
|
|
91
|
+
|
|
92
|
+
```text
|
|
93
|
+
[acps-math-multisolver] 正在启动二次函数压轴题多解演示 ...
|
|
94
|
+
[acps-math-multisolver] 在线 Agent:Algebra Agent、Geometry Agent、Socratic Agent
|
|
95
|
+
========================================================================================
|
|
96
|
+
ACPs Math MultiSolver v1.0.0 | session=multisolve-...
|
|
97
|
+
SDK=acps-sdk 2.1.0 | 端到端耗时 ... ms | report=report-...
|
|
98
|
+
========================================================================================
|
|
99
|
+
[1/4] Algebra Agent · 代数路径:面积函数与配方
|
|
100
|
+
核心洞察:以动点横坐标为单变量,把面积转化为区间上的二次函数最值。
|
|
101
|
+
1. ... A(−1,0)、B(3,0);... C(0,3)。
|
|
102
|
+
2. 设 P(t,−t²+2t+3),其中 0<t<3。直线 BC 为 x+y−3=0。
|
|
103
|
+
4. S(t)=...=−3/2(t−3/2)²+27/8。
|
|
104
|
+
结论:最大面积为 27/8,此时 P(3/2,15/4)。
|
|
105
|
+
|
|
106
|
+
[2/4] Geometry Agent · 几何路径:平行线平移与相切
|
|
107
|
+
核心洞察:固定底边后,面积最大等价于高最大;最远平行线的临界状态是相切。
|
|
108
|
+
3. 作 l∥BC,设 l:x+y=k。... 临界位置是与抛物线相切,切点即所求 P。
|
|
109
|
+
4. ... 相切要求 Δ=...=21−4k=0,故 k=21/4。
|
|
110
|
+
结论:最大面积为 27/8,此时 P(3/2,15/4)。
|
|
111
|
+
|
|
112
|
+
[3/4] Socratic Agent · 连续追问启发
|
|
113
|
+
导师 1:在 P 移动时,BC 的长度会改变吗?若把 BC 作为底,真正变化的量是什么?
|
|
114
|
+
学生 1:BC 的长度不变;面积变化来自 P 到 BC 的高。
|
|
115
|
+
导师 5:如果作一条与 BC 平行的直线并向抛物线外侧平移,何时达到‘仍有公共点’的最后位置?
|
|
116
|
+
学生 5:平行线向外平移,即将离开抛物线时的临界位置是相切。
|
|
117
|
+
导师 7:代数面积函数的顶点与几何路径的切点重合,是巧合吗?它们共同刻画了什么事实?
|
|
118
|
+
学生 7:不是巧合;... 都在刻画同一个‘到 BC 的距离最大’。
|
|
119
|
+
|
|
120
|
+
[4/4] AIP v2 协作审计
|
|
121
|
+
Algebra Agent | algebra-solution | completed | ... ms | task=task-...
|
|
122
|
+
Geometry Agent | geometry-solution | completed | ... ms | task=task-...
|
|
123
|
+
Socratic Agent | socratic-guidance | completed | ... ms | task=task-...
|
|
124
|
+
调度拓扑:(Algebra Agent ∥ Geometry Agent) → Socratic Agent → Leader
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## 测试
|
|
128
|
+
|
|
129
|
+
```powershell
|
|
130
|
+
.\.venv\Scripts\python -m pytest
|
|
131
|
+
.\.venv\Scripts\python -m ruff check .
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
测试覆盖数学结果、区间条件、七轮启发不泄露最终答案、双路径一致性保护、不支持题型的失败行为,以及三个真实 AIP 任务的端到端往返。
|
|
135
|
+
|
|
136
|
+
## 构建 wheel 与上传 PyPI
|
|
137
|
+
|
|
138
|
+
```powershell
|
|
139
|
+
# 在开发虚拟环境中执行;构建 wheel 与 sdist 到 dist/
|
|
140
|
+
.\.venv\Scripts\python -m build
|
|
141
|
+
|
|
142
|
+
# 检查 METADATA、README 渲染与包描述
|
|
143
|
+
.\.venv\Scripts\python -m twine check dist/*
|
|
144
|
+
|
|
145
|
+
# 可选:先上传 TestPyPI 验证发布流程;密码提示中粘贴 TestPyPI API Token
|
|
146
|
+
.\.venv\Scripts\python -m twine upload --repository testpypi -u __token__ dist/*
|
|
147
|
+
|
|
148
|
+
# 正式发布;密码提示中粘贴 PyPI API Token
|
|
149
|
+
.\.venv\Scripts\python -m twine upload -u __token__ dist/*
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
不要把 API Token 写入代码、README 或命令历史。PyPI 不允许覆盖同版本文件;再次发布前必须提升 `pyproject.toml` 与 `identity.py` 中的版本号。上传是显式发布操作,本地构建和校验不会自动上传。
|
|
153
|
+
|
|
154
|
+
## 项目结构
|
|
155
|
+
|
|
156
|
+
```text
|
|
157
|
+
acps-math-multisolver/
|
|
158
|
+
├── pyproject.toml # 1.0.0、acps-sdk==2.1.0、CLI、构建与质量工具
|
|
159
|
+
├── README.md # 安装、交互、演示、测试和 PyPI 发布说明
|
|
160
|
+
├── run_demo.py # 源码目录一键演示
|
|
161
|
+
├── src/math_multisolver/
|
|
162
|
+
│ ├── __init__.py # 公共 API 与 __version__
|
|
163
|
+
│ ├── __main__.py # python -m math_multisolver
|
|
164
|
+
│ ├── cli.py # demo / solve / tutor
|
|
165
|
+
│ ├── models.py # AIP typed request/product/report
|
|
166
|
+
│ ├── identity.py # AIC、ACS 与项目版本
|
|
167
|
+
│ ├── registry.py # 基于 ADP 模型的能力注册与过滤发现
|
|
168
|
+
│ ├── runtime.py # AIP v2 服务、任务生命周期与产品编解码
|
|
169
|
+
│ ├── mesh.py # 三个独立 Agent 服务生命周期
|
|
170
|
+
│ ├── orchestrator.py # ADP 发现、并行 AIP 分发与 fan-in
|
|
171
|
+
│ ├── demo.py # 模拟对话、真人 tutor 与一键演示
|
|
172
|
+
│ ├── report.py # 双解、启发记录与审计渲染
|
|
173
|
+
│ ├── py.typed # PEP 561 类型标记
|
|
174
|
+
│ ├── agents/
|
|
175
|
+
│ │ ├── base.py # AIP handler 基类
|
|
176
|
+
│ │ ├── algebra.py # Algebra Agent
|
|
177
|
+
│ │ ├── geometry.py # Geometry Agent
|
|
178
|
+
│ │ └── socratic.py # Socratic Agent
|
|
179
|
+
│ └── engine/
|
|
180
|
+
│ ├── quadratic.py # 已验证双解与苏格拉底问题链
|
|
181
|
+
│ └── __init__.py
|
|
182
|
+
└── tests/test_workflow.py # 单元与真实 AIP 集成测试
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## License
|
|
186
|
+
|
|
187
|
+
MIT
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
math_multisolver/__init__.py,sha256=hm8X9JmIThJk-dck-O0WucRuLrOzPeoII4fcxB1bW8M,249
|
|
2
|
+
math_multisolver/__main__.py,sha256=18LKtOHEU2pmFVVmFcJfp_7oWA-l9mMELarQ5Wte7Vs,138
|
|
3
|
+
math_multisolver/cli.py,sha256=5s--0K48nxuzPvncD_PegNrzIfiyjc8bNrkXlaxQkDY,1956
|
|
4
|
+
math_multisolver/demo.py,sha256=619ZMT1AqKXG_fVcmr6llUlSKEgH0U9SG8uyU1bi5HM,3958
|
|
5
|
+
math_multisolver/identity.py,sha256=C45qgrqfiplmZAbOJTWMXOaAZPlB9G19-ayQpUMyGjM,2206
|
|
6
|
+
math_multisolver/mesh.py,sha256=tgWglNGEsZqXCpy8fOLy0klLkJ-4HqZ_qW-VQa3ciRY,1729
|
|
7
|
+
math_multisolver/models.py,sha256=-NrOuTUEWMvvaovy_eNc-CStFEG65tHeXeGxNE3VUSE,2482
|
|
8
|
+
math_multisolver/orchestrator.py,sha256=yipLNNmx86i9VwAFk-vkUIDordduDGu1t6DA2CvOrPk,6988
|
|
9
|
+
math_multisolver/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
math_multisolver/registry.py,sha256=_WSQb1u15l0q21Sw2DLnjqIC0RaVA_FCAEVLBWGu048,2982
|
|
11
|
+
math_multisolver/report.py,sha256=dKovhKVmcuzJWnV94EqdKzP6tKXTiN-zNCB2TERghSg,3126
|
|
12
|
+
math_multisolver/runtime.py,sha256=eqf9VFxCqeivM67nSwGqSq77tCVViQ2OYP0J8wPNW3o,6595
|
|
13
|
+
math_multisolver/agents/__init__.py,sha256=oeZ4bSUpkLfNYMlUrTBgmKWKkLviHE03k7SPmCZ487E,271
|
|
14
|
+
math_multisolver/agents/algebra.py,sha256=kJmH2LlusO8NtYEQ6g6sHFpK6LAZwb3K4Ld3ZmqX0IY,1599
|
|
15
|
+
math_multisolver/agents/base.py,sha256=NBHCjYesB2lV8LXEHkVAkGOBG1mL2qEgzVcDmiWVNXM,3890
|
|
16
|
+
math_multisolver/agents/geometry.py,sha256=nP-TX8k95iddRK7IebUlBT1mTJ1acbhtxV-nPkZV8jQ,1605
|
|
17
|
+
math_multisolver/agents/socratic.py,sha256=QpAMTZvB7YpzEhTnkBb9oQegyPuP4V-6Ycged6vQzK8,1631
|
|
18
|
+
math_multisolver/engine/__init__.py,sha256=tUmhLXl74Fy3VP1x9YE4xPeYpBwbXk26bwoAdtxfrAA,323
|
|
19
|
+
math_multisolver/engine/quadratic.py,sha256=8AyWn3afwgQlLqmAAfI0EbID1-IYOZqJEwJPSFPwVCk,8371
|
|
20
|
+
acps_math_multisolver-1.0.0.dist-info/METADATA,sha256=tWpmL9_0HjPps6BrzwYNQ6hY_vr6xBCKK-D4TnHzZio,10492
|
|
21
|
+
acps_math_multisolver-1.0.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
22
|
+
acps_math_multisolver-1.0.0.dist-info/entry_points.txt,sha256=9gU-8EPgQ0v2aXfiK9-nE2WYUkQkjeCUbIrYK8G0stc,63
|
|
23
|
+
acps_math_multisolver-1.0.0.dist-info/top_level.txt,sha256=5qj-UHe621NUFya2903d4nB7J2-EFAzpYiq_0qb1FUA,17
|
|
24
|
+
acps_math_multisolver-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
math_multisolver
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""The three ACPs specialists used by the MultiSolver mesh."""
|
|
2
|
+
|
|
3
|
+
from .algebra import AlgebraAgent
|
|
4
|
+
from .base import AipAgent
|
|
5
|
+
from .geometry import GeometryAgent
|
|
6
|
+
from .socratic import SocraticAgent
|
|
7
|
+
|
|
8
|
+
__all__ = ["AipAgent", "AlgebraAgent", "GeometryAgent", "SocraticAgent"]
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Algebra Agent: equations, functions and analytic representations."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from acps_sdk.aip import TaskCommand, TaskResult
|
|
6
|
+
from pydantic import ValidationError
|
|
7
|
+
|
|
8
|
+
from ..engine import algebra_solution
|
|
9
|
+
from ..models import SolveRequest
|
|
10
|
+
from ..runtime import PayloadError, decode_payload, first_text
|
|
11
|
+
from .base import AipAgent
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class AlgebraAgent(AipAgent):
|
|
15
|
+
name = "Algebra Agent"
|
|
16
|
+
description = "从方程、函数、判别式与代数恒等变形出发,构造可计算、可验证的解法。"
|
|
17
|
+
skill_id = "algebra-solution"
|
|
18
|
+
skill_name = "代数多解构造"
|
|
19
|
+
skill_description = (
|
|
20
|
+
"Construct a solution through equations, functions, discriminants and "
|
|
21
|
+
"analytic transformations, with explicit domain and verification checks."
|
|
22
|
+
)
|
|
23
|
+
tags = ("algebra-solution", "quadratic", "mathematics")
|
|
24
|
+
examples = ("将抛物线动点面积转化为单变量二次函数并求最值。",)
|
|
25
|
+
product_name = "algebra-solution"
|
|
26
|
+
|
|
27
|
+
def handle_start(self, command: TaskCommand, task: TaskResult) -> TaskResult:
|
|
28
|
+
try:
|
|
29
|
+
request = SolveRequest.model_validate(decode_payload(first_text(command)))
|
|
30
|
+
solution = algebra_solution(request)
|
|
31
|
+
except (PayloadError, ValidationError, ValueError) as exc:
|
|
32
|
+
return self.fail(task, f"Algebra Agent rejected the payload: {exc}")
|
|
33
|
+
return self.publish(
|
|
34
|
+
task,
|
|
35
|
+
solution.model_dump(mode="json"),
|
|
36
|
+
summary="代数路径完成:面积函数、定义域与顶点最值均已验证",
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
__all__ = ["AlgebraAgent"]
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""Base class for independently hosted AIP mathematics specialists."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from abc import ABC, abstractmethod
|
|
6
|
+
from collections.abc import Mapping
|
|
7
|
+
from typing import Any, ClassVar
|
|
8
|
+
|
|
9
|
+
from acps_sdk.acs import AgentCapabilitySpec, AgentSkill
|
|
10
|
+
from acps_sdk.aip import TaskCommand, TaskResult, TaskState
|
|
11
|
+
from acps_sdk.aip.aip_rpc_server import CommandHandlers, DefaultHandlers, TaskManager
|
|
12
|
+
|
|
13
|
+
from ..identity import PROJECT_VERSION, build_capability_spec
|
|
14
|
+
from ..runtime import TERMINAL_STATES, ResultBuilder
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class AipAgent(ABC):
|
|
18
|
+
"""One specialist exposing a single discoverable ACPs skill."""
|
|
19
|
+
|
|
20
|
+
name: ClassVar[str]
|
|
21
|
+
description: ClassVar[str]
|
|
22
|
+
skill_id: ClassVar[str]
|
|
23
|
+
skill_name: ClassVar[str]
|
|
24
|
+
skill_description: ClassVar[str]
|
|
25
|
+
tags: ClassVar[tuple[str, ...]]
|
|
26
|
+
examples: ClassVar[tuple[str, ...]] = ()
|
|
27
|
+
product_name: ClassVar[str]
|
|
28
|
+
|
|
29
|
+
def __init__(self, aic: str) -> None:
|
|
30
|
+
self.aic = aic
|
|
31
|
+
self.endpoint_url: str | None = None
|
|
32
|
+
self._result = ResultBuilder(aic)
|
|
33
|
+
|
|
34
|
+
def attach_endpoint(self, endpoint_url: str) -> None:
|
|
35
|
+
self.endpoint_url = endpoint_url
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def capability_spec(self) -> AgentCapabilitySpec:
|
|
39
|
+
if self.endpoint_url is None:
|
|
40
|
+
raise RuntimeError(f"{self.name} has no endpoint; start its server first")
|
|
41
|
+
skill = AgentSkill(
|
|
42
|
+
id=self.skill_id,
|
|
43
|
+
name=self.skill_name,
|
|
44
|
+
description=self.skill_description,
|
|
45
|
+
version=PROJECT_VERSION,
|
|
46
|
+
tags=list(self.tags),
|
|
47
|
+
examples=list(self.examples) or None,
|
|
48
|
+
input_modes=["text/plain", "application/json"],
|
|
49
|
+
output_modes=["application/json"],
|
|
50
|
+
)
|
|
51
|
+
return build_capability_spec(
|
|
52
|
+
aic=self.aic,
|
|
53
|
+
name=self.name,
|
|
54
|
+
description=self.description,
|
|
55
|
+
skill=skill,
|
|
56
|
+
endpoint_url=self.endpoint_url,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
def build_handlers(self) -> CommandHandlers:
|
|
60
|
+
return CommandHandlers(
|
|
61
|
+
on_start=self._on_start,
|
|
62
|
+
on_continue=self._on_continue,
|
|
63
|
+
on_cancel=self._on_cancel,
|
|
64
|
+
on_complete=self._on_complete,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
async def _on_start(
|
|
68
|
+
self,
|
|
69
|
+
command: TaskCommand,
|
|
70
|
+
task: TaskResult | None,
|
|
71
|
+
) -> TaskResult:
|
|
72
|
+
if task is not None:
|
|
73
|
+
return task
|
|
74
|
+
created = TaskManager.create_task(command)
|
|
75
|
+
created.senderId = self.aic
|
|
76
|
+
if command.sessionId:
|
|
77
|
+
created.sessionId = command.sessionId
|
|
78
|
+
return self.handle_start(command, created)
|
|
79
|
+
|
|
80
|
+
async def _on_continue(self, command: TaskCommand, task: TaskResult) -> TaskResult:
|
|
81
|
+
if task.status.state in TERMINAL_STATES:
|
|
82
|
+
return task
|
|
83
|
+
return self.fail(task, f"{self.name} does not accept continue commands")
|
|
84
|
+
|
|
85
|
+
async def _on_cancel(self, command: TaskCommand, task: TaskResult) -> TaskResult:
|
|
86
|
+
result = await DefaultHandlers.cancel(command, task)
|
|
87
|
+
result.senderId = self.aic
|
|
88
|
+
return result
|
|
89
|
+
|
|
90
|
+
async def _on_complete(self, command: TaskCommand, task: TaskResult) -> TaskResult:
|
|
91
|
+
result = await DefaultHandlers.complete(command, task)
|
|
92
|
+
result.senderId = self.aic
|
|
93
|
+
return result
|
|
94
|
+
|
|
95
|
+
@abstractmethod
|
|
96
|
+
def handle_start(self, command: TaskCommand, task: TaskResult) -> TaskResult:
|
|
97
|
+
"""Consume an AIP start command and return its terminal result."""
|
|
98
|
+
|
|
99
|
+
def publish(
|
|
100
|
+
self,
|
|
101
|
+
task: TaskResult,
|
|
102
|
+
payload: Mapping[str, Any],
|
|
103
|
+
*,
|
|
104
|
+
summary: str,
|
|
105
|
+
) -> TaskResult:
|
|
106
|
+
return self._result.publish(
|
|
107
|
+
task,
|
|
108
|
+
TaskState.Completed,
|
|
109
|
+
payload,
|
|
110
|
+
product_name=self.product_name,
|
|
111
|
+
summary=summary,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
def fail(self, task: TaskResult, message: str) -> TaskResult:
|
|
115
|
+
return self._result.fail(task, message)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
__all__ = ["AipAgent"]
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Geometry Agent: geometric meaning, auxiliary lines and tangency."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from acps_sdk.aip import TaskCommand, TaskResult
|
|
6
|
+
from pydantic import ValidationError
|
|
7
|
+
|
|
8
|
+
from ..engine import geometry_solution
|
|
9
|
+
from ..models import SolveRequest
|
|
10
|
+
from ..runtime import PayloadError, decode_payload, first_text
|
|
11
|
+
from .base import AipAgent
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class GeometryAgent(AipAgent):
|
|
15
|
+
name = "Geometry Agent"
|
|
16
|
+
description = "挖掘底高、距离、平行与相切等几何意义,提供数形结合的独立路径。"
|
|
17
|
+
skill_id = "geometry-solution"
|
|
18
|
+
skill_name = "几何多解构造"
|
|
19
|
+
skill_description = (
|
|
20
|
+
"Develop a visual solution through base-height relations, auxiliary "
|
|
21
|
+
"parallel lines, distance extrema and discriminant-based tangency."
|
|
22
|
+
)
|
|
23
|
+
tags = ("geometry-solution", "quadratic", "mathematics")
|
|
24
|
+
examples = ("平移底边的平行线,利用与抛物线相切的临界状态求最大高。",)
|
|
25
|
+
product_name = "geometry-solution"
|
|
26
|
+
|
|
27
|
+
def handle_start(self, command: TaskCommand, task: TaskResult) -> TaskResult:
|
|
28
|
+
try:
|
|
29
|
+
request = SolveRequest.model_validate(decode_payload(first_text(command)))
|
|
30
|
+
solution = geometry_solution(request)
|
|
31
|
+
except (PayloadError, ValidationError, ValueError) as exc:
|
|
32
|
+
return self.fail(task, f"Geometry Agent rejected the payload: {exc}")
|
|
33
|
+
return self.publish(
|
|
34
|
+
task,
|
|
35
|
+
solution.model_dump(mode="json"),
|
|
36
|
+
summary="几何路径完成:平行线相切、切点与最大距离均已验证",
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
__all__ = ["GeometryAgent"]
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Socratic Agent: progressive questioning grounded in both solution paths."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from acps_sdk.aip import TaskCommand, TaskResult
|
|
6
|
+
from pydantic import ValidationError
|
|
7
|
+
|
|
8
|
+
from ..engine import socratic_guide
|
|
9
|
+
from ..models import SocraticRequest
|
|
10
|
+
from ..runtime import PayloadError, decode_payload, first_text
|
|
11
|
+
from .base import AipAgent
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SocraticAgent(AipAgent):
|
|
15
|
+
name = "Socratic Agent"
|
|
16
|
+
description = "读取代数与几何产物,以连续追问、必要支架和双路径反思替代直接报答案。"
|
|
17
|
+
skill_id = "socratic-guidance"
|
|
18
|
+
skill_name = "苏格拉底式启发"
|
|
19
|
+
skill_description = (
|
|
20
|
+
"Transform verified algebra and geometry products into progressive "
|
|
21
|
+
"questions, lightweight scaffolds and a cross-path reflection."
|
|
22
|
+
)
|
|
23
|
+
tags = ("socratic-guidance", "tutoring", "mathematics")
|
|
24
|
+
examples = ("先追问固定量与变化量,再引导学生想到函数顶点或平行线相切。",)
|
|
25
|
+
product_name = "socratic-guide"
|
|
26
|
+
|
|
27
|
+
def handle_start(self, command: TaskCommand, task: TaskResult) -> TaskResult:
|
|
28
|
+
try:
|
|
29
|
+
request = SocraticRequest.model_validate(decode_payload(first_text(command)))
|
|
30
|
+
guide = socratic_guide(request)
|
|
31
|
+
except (PayloadError, ValidationError, ValueError) as exc:
|
|
32
|
+
return self.fail(task, f"Socratic Agent rejected the payload: {exc}")
|
|
33
|
+
return self.publish(
|
|
34
|
+
task,
|
|
35
|
+
guide.model_dump(mode="json"),
|
|
36
|
+
summary=f"基于双路径生成 {len(guide.turns)} 轮渐进追问,未直接泄露最终答案",
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
__all__ = ["SocraticAgent"]
|
math_multisolver/cli.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Command-line entry points for the mathematics multi-agent tool."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import asyncio
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from .demo import run_analysis, run_demo, run_tutor
|
|
10
|
+
from .identity import PROJECT_VERSION
|
|
11
|
+
from .models import SolveRequest
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _build_parser() -> argparse.ArgumentParser:
|
|
15
|
+
parser = argparse.ArgumentParser(
|
|
16
|
+
prog="math-multisolver",
|
|
17
|
+
description=(
|
|
18
|
+
"数学一题多解与苏格拉底启发多智能体工具 "
|
|
19
|
+
"(Algebra ∥ Geometry → Socratic, acps-sdk 2.1.0)"
|
|
20
|
+
),
|
|
21
|
+
)
|
|
22
|
+
parser.add_argument("--version", action="version", version=PROJECT_VERSION)
|
|
23
|
+
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
24
|
+
|
|
25
|
+
demo = subparsers.add_parser("demo", help="一键演示二次函数压轴题双解与模拟启发对话")
|
|
26
|
+
demo.add_argument("--json", action="store_true", help="以 JSON 输出完整结构化报告")
|
|
27
|
+
|
|
28
|
+
solve = subparsers.add_parser("solve", help="求解受支持题目并输出双路径与问题链")
|
|
29
|
+
solve.add_argument("--problem", required=True, help="完整题目文本")
|
|
30
|
+
solve.add_argument("--json", action="store_true", help="以 JSON 输出完整结构化报告")
|
|
31
|
+
|
|
32
|
+
subparsers.add_parser("tutor", help="真实逐轮苏格拉底启发;:hint 提示,:reveal 查看解析")
|
|
33
|
+
return parser
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def main(argv: list[str] | None = None) -> int:
|
|
37
|
+
parser = _build_parser()
|
|
38
|
+
args = parser.parse_args(argv)
|
|
39
|
+
try:
|
|
40
|
+
if args.command == "demo":
|
|
41
|
+
return asyncio.run(run_demo(as_json=args.json))
|
|
42
|
+
if args.command == "tutor":
|
|
43
|
+
return asyncio.run(run_tutor())
|
|
44
|
+
request = SolveRequest(problem=args.problem)
|
|
45
|
+
return asyncio.run(run_analysis(request, as_json=args.json))
|
|
46
|
+
except (LookupError, RuntimeError, ValueError) as exc:
|
|
47
|
+
print(f"math-multisolver: {exc}", file=sys.stderr)
|
|
48
|
+
return 1
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if __name__ == "__main__":
|
|
52
|
+
raise SystemExit(main())
|
math_multisolver/demo.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""One-command, API-key-free demonstration and interactive tutoring."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
from .engine import DEMO_REQUEST
|
|
8
|
+
from .mesh import LocalAgentMesh
|
|
9
|
+
from .models import DialogueTurn, MultiSolveReport, SolveRequest
|
|
10
|
+
from .orchestrator import MultiSolveSession
|
|
11
|
+
from .report import render_report
|
|
12
|
+
|
|
13
|
+
SCRIPTED_RESPONSES = (
|
|
14
|
+
"BC 的长度不变;面积变化来自 P 到 BC 的高。",
|
|
15
|
+
"不能保证。纵坐标垂直于 x 轴,而三角形的高必须垂直于斜线 BC。",
|
|
16
|
+
"设 P(t,−t²+2t+3),先求 BC 方程,再用底高公式和点到直线距离公式表示 S(t)。",
|
|
17
|
+
"还要检查顶点横坐标是否属于 0<t<3,不能只看抛物线整体。",
|
|
18
|
+
"平行线向外平移,即将离开抛物线时的临界位置是相切。",
|
|
19
|
+
"相切意味着两个交点重合,所以联立后的一元二次方程判别式为零。",
|
|
20
|
+
"不是巧合;面积函数顶点与平行线切点都在刻画同一个‘到 BC 的距离最大’。",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
async def solve(request: SolveRequest) -> MultiSolveReport:
|
|
25
|
+
"""Start a local mesh and run one complete ACP collaboration session."""
|
|
26
|
+
|
|
27
|
+
with LocalAgentMesh() as mesh:
|
|
28
|
+
async with MultiSolveSession(mesh.registry) as session:
|
|
29
|
+
return await session.run(request)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
async def run_analysis(request: SolveRequest, *, as_json: bool = False) -> int:
|
|
33
|
+
"""Run the team for one problem and print its structured report."""
|
|
34
|
+
|
|
35
|
+
print("[acps-math-multisolver] 正在启动本地 ACP 多智能体网格 ...")
|
|
36
|
+
report = await solve(request)
|
|
37
|
+
print("[acps-math-multisolver] 在线 Agent:" + "、".join(report.agents_online))
|
|
38
|
+
_print_report(report, as_json=as_json)
|
|
39
|
+
return 0
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
async def run_demo(*, as_json: bool = False) -> int:
|
|
43
|
+
"""Simulate a learner's answers while executing real AIP agent tasks."""
|
|
44
|
+
|
|
45
|
+
print("[acps-math-multisolver] 正在启动二次函数压轴题多解演示 ...")
|
|
46
|
+
report = await solve(DEMO_REQUEST)
|
|
47
|
+
report.dialogue = [
|
|
48
|
+
DialogueTurn(
|
|
49
|
+
number=turn.number,
|
|
50
|
+
question=turn.question,
|
|
51
|
+
learner_response=response,
|
|
52
|
+
tutor_reply=turn.acknowledgement,
|
|
53
|
+
)
|
|
54
|
+
for turn, response in zip(report.socratic.turns, SCRIPTED_RESPONSES, strict=True)
|
|
55
|
+
]
|
|
56
|
+
print("[acps-math-multisolver] 在线 Agent:" + "、".join(report.agents_online))
|
|
57
|
+
_print_report(report, as_json=as_json)
|
|
58
|
+
return 0
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
async def run_tutor() -> int:
|
|
62
|
+
"""Ask real questions; reveal a scaffold only when the learner requests it."""
|
|
63
|
+
|
|
64
|
+
print("[acps-math-multisolver] Socratic Agent 正在读取双路径产物 ...\n")
|
|
65
|
+
report = await solve(DEMO_REQUEST)
|
|
66
|
+
print("题目:\n" + report.problem)
|
|
67
|
+
print("\n输入 :hint 获取一层支架,输入 :quit 结束启发。")
|
|
68
|
+
for turn in report.socratic.turns:
|
|
69
|
+
print(f"\n[Socratic Agent · 第 {turn.number} 问] {turn.question}")
|
|
70
|
+
response = input("你的思考> ").strip()
|
|
71
|
+
if response == ":quit":
|
|
72
|
+
break
|
|
73
|
+
if response == ":hint":
|
|
74
|
+
print(f"支架(不是答案):{turn.scaffold}")
|
|
75
|
+
response = input("再想一想> ").strip()
|
|
76
|
+
report.dialogue.append(
|
|
77
|
+
DialogueTurn(
|
|
78
|
+
number=turn.number,
|
|
79
|
+
question=turn.question,
|
|
80
|
+
learner_response=response,
|
|
81
|
+
tutor_reply=turn.acknowledgement,
|
|
82
|
+
)
|
|
83
|
+
)
|
|
84
|
+
print(f"导师反馈:{turn.acknowledgement}")
|
|
85
|
+
print("\n" + report.socratic.reflection)
|
|
86
|
+
if input("\n输入 :reveal 查看双路径完整解析,其它键退出> ").strip() == ":reveal":
|
|
87
|
+
print(render_report(report, show_socratic=False))
|
|
88
|
+
return 0
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _print_report(report: MultiSolveReport, *, as_json: bool) -> None:
|
|
92
|
+
if as_json:
|
|
93
|
+
print(json.dumps(report.model_dump(mode="json"), ensure_ascii=False, indent=2))
|
|
94
|
+
else:
|
|
95
|
+
print(render_report(report))
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
__all__ = ["run_analysis", "run_demo", "run_tutor", "solve"]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Verified domain strategies for the local multi-agent runtime."""
|
|
2
|
+
|
|
3
|
+
from .quadratic import (
|
|
4
|
+
DEMO_PROBLEM,
|
|
5
|
+
DEMO_REQUEST,
|
|
6
|
+
algebra_solution,
|
|
7
|
+
geometry_solution,
|
|
8
|
+
socratic_guide,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"DEMO_PROBLEM",
|
|
13
|
+
"DEMO_REQUEST",
|
|
14
|
+
"algebra_solution",
|
|
15
|
+
"geometry_solution",
|
|
16
|
+
"socratic_guide",
|
|
17
|
+
]
|