Skip to main content

dynworkflow

dynworkflow 是一个 Python 3.12 库,用于编排动态工作流,工作流节点可以调用一个或多个 ACP Agent。

安装

使用项目包管理器安装:

uv sync

运行时依赖为 websockets,开发依赖包括 pytestmypy

快速开始

import dynworkflow as d

flow = d.Flow(
    "document-flow",
    agent=d.AgentClient("ws://127.0.0.1:7433/acp?k=a"),
)

@flow.node("summarize")
def summarize() -> d.TaskGenerator:
    result = yield d.Agent("Summarize the documents in docs/test", path="docs/test")
    return d.Result(result)

flow.execute(summarize())

使用 @flow.node(name) 声明节点。普通节点可以返回 NoneResult 或一个或多个下游 Execute 任务。生成器节点可以 yield AgentMultiAgent,接收 Agent 结果后返回节点结果。

公共 API

  • Flow:创建并执行工作流。
  • Flow.node(name):注册节点函数。
  • Flow.execute(*tasks):在当前进程中执行任务,并在所有节点结束后抛出节点异常。
  • Flow.run(*tasks):在 fork 子进程中运行工作流,并监听 stdin 中的 JSONL 控制命令。
  • Agent:描述一次 Agent 请求。
  • MultiAgent:并发运行多个 Agent 请求。
  • AgentClient:连接 ACP WebSocket 端点。
  • Result:保存节点的最终结果。

执行语义

  • 相互独立的节点会并发运行。
  • 节点失败后会立即变为 error 状态,并在启用上报时立即发送状态。
  • 失败节点不会停止兄弟节点。
  • 所有节点异常会在最后统一以 ExceptionGroup 抛出。
  • 节点和 Agent 的终止命令只影响指定目标;工作流关闭会终止整个工作流。

缓存与状态上报

缓存默认启用。可以使用 Flow(..., cache=False) 关闭缓存。缓存文件位于 .alkaid0/workflow.db;设置 ALKAID0_WORKFLOW_SESSION_ID 可以隔离不同会话。

可以通过 Flow(..., report=True) 或环境变量 ALKAID0_WORKFLOW_REPORT=1 开启 JSONL 状态上报。Flow.run() 会自动开启上报。事件包括 graphnodeagentagents_startnode_codenode_log

示例

参见 example.py,其中包含使用 AgentClientAgentMultiAgent、分支和回退参数的完整工作流示例。

测试

运行测试套件:

python -m pytest -q

运行静态编译检查:

python -m compileall -q src tests

文档索引

  • docs/SKILL.md:仅供 AI Agent 读取的使用说明,保持英文。
  • docs/architecture.md:面向人的实现与生命周期说明。
  • docs/protocol.md:stdin 控制命令和 JSONL 上报事件说明。
  • docs/test/ai_must_read.md:示例工作流读取的测试文档。

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dynworkflow-0.1.1.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dynworkflow-0.1.1-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file dynworkflow-0.1.1.tar.gz.

File metadata

  • Download URL: dynworkflow-0.1.1.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for dynworkflow-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b58e6feff851a9e1a4f750e4915006a3f0f7197d1f72e5e68bafbb0b60a56df8
MD5 4669001ab61427f132de7d4adf2ca507
BLAKE2b-256 1bd76c9aa7f1b9ae636c7d5e8d6b7a8a3b18eafaff252a00ba8c9cd705ef38e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for dynworkflow-0.1.1.tar.gz:

Publisher: python-publish.yml on cxykevin/dynworkflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dynworkflow-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: dynworkflow-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for dynworkflow-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 82761275dd766d21eb9512ad348cdab52253bac934b57b477ca8e2877bb780ed
MD5 385bab1db9f9d96c0a074ff085237772
BLAKE2b-256 375ee969b9e51171db70e7fcf6d2614e072bd54ae8dc431fe19577af78928886

See more details on using hashes here.

Provenance

The following attestation bundles were made for dynworkflow-0.1.1-py3-none-any.whl:

Publisher: python-publish.yml on cxykevin/dynworkflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page