mainspring-workflow
图编排与多 agent 外挂(T4-2):条件节点、并行 fan-out + reducer、supervisor、 agents-as-tools(委托)与 handoff(控制权转移)。只复用 core 的 Runner / Session / Hook / Tracing。
设计小节
- 工作流不是第二套 runtime:节点准备输入 → 调 core
Runner.run;会话/Hook/追踪全部随 Agent 与 Runner 走。 - 根 run 虚拟
wf_<hex>;子 run 用RunConfig.parent_run_id挂回根,OTel 父子与用量归集的唯一接缝。 - fan-out 分支各拿浅拷贝 state,
asyncio.gather+ 信号量(默认 50),reducer 按声明顺序聚合。 - 路由优先级:节点显式 next > 条件边 router > 静态边 > 隐式插入顺序;
max_steps防死循环。 - agents-as-tools = 委托取结果(专家独立会话、只带自己的工具,结论回填主线)。
- handoff = 控制权转移(工具只登记,编排层执行目标并丢弃调用者终答)。
- 子 agent 挂起(待审批)时工作流显式报错,不把 pending 当结论。
fan-out + reducer
from mainspring_workflow import FunctionNode, Workflow
wf = Workflow(runner=runner)
wf.add_parallel(
"research",
[FunctionNode(f"source-{i}", lambda state, i=i: state["input"] + f" via {i}") for i in range(50)],
reducer=lambda outs: "\n".join(outs),
)
result = await wf.run("调研主题")
print(result.usage) # 所有分支用量归集到根
supervisor
from mainspring_workflow import Supervisor
result = await Supervisor(dispatcher, [search_agent, writer_agent], runner=runner, max_rounds=5).run(task)
# result.worker_runs / result.handoffs 可审计;调度 agent 的终答只在它不再转交时生效
委托与 handoff
from mainspring_workflow import agent_as_tool, handoff_tool
parent = Agent(..., tools=[agent_as_tool(expert)]) # 委托:结论回到主线
caller = Agent(..., tools=[handoff_tool(expert)]) # 转移:调用者终答作废
验收覆盖(tests/test_workflow.py):条件路由、50 路并发 barrier、Session/Hook/Tracing 复用、
parent_run_id 全事件注入、Usage 归集、专家上下文隔离、handoff 覆盖终答、supervisor 轮次、循环护栏。
Metadata
Release files for mainspring-workflow 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mainspring_workflow-0.1.1.tar.gz | 11.9 kB | With provenance | Details for mainspring_workflow-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mainspring_workflow-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for mainspring_workflow-0.1.1-py3-none-any.whl |
Total release size: 27.2 kB
Release files / mainspring_workflow-0.1.1.tar.gz
| Download URL | mainspring_workflow-0.1.1.tar.gz |
|---|---|
| Size | 11.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6b218e73722e3e26ba8a9f633f688d50407036af6f6ec1dd5141be80aa76e81
|
|
BLAKE2b-256 checksum How to use checksums |
29ebf4c872021f8eec5d35915838d6fe73be41614747f976a715a1cbd35f1ced
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logRelease files / mainspring_workflow-0.1.1-py3-none-any.whl
| Download URL | mainspring_workflow-0.1.1-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4d46ec4b67d7fe66095a89556fa63d10692649d4c79f7ea4e56d6294991872c9
|
|
BLAKE2b-256 checksum How to use checksums |
41fc588a6db4751410ed221965e61c5a213c6e3d3593212811992d104d6483be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logSecurity for mainspring-workflow 0.1.1
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mainspring_workflow-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logA 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.