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.0.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.0-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dynworkflow-0.1.0.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dynworkflow-0.1.0.tar.gz
Algorithm Hash digest
SHA256 db23e0cec7b4d30be36ec00c97bb0f440f6de5b0a79a08d1b16f4f1838e83ec7
MD5 71317f6b23a27da90de682464b34dec5
BLAKE2b-256 9463c0af54b95e3aa3fa40ae818d8724df9f2822c54ea3a696d978b0abb8ba0e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dynworkflow-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dynworkflow-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2fb8c40ebc5d2c986e819ed0eca6ce40bf5198270888998248ca1111e82d6b8c
MD5 a046472776bd812b7900e47ae9b92992
BLAKE2b-256 79d5f5745e0931d3223822ac353e2558e587ff098df03ff3c0aad83bcabf7cf3

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

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