Skip to main content

acps-math-retrace

数学错题归因与举一反三多智能体协作小工具 —— 基于 acps-sdk 2.1.0 构建的三智能体协作系统,把"盲目刷题"升级为"诊断错因 → 溯源考点 → 靶向巩固"的精准查漏补缺闭环。

命名含义

Retrace = Re(回溯归因)+ trace(溯源推演):

  • 向后 re-trace 学生的解题链路,定位错因根脉;
  • 向前 trace 出同类型变式,完成当场巩固。

acps- 前缀表明本项目构建于 ACPs 智能体平台协议(acps-sdk)之上,与同生态的多智能体应用保持一致的工程范式。

项目定位与价值

题海战术的痛点不在于"做得少",而在于"错了却不知道为什么错、错在哪个考点、接下来该练什么"。acps-math-retrace 用一组各司其职的 ACPs 智能体协作,替代低效率的人工复盘:

  • 中高考数学刷题复盘:学生提交一道错题的解题步骤与标准答案,系统秒级定位是算错、看错还是逻辑漏,并立刻给出 3 道同考点变式,避免"一错再错"。
  • 大学高数作业自查:对一元二次、二次函数等基础题型进行自检,把每一次错误都收敛到具体知识点,形成可追溯的知识图谱。
  • 教培 / 私教备课:教师批量导入错题,自动生成错因报告与分层变式题,减少重复性组卷劳动。

整个流程由 Leader(DiagnosisSession) 通过 AIP v2 协议编排三个独立部署的专家 Agent,每一步都留下可审计的 task 记录,而非单体脚本的"黑盒调用"。

三个协作 Agent

Agent 角色 技能标签 产物
Diagnoser Agent 错因诊断:逐行对齐学生步骤与标准答案,分类为计算错误 / 审题错误 / 逻辑漏洞 error-diagnosis diagnosis-report
Concept Tracer Agent 考点溯源:指明考查的核心知识点(如"韦达定理和判别式的综合运用"),并把错因映射回考点 concept-trace concept-trace-report
Generator Agent 举一反三:针对错因生成 3 道同类型、同难度变式题,附答案与解析 variant-generation variant-report

调度拓扑:Diagnoser → Concept Tracer → Generator → Leader(fan-in),Leader 通过 ADP 发现各 Agent 端点,用 AipRpcClient.start_task 派发任务并聚合 typed product。

安装

pip install acps-math-retrace

或从本地 wheel 安装:

pip install dist/acps_math_retrace-1.0.0-py3-none-any.whl

依赖:acps-sdk==2.1.0、fastapi、uvicorn、httpx、pydantic(纯 Python,可离线运行,无需任何 LLM API Key)。

一键运行(演示)

安装后一行命令启动完整多智能体协作(内置一道包含计算错误的韦达定理错题):

math-retrace demo

无需安装也可从源码一键运行:

python run_demo.py          # 等价于 math-retrace demo
# 或
python -m math_retrace demo

切换其它内置样例:

math-retrace demo --case 1   # 逻辑漏洞:证明实根时缺失判别式
math-retrace demo --case 2   # 二次函数顶点计算错误

分析自定义错题

math-retrace analyze \
  --problem "已知方程 x² − 5x + 6 = 0 的两根为 x₁、x₂,求 x₁² + x₂²。" \
  --student "x₁ + x₂ = 5,所以 x₁² + x₂² = 5。" \
  --standard "x₁ + x₂ = 5,x₁x₂ = 6;x₁² + x₂² = (x₁+x₂)² − 2x₁x₂ = 25 − 12 = 13。" \
  --answer "13"

程序化调用

import asyncio
from math_retrace.engine.samples import DEMO_PROBLEM
from math_retrace.mesh import LocalAgentMesh
from math_retrace.orchestrator import DiagnosisSession
from math_retrace.report import render_report

async def main():
    with LocalAgentMesh() as mesh:
        async with DiagnosisSession(mesh.registry) as session:
            report = await session.run(DEMO_PROBLEM)
    print(render_report(report))

asyncio.run(main())

运行测试

pip install -e ".[dev]"     # 安装 pytest 等开发依赖
pytest                       # 端到端:引擎断言 + 完整 AIP 往返 + 打包元数据

构建与发布到 PyPI

# 1. 构建 wheel 与 sdist(产物在 dist/)
python -m build

# 2. 校验产物
python -m twine check dist/*

# 3. 上传到 TestPyPI(先验证)
python -m twine upload --repository testpypi dist/*

# 4. 正式上传到 PyPI
python -m twine upload dist/*

上传需要 PyPI 账号与 API Token(在 https://pypi.org/manage/account/token/ 生成),并通过 keyring 或环境变量 TWINE_USERNAME/TWINE_PASSWORD 配置凭据,切勿把 Token 写入代码或命令历史。

预期输出(math-retrace demo)

下面是一次真实运行的输出(session / report / task id 与耗时每次运行不同,其余内容稳定):

[acps-math-retrace] 正在启动本地多智能体协作网格 ...
[acps-math-retrace] 在线 ACPs Agent: Diagnoser Agent, Concept Tracer Agent, Generator Agent
========================================================================================
ACPs Math Retrace v1.0.0 | session=math-...
端到端耗时 ... ms | report=report-... | SDK=acps-sdk 2.1.0
========================================================================================
[User] 错题题干:
已知关于 x 的一元二次方程 x² − (m+2)x + 2m = 0。
(1) 求证:无论 m 取何值,方程总有两个实数根;
(2) 若方程的两根为 x₁、x₂,且 x₁² + x₂² = 10,求 m 的值。

[1/3] Diagnoser Agent · 错因诊断
检测到 1 处错误,首要错因为【计算错误】——完全平方恒等变形符号错误。
问题 1:完全平方恒等变形符号错误  [计算错误]
  定位位置:第 3 步
  学生步骤:x₁² + x₂² = (x₁+x₂)² + 2x₁x₂ = (m+2)² + 4m = m² + 8m + 4。
  参考正解:x₁² + x₂² = (x₁+x₂)² − 2x₁x₂ = (m+2)² − 4m = m² + 4。
  修正方向:将 '+ 2x₁x₂' 改为 '− 2x₁x₂',即 x₁²+x₂² = (x₁+x₂)² − 2x₁x₂。
  置信度:92%
参考答案(标准解题步骤):
  1. Δ = (m+2)² − 4·1·2m = ... = (m−2)² ≥ 0,故方程总有两个实数根。
  2. 由韦达定理:x₁ + x₂ = m + 2,x₁x₂ = 2m。
  3. x₁² + x₂² = (x₁+x₂)² − 2x₁x₂ = ... = m² + 4。
  4. 由 m² + 4 = 10,得 m² = 6,故 m = √6 或 m = −√6。

[2/3] Concept Tracer Agent · 考点溯源
考点总结:本题考查了一元二次方程根的判别式与韦达定理的综合运用,并要求熟练运用完全平方公式对根的对称式进行恒等变形。
核心知识点:
  ★ 根的判别式 Δ = b² − 4ac
  ★ 韦达定理(根与系数的关系)
  ★ 完全平方恒等变形
错因→考点映射:学生的错误集中在“完全平方恒等变形”环节……

[3/3] Generator Agent · 举一反三变式巩固
针对【计算错误】——完全平方恒等变形符号错误 的靶向变式巩固(同类型、同难度,共 3 道)
变式 1:已知 ... x² − 7x + m = 0 ... 且 x₁² + x₂² = 29,求 m 的值。  → 答案:m = 10
变式 2:已知 ... x² − 7x + 10 = 0 ... 求 x₁² + x₂² 的值。              → 答案:x₁² + x₂² = 29
变式 3:已知 ... x² − 10x + 21 = 0 ... 求 |x₁ − x₂| 的值。           → 答案:|x₁ − x₂| = 4

AIP v2 协作审计
Diagnoser Agent      | error-diagnosis     | completed | ... ms | task=task-...
Concept Tracer Agent | concept-trace       | completed | ... ms | task=task-...
Generator Agent      | variant-generation  | completed | ... ms | task=task-...
调度拓扑:Diagnoser Agent → Concept Tracer Agent → Generator Agent → Leader
在线 Agent:Diagnoser Agent, Concept Tracer Agent, Generator Agent

项目结构

acps-math-retrace/
├── pyproject.toml              # 打包配置:name=acps-math-retrace, version=1.0.0, acps-sdk==2.1.0
├── README.md
├── LICENSE
├── run_demo.py                 # 一键运行入口(无需安装)
├── src/
│   └── math_retrace/
│       ├── __init__.py
│       ├── __main__.py         # python -m math_retrace
│       ├── cli.py              # math-retrace 命令行入口
│       ├── demo.py             # 一键演示编排
│       ├── identity.py         # AIC 身份与 ACS 能力描述
│       ├── registry.py         # 本地 ADP 能力注册与发现
│       ├── runtime.py          # AIP v2 传输:AgentServer / ResultBuilder / 产品编解码
│       ├── models.py           # 全部 typed product(DiagnosisReport 等)
│       ├── mesh.py             # LocalAgentMesh:启动并托管 3 个 Agent 服务
│       ├── orchestrator.py     # DiagnosisSession:Leader 编排与 fan-in
│       ├── report.py           # 终端可读报告渲染
│       ├── py.typed
│       ├── agents/
│       │   ├── base.py         # AipAgent 基类(AIP handler 契约)
│       │   ├── diagnoser.py    # Diagnoser Agent
│       │   ├── concept_tracer.py  # Concept Tracer Agent
│       │   └── generator.py    # Generator Agent
│       └── engine/             # 领域引擎(纯 Python,离线可运行)
│           ├── patterns.py     # 考点家族 / 错因模式 / 概念图谱注册表
│           ├── diagnosis.py    # 错因诊断引擎
│           ├── concepts.py     # 考点溯源引擎
│           ├── variants.py     # 变式生成引擎(算术保证答案正确)
│           └── samples.py      # 内置错题样例
└── tests/
    └── test_workflow.py        # 端到端测试

License

MIT

Metadata

Release files for acps-math-retrace 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for acps-math-retrace 1.0.0
File Size Uploaded Provenance Actions
acps_math_retrace-1.0.0.tar.gz 33.2 kB Without provenance Details for acps_math_retrace-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for acps-math-retrace 1.0.0
File Interpreter ABI Platform Actions
acps_math_retrace-1.0.0-py3-none-any.whl Python 3 none any Details for acps_math_retrace-1.0.0-py3-none-any.whl

Total release size: 72.5 kB

Release files / acps_math_retrace-1.0.0.tar.gz

Download URL acps_math_retrace-1.0.0.tar.gz
Size 33.2 kB
Tags Source
SHA-256 checksum
How to use checksums
590d1ca5b19af7d4d9bb6b8a60dc638413b5e2ff90ca36e9006b696b6fc7f284
BLAKE2b-256 checksum
How to use checksums
5433341e8a366d333121334bbe5fdf857503c0f447466059831dd9c6373ab62a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / acps_math_retrace-1.0.0-py3-none-any.whl

Download URL acps_math_retrace-1.0.0-py3-none-any.whl
Size 39.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3527a2d56e414a5da97ecfced0a347aaf0a9192eb9c545db55027724ceeb793e
BLAKE2b-256 checksum
How to use checksums
027073462ca1d3edb4094d84a5b5814dd7b78d20ebc5f750ab881c3595c6a734
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for acps-math-retrace 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page