workflow-exec-engine 0.0.3__tar.gz → 0.1.0__tar.gz
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.
- workflow_exec_engine-0.1.0/PKG-INFO +161 -0
- workflow_exec_engine-0.1.0/README.md +127 -0
- workflow_exec_engine-0.1.0/README_en.md +119 -0
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/examples/execute_psop_demo.py +33 -15
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/examples/quickstart.py +100 -97
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/pyproject.toml +24 -12
- workflow_exec_engine-0.0.3/workflow_exec_engine.egg-info/requires.txt → workflow_exec_engine-0.1.0/requirements.txt +2 -2
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/setup.cfg +4 -4
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_engine/__init__.py +28 -21
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_engine/client/__init__.py +31 -31
- workflow_exec_engine-0.1.0/workflow_engine/client/a2a_transport.py +790 -0
- workflow_exec_engine-0.1.0/workflow_engine/client/a2at_messages.py +92 -0
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_engine/client/agentcard_normalizer.py +101 -106
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_engine/client/auth_manager.py +91 -81
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_engine/client/auth_provider.py +4 -3
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_engine/client/credential_crypto.py +23 -11
- workflow_exec_engine-0.1.0/workflow_engine/client/credential_service.py +360 -0
- workflow_exec_engine-0.1.0/workflow_engine/client/engine_client.py +459 -0
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_engine/client/extension_interceptor.py +8 -10
- workflow_exec_engine-0.1.0/workflow_engine/client/extension_sender.py +244 -0
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_engine/client/extensions.py +13 -5
- workflow_exec_engine-0.1.0/workflow_engine/client/protocol_interceptor.py +43 -0
- workflow_exec_engine-0.1.0/workflow_engine/client/protocol_logger.py +76 -0
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_engine/client/sse_normalization.py +90 -87
- workflow_exec_engine-0.1.0/workflow_engine/client/ssl_context.py +78 -0
- workflow_exec_engine-0.1.0/workflow_engine/client/stub_engine_client.py +80 -0
- workflow_exec_engine-0.1.0/workflow_engine/control/control_points.py +126 -0
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_engine/core/__init__.py +32 -25
- workflow_exec_engine-0.1.0/workflow_engine/core/context_builder.py +85 -0
- workflow_exec_engine-0.1.0/workflow_engine/core/executor.py +368 -0
- workflow_exec_engine-0.1.0/workflow_engine/core/failure_mapping.py +59 -0
- workflow_exec_engine-0.1.0/workflow_engine/core/models.py +533 -0
- workflow_exec_engine-0.1.0/workflow_engine/core/workflow_validator.py +144 -0
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_engine/registry/registry_client.py +165 -177
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_engine/runner.py +267 -246
- workflow_exec_engine-0.1.0/workflow_exec_engine.egg-info/PKG-INFO +161 -0
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_exec_engine.egg-info/SOURCES.txt +4 -1
- workflow_exec_engine-0.1.0/workflow_exec_engine.egg-info/requires.txt +12 -0
- workflow_exec_engine-0.0.3/PKG-INFO +0 -309
- workflow_exec_engine-0.0.3/README.md +0 -279
- workflow_exec_engine-0.0.3/README_en.md +0 -279
- workflow_exec_engine-0.0.3/requirements.txt +0 -6
- workflow_exec_engine-0.0.3/workflow_engine/client/a2a_transport.py +0 -560
- workflow_exec_engine-0.0.3/workflow_engine/client/credential_service.py +0 -229
- workflow_exec_engine-0.0.3/workflow_engine/client/engine_client.py +0 -374
- workflow_exec_engine-0.0.3/workflow_engine/client/extension_handlers.py +0 -203
- workflow_exec_engine-0.0.3/workflow_engine/client/extension_sender.py +0 -203
- workflow_exec_engine-0.0.3/workflow_engine/client/protocol_logger.py +0 -78
- workflow_exec_engine-0.0.3/workflow_engine/client/ssl_context.py +0 -84
- workflow_exec_engine-0.0.3/workflow_engine/client/stub_engine_client.py +0 -68
- workflow_exec_engine-0.0.3/workflow_engine/control/control_points.py +0 -223
- workflow_exec_engine-0.0.3/workflow_engine/core/context_builder.py +0 -101
- workflow_exec_engine-0.0.3/workflow_engine/core/executor.py +0 -278
- workflow_exec_engine-0.0.3/workflow_engine/core/models.py +0 -184
- workflow_exec_engine-0.0.3/workflow_exec_engine.egg-info/PKG-INFO +0 -309
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/LICENSE +0 -0
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/MANIFEST.in +0 -0
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_engine/client/env_file_loader.py +0 -0
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_engine/control/__init__.py +0 -0
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_engine/registry/__init__.py +0 -0
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_exec_engine.egg-info/dependency_links.txt +0 -0
- {workflow_exec_engine-0.0.3 → workflow_exec_engine-0.1.0}/workflow_exec_engine.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: workflow-exec-engine
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Standalone workflow execution SDK for A2A-T multi-agent orchestration
|
|
5
|
+
Author-email: A2A SDK Team <ivo.zhou@huawei.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/project-openan/workflow-engine-sdk-python
|
|
8
|
+
Project-URL: Documentation, https://github.com/project-openan/workflow-engine-sdk-python#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/project-openan/workflow-engine-sdk-python
|
|
10
|
+
Project-URL: Issues, https://github.com/project-openan/workflow-engine-sdk-python/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/project-openan/workflow-engine-sdk-python/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: a2a,agent,orchestration,workflow,sdk
|
|
13
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
19
|
+
Requires-Python: >=3.12
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: a2a-sdk<2,>=1.1.2
|
|
23
|
+
Requires-Dist: a2a-t-sdk<2,>=1.0.9
|
|
24
|
+
Requires-Dist: httpx>=0.27.0
|
|
25
|
+
Requires-Dist: loguru>=0.7.0
|
|
26
|
+
Requires-Dist: protobuf>=4.25.0
|
|
27
|
+
Requires-Dist: packaging>=23.0
|
|
28
|
+
Requires-Dist: cryptography>=42.0.0
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: build>=1.2.0; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# A2A-T Workflow Engine SDK(Python)
|
|
36
|
+
|
|
37
|
+
面向宿主智能体的嵌入式工作流执行引擎。引擎负责工作流 DAG、A2A 消息封装、任务与会话关联、远端任务等待、Negotiation-T 交互循环和生命周期;宿主负责业务输入解释、A2A-T 内容生成与语义校验,以及路由和协商决策。
|
|
38
|
+
|
|
39
|
+
Python 与 Java 版本遵循同一业务契约。Python 当前要求 Python 3.12+、`a2a-sdk>=1.1.2,<2` 和 `a2a-t-sdk>=1.0.9,<2`。
|
|
40
|
+
|
|
41
|
+
## 安装
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
python -m pip install workflow-exec-engine
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
执行引擎直接使用最新版 A2A-T core 元数据类型识别协议,但不会调用 LLM,也不会替宿主生成或校验 Task-T、Negotiation-T、Authorization-T、Notification-T 的业务内容;这些内容操作仍由宿主调用 `a2a-t-sdk` 完成。
|
|
48
|
+
|
|
49
|
+
## 最小集成
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from a2a.types import Part
|
|
53
|
+
from a2a_t.client import A2ATClient
|
|
54
|
+
from a2a_t.core.standard_templates import PRIVATE_LINE_COMPLAINT_URI
|
|
55
|
+
from workflow_engine import (
|
|
56
|
+
A2ATransport, A2atMessages, ControlPoint, ExtensionSender,
|
|
57
|
+
MessageContent, NegotiationReply, RouteDecision, TaskResult,
|
|
58
|
+
WorkflowEngineClient, WorkflowExecutor,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class BusinessCallbacks(ControlPoint):
|
|
63
|
+
async def on_task(self, request):
|
|
64
|
+
# a2a-t-sdk 负责内容生成;执行引擎只接收生成结果并发送。
|
|
65
|
+
generated = a2at.generate_task_prompt_from_text(
|
|
66
|
+
request.input.text,
|
|
67
|
+
PRIVATE_LINE_COMPLAINT_URI,
|
|
68
|
+
)
|
|
69
|
+
return A2atMessages.from_generated(
|
|
70
|
+
generated,
|
|
71
|
+
[Part(text=request.instruction)],
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
async def on_self_task(self, request):
|
|
75
|
+
outputs = aggregate(request.workflow_input.upstream_results)
|
|
76
|
+
return TaskResult.succeeded(outputs)
|
|
77
|
+
|
|
78
|
+
async def on_route(self, request):
|
|
79
|
+
# 每条非空条件边独立调用;允许多条边同时返回 true。
|
|
80
|
+
return RouteDecision.allow() if matches(request.condition) else RouteDecision.deny()
|
|
81
|
+
|
|
82
|
+
async def on_negotiation(self, request):
|
|
83
|
+
generated = generate_terminal_negotiation_reply_with_a2at(request)
|
|
84
|
+
return NegotiationReply.send(
|
|
85
|
+
A2atMessages.from_generated(generated, [Part(text="补充后的业务内容")])
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
a2at = A2ATClient(env_path=a2at_env_path)
|
|
90
|
+
transport = A2ATransport(agent_cards=agent_cards)
|
|
91
|
+
client = WorkflowEngineClient(transport)
|
|
92
|
+
result = await WorkflowExecutor(workflow, BusinessCallbacks(), client).run()
|
|
93
|
+
await transport.close()
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`on_task` 不接收客户端对象,也不自行发送消息。这样业务代码只负责最终内容,引擎统一保证 A2A 信封、上下文 ID、远端任务 ID、协议头和后续协商仍属于同一次任务交互。
|
|
97
|
+
|
|
98
|
+
## 路由规则
|
|
99
|
+
|
|
100
|
+
- 空条件边:无需调用 `on_route`,默认放行。
|
|
101
|
+
- 非空条件边:每条边独立调用一次 `on_route(RouteRequest)`。
|
|
102
|
+
- 一个节点可激活 0 到 N 条后继边;全部拒绝表示该分支正常结束。
|
|
103
|
+
- 同一节点的全部条件判断完成后才调度后继节点;任一判断异常时不调度任何后继节点。
|
|
104
|
+
|
|
105
|
+
## 上游结果
|
|
106
|
+
|
|
107
|
+
引擎不再把前置结果拼成 `Runtime Context` Markdown。回调通过 `request.workflow_input` 获取:
|
|
108
|
+
|
|
109
|
+
- `runtime_intent`:本次执行的运行时意图;
|
|
110
|
+
- `upstream_results`:按步骤分组的上游任务结果;
|
|
111
|
+
- 每个任务结果包含有序 `outputs`、来源 Agent/skill、逻辑任务 ID、状态和安全错误信息。
|
|
112
|
+
|
|
113
|
+
工作流的 `context_from` 控制聚合范围:省略时使用直接前驱,`["*"]` 使用全部祖先,空列表表示不传上游结果,指定名称时仅传对应祖先步骤。
|
|
114
|
+
|
|
115
|
+
## 独立协议操作
|
|
116
|
+
|
|
117
|
+
Authorization-T 和 Notification-T 不属于工作流因果链,应使用独立 `A2ATransport` 和 `ExtensionSender`:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
sender = ExtensionSender(independent_transport)
|
|
121
|
+
authorization = await sender.send_authorization(agent_name, authorization_content)
|
|
122
|
+
|
|
123
|
+
subscription = sender.open_notification(agent_name, notification_content, on_notification)
|
|
124
|
+
ack = await subscription.acknowledgement
|
|
125
|
+
# 收到业务结果后由集成方显式关闭:
|
|
126
|
+
subscription.close()
|
|
127
|
+
await subscription.completion
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
授权或订阅失败不会自动阻断后续工作流。`send_authorization` 会等待授权任务到达终态,集成方通过 `is_success` 判断结果;订阅确认通过 `is_failure` 排除失败、拒绝或取消。订阅确认与长连接结束是两个不同 Future;`heartbeat` 和 `is_healthy()` 可用于本地存活性判断。
|
|
131
|
+
|
|
132
|
+
## 远端任务管理
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
await client.get_task(agent_name, task_id)
|
|
136
|
+
page = await client.list_tasks(agent_name, list_tasks_request)
|
|
137
|
+
await client.cancel_task(agent_name, task_id)
|
|
138
|
+
await client.subscribe_to_task(agent_name, task_id, on_event)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
这些是标准 A2A 任务接口;取消任务不等同于 Negotiation-T Abort。
|
|
142
|
+
|
|
143
|
+
同一个 `WorkflowEngineClient` 同一时刻只能绑定一个工作流执行;并发执行应创建独立 client。协商在本地停止、超时、取消或协议校验失败时,引擎会对已知远端任务做有界的尽力取消,取消失败只记录日志,不覆盖原始错误。
|
|
144
|
+
|
|
145
|
+
## 认证与 TLS
|
|
146
|
+
|
|
147
|
+
`A2ATransport` 支持 AgentCard 声明的凭据配置、自定义 `AuthProvider`、自定义 CA、mTLS 客户端证书、CRL、协议偏好和发送超时。默认验证服务端证书;指定的证书文件缺失或无效时启动失败,不会静默降级为不校验。
|
|
148
|
+
|
|
149
|
+
仅受控开发环境可显式配置 `ssl_verify=False`。调用方传入的 `httpx.AsyncClient` 仍由调用方关闭;执行引擎只关闭自己创建的客户端资源。
|
|
150
|
+
|
|
151
|
+
## 文档与验证
|
|
152
|
+
|
|
153
|
+
- [设计说明](DESIGN.md)
|
|
154
|
+
- [集成开发指南](DEVELOPER_GUIDE.md)
|
|
155
|
+
- [英文 README](README_en.md)
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
python -m pip install -e ".[dev]"
|
|
159
|
+
python -m pytest -q
|
|
160
|
+
python -m build
|
|
161
|
+
```
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# A2A-T Workflow Engine SDK(Python)
|
|
2
|
+
|
|
3
|
+
面向宿主智能体的嵌入式工作流执行引擎。引擎负责工作流 DAG、A2A 消息封装、任务与会话关联、远端任务等待、Negotiation-T 交互循环和生命周期;宿主负责业务输入解释、A2A-T 内容生成与语义校验,以及路由和协商决策。
|
|
4
|
+
|
|
5
|
+
Python 与 Java 版本遵循同一业务契约。Python 当前要求 Python 3.12+、`a2a-sdk>=1.1.2,<2` 和 `a2a-t-sdk>=1.0.9,<2`。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
python -m pip install workflow-exec-engine
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
执行引擎直接使用最新版 A2A-T core 元数据类型识别协议,但不会调用 LLM,也不会替宿主生成或校验 Task-T、Negotiation-T、Authorization-T、Notification-T 的业务内容;这些内容操作仍由宿主调用 `a2a-t-sdk` 完成。
|
|
14
|
+
|
|
15
|
+
## 最小集成
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from a2a.types import Part
|
|
19
|
+
from a2a_t.client import A2ATClient
|
|
20
|
+
from a2a_t.core.standard_templates import PRIVATE_LINE_COMPLAINT_URI
|
|
21
|
+
from workflow_engine import (
|
|
22
|
+
A2ATransport, A2atMessages, ControlPoint, ExtensionSender,
|
|
23
|
+
MessageContent, NegotiationReply, RouteDecision, TaskResult,
|
|
24
|
+
WorkflowEngineClient, WorkflowExecutor,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class BusinessCallbacks(ControlPoint):
|
|
29
|
+
async def on_task(self, request):
|
|
30
|
+
# a2a-t-sdk 负责内容生成;执行引擎只接收生成结果并发送。
|
|
31
|
+
generated = a2at.generate_task_prompt_from_text(
|
|
32
|
+
request.input.text,
|
|
33
|
+
PRIVATE_LINE_COMPLAINT_URI,
|
|
34
|
+
)
|
|
35
|
+
return A2atMessages.from_generated(
|
|
36
|
+
generated,
|
|
37
|
+
[Part(text=request.instruction)],
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
async def on_self_task(self, request):
|
|
41
|
+
outputs = aggregate(request.workflow_input.upstream_results)
|
|
42
|
+
return TaskResult.succeeded(outputs)
|
|
43
|
+
|
|
44
|
+
async def on_route(self, request):
|
|
45
|
+
# 每条非空条件边独立调用;允许多条边同时返回 true。
|
|
46
|
+
return RouteDecision.allow() if matches(request.condition) else RouteDecision.deny()
|
|
47
|
+
|
|
48
|
+
async def on_negotiation(self, request):
|
|
49
|
+
generated = generate_terminal_negotiation_reply_with_a2at(request)
|
|
50
|
+
return NegotiationReply.send(
|
|
51
|
+
A2atMessages.from_generated(generated, [Part(text="补充后的业务内容")])
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
a2at = A2ATClient(env_path=a2at_env_path)
|
|
56
|
+
transport = A2ATransport(agent_cards=agent_cards)
|
|
57
|
+
client = WorkflowEngineClient(transport)
|
|
58
|
+
result = await WorkflowExecutor(workflow, BusinessCallbacks(), client).run()
|
|
59
|
+
await transport.close()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`on_task` 不接收客户端对象,也不自行发送消息。这样业务代码只负责最终内容,引擎统一保证 A2A 信封、上下文 ID、远端任务 ID、协议头和后续协商仍属于同一次任务交互。
|
|
63
|
+
|
|
64
|
+
## 路由规则
|
|
65
|
+
|
|
66
|
+
- 空条件边:无需调用 `on_route`,默认放行。
|
|
67
|
+
- 非空条件边:每条边独立调用一次 `on_route(RouteRequest)`。
|
|
68
|
+
- 一个节点可激活 0 到 N 条后继边;全部拒绝表示该分支正常结束。
|
|
69
|
+
- 同一节点的全部条件判断完成后才调度后继节点;任一判断异常时不调度任何后继节点。
|
|
70
|
+
|
|
71
|
+
## 上游结果
|
|
72
|
+
|
|
73
|
+
引擎不再把前置结果拼成 `Runtime Context` Markdown。回调通过 `request.workflow_input` 获取:
|
|
74
|
+
|
|
75
|
+
- `runtime_intent`:本次执行的运行时意图;
|
|
76
|
+
- `upstream_results`:按步骤分组的上游任务结果;
|
|
77
|
+
- 每个任务结果包含有序 `outputs`、来源 Agent/skill、逻辑任务 ID、状态和安全错误信息。
|
|
78
|
+
|
|
79
|
+
工作流的 `context_from` 控制聚合范围:省略时使用直接前驱,`["*"]` 使用全部祖先,空列表表示不传上游结果,指定名称时仅传对应祖先步骤。
|
|
80
|
+
|
|
81
|
+
## 独立协议操作
|
|
82
|
+
|
|
83
|
+
Authorization-T 和 Notification-T 不属于工作流因果链,应使用独立 `A2ATransport` 和 `ExtensionSender`:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
sender = ExtensionSender(independent_transport)
|
|
87
|
+
authorization = await sender.send_authorization(agent_name, authorization_content)
|
|
88
|
+
|
|
89
|
+
subscription = sender.open_notification(agent_name, notification_content, on_notification)
|
|
90
|
+
ack = await subscription.acknowledgement
|
|
91
|
+
# 收到业务结果后由集成方显式关闭:
|
|
92
|
+
subscription.close()
|
|
93
|
+
await subscription.completion
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
授权或订阅失败不会自动阻断后续工作流。`send_authorization` 会等待授权任务到达终态,集成方通过 `is_success` 判断结果;订阅确认通过 `is_failure` 排除失败、拒绝或取消。订阅确认与长连接结束是两个不同 Future;`heartbeat` 和 `is_healthy()` 可用于本地存活性判断。
|
|
97
|
+
|
|
98
|
+
## 远端任务管理
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
await client.get_task(agent_name, task_id)
|
|
102
|
+
page = await client.list_tasks(agent_name, list_tasks_request)
|
|
103
|
+
await client.cancel_task(agent_name, task_id)
|
|
104
|
+
await client.subscribe_to_task(agent_name, task_id, on_event)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
这些是标准 A2A 任务接口;取消任务不等同于 Negotiation-T Abort。
|
|
108
|
+
|
|
109
|
+
同一个 `WorkflowEngineClient` 同一时刻只能绑定一个工作流执行;并发执行应创建独立 client。协商在本地停止、超时、取消或协议校验失败时,引擎会对已知远端任务做有界的尽力取消,取消失败只记录日志,不覆盖原始错误。
|
|
110
|
+
|
|
111
|
+
## 认证与 TLS
|
|
112
|
+
|
|
113
|
+
`A2ATransport` 支持 AgentCard 声明的凭据配置、自定义 `AuthProvider`、自定义 CA、mTLS 客户端证书、CRL、协议偏好和发送超时。默认验证服务端证书;指定的证书文件缺失或无效时启动失败,不会静默降级为不校验。
|
|
114
|
+
|
|
115
|
+
仅受控开发环境可显式配置 `ssl_verify=False`。调用方传入的 `httpx.AsyncClient` 仍由调用方关闭;执行引擎只关闭自己创建的客户端资源。
|
|
116
|
+
|
|
117
|
+
## 文档与验证
|
|
118
|
+
|
|
119
|
+
- [设计说明](DESIGN.md)
|
|
120
|
+
- [集成开发指南](DEVELOPER_GUIDE.md)
|
|
121
|
+
- [英文 README](README_en.md)
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
python -m pip install -e ".[dev]"
|
|
125
|
+
python -m pytest -q
|
|
126
|
+
python -m build
|
|
127
|
+
```
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# A2A-T Workflow Engine SDK for Python
|
|
2
|
+
|
|
3
|
+
An embedded workflow execution SDK for host agents. The engine owns workflow DAG execution, A2A envelopes, task/context correlation, remote-task waiting, the Negotiation-T interaction loop, and lifecycle management. The host owns business-input interpretation, A2A-T content generation and semantic validation, routing, and negotiation decisions.
|
|
4
|
+
|
|
5
|
+
The Python and Java engines follow the same business contract. This package requires Python 3.12+, `a2a-sdk>=1.1.2,<2`, and `a2a-t-sdk>=1.1.0,<2`.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
python -m pip install workflow-exec-engine
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The engine uses the current A2A-T core metadata types for protocol coordination. It does not call an LLM or generate or validate Task-T, Negotiation-T, Authorization-T, or Notification-T business content; the host still invokes `a2a-t-sdk` for those content operations.
|
|
14
|
+
|
|
15
|
+
## Minimal integration
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from a2a.types import Part
|
|
19
|
+
from a2a_t.client import A2ATClient
|
|
20
|
+
from a2a_t.core.standard_templates import PRIVATE_LINE_COMPLAINT_URI
|
|
21
|
+
from workflow_engine import (
|
|
22
|
+
A2ATransport, A2atMessages, ControlPoint, ExtensionSender,
|
|
23
|
+
MessageContent, NegotiationReply, RouteDecision, TaskResult,
|
|
24
|
+
WorkflowEngineClient, WorkflowExecutor,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class BusinessCallbacks(ControlPoint):
|
|
29
|
+
async def on_task(self, request):
|
|
30
|
+
generated = a2at.generate_task_prompt_from_text(
|
|
31
|
+
request.input.text,
|
|
32
|
+
PRIVATE_LINE_COMPLAINT_URI,
|
|
33
|
+
)
|
|
34
|
+
return A2atMessages.from_generated(
|
|
35
|
+
generated,
|
|
36
|
+
[Part(text=request.instruction)],
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
async def on_self_task(self, request):
|
|
40
|
+
return TaskResult.succeeded(aggregate(request.workflow_input.upstream_results))
|
|
41
|
+
|
|
42
|
+
async def on_route(self, request):
|
|
43
|
+
return RouteDecision.allow() if matches(request.condition) else RouteDecision.deny()
|
|
44
|
+
|
|
45
|
+
async def on_negotiation(self, request):
|
|
46
|
+
generated = generate_terminal_negotiation_reply_with_a2at(request)
|
|
47
|
+
return NegotiationReply.send(
|
|
48
|
+
A2atMessages.from_generated(generated, [Part(text="supplemented content")])
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
a2at = A2ATClient(env_path=a2at_env_path)
|
|
53
|
+
transport = A2ATransport(agent_cards=agent_cards)
|
|
54
|
+
client = WorkflowEngineClient(transport)
|
|
55
|
+
result = await WorkflowExecutor(workflow, BusinessCallbacks(), client).run()
|
|
56
|
+
await transport.close()
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`on_task` does not receive a transport client and does not send the message. The host prepares final content; the engine keeps the A2A envelope, context ID, remote task ID, headers, waiting, and subsequent negotiation in one interaction.
|
|
60
|
+
|
|
61
|
+
## Routing contract
|
|
62
|
+
|
|
63
|
+
- A blank condition is unconditional, bypasses `on_route`, and is allowed.
|
|
64
|
+
- Every nonblank edge gets one independent `on_route(RouteRequest)` call.
|
|
65
|
+
- A node may activate zero through N successors; all denied means a normal branch end.
|
|
66
|
+
- All decisions for the source node finish before successors are scheduled. If one decision fails, no successor of that source is scheduled.
|
|
67
|
+
|
|
68
|
+
## Upstream results
|
|
69
|
+
|
|
70
|
+
The engine no longer renders predecessor output into a `Runtime Context` Markdown string. Callbacks receive `request.workflow_input` with the runtime intent and ordered, step-scoped upstream task results. Each task result carries outputs, source agent/skill, logical task ID, status, and safe failure information.
|
|
71
|
+
|
|
72
|
+
`context_from` selects the history window: omission selects direct predecessors, `["*"]` selects every ancestor, an empty list selects none, and named entries select only those ancestor steps.
|
|
73
|
+
|
|
74
|
+
## Independent protocol operations
|
|
75
|
+
|
|
76
|
+
Authorization-T and Notification-T are independent of workflow causality. Give them a separate `A2ATransport` and `ExtensionSender`:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
sender = ExtensionSender(independent_transport)
|
|
80
|
+
authorization = await sender.send_authorization(agent_name, authorization_content)
|
|
81
|
+
|
|
82
|
+
subscription = sender.open_notification(agent_name, notification_content, on_notification)
|
|
83
|
+
ack = await subscription.acknowledgement
|
|
84
|
+
subscription.close()
|
|
85
|
+
await subscription.completion
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Authorization or subscription failure does not automatically block workflow execution. `send_authorization` waits for a final task state and the caller checks `is_success`; a subscription acknowledgement must be rejected when `is_failure` is true. A subscription acknowledgement and stream completion are separate futures. Use `heartbeat` and `is_healthy()` for local liveness checks.
|
|
89
|
+
|
|
90
|
+
## Remote task management
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
await client.get_task(agent_name, task_id)
|
|
94
|
+
page = await client.list_tasks(agent_name, list_tasks_request)
|
|
95
|
+
await client.cancel_task(agent_name, task_id)
|
|
96
|
+
await client.subscribe_to_task(agent_name, task_id, on_event)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
These are standard A2A task operations. Task cancellation is not a Negotiation-T Abort.
|
|
100
|
+
|
|
101
|
+
A `WorkflowEngineClient` can be bound to only one active workflow execution at a time; concurrent executions require separate clients. When negotiation ends locally because of stop, timeout, cancellation, or protocol validation failure, the engine makes a bounded best-effort cancellation of a known remote task without replacing the original error.
|
|
102
|
+
|
|
103
|
+
## Authentication and TLS
|
|
104
|
+
|
|
105
|
+
`A2ATransport` supports AgentCard-driven credential configuration, a host `AuthProvider`, custom CA trust, mTLS client identity, CRL checks, protocol preference, and send timeout. Server certificates are verified by default. Missing or invalid configured certificate files fail closed instead of silently disabling verification.
|
|
106
|
+
|
|
107
|
+
Only controlled development environments should use `ssl_verify=False`. A caller-supplied `httpx.AsyncClient` remains caller-owned; the engine closes only resources it creates.
|
|
108
|
+
|
|
109
|
+
## Documentation and verification
|
|
110
|
+
|
|
111
|
+
- [Design](DESIGN.md)
|
|
112
|
+
- [Developer guide](DEVELOPER_GUIDE.md)
|
|
113
|
+
- [Chinese README](README.md)
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
python -m pip install -e ".[dev]"
|
|
117
|
+
python -m pytest -q
|
|
118
|
+
python -m build
|
|
119
|
+
```
|
|
@@ -1,26 +1,43 @@
|
|
|
1
1
|
"""Quick start using execute_psop (recommended high-level API).
|
|
2
2
|
|
|
3
|
-
This is the simplest way to integrate the SDK: implement ControlPoint
|
|
4
|
-
|
|
3
|
+
This is the simplest way to integrate the SDK: implement the ControlPoint
|
|
4
|
+
callbacks used by the selected workflow, call execute_psop, and drain events.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
import asyncio
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from a2a.types import Part
|
|
11
|
+
from a2a_t.client import A2ATClient
|
|
12
|
+
from a2a_t.core.standard_templates import PRIVATE_LINE_COMPLAINT_URI
|
|
13
|
+
|
|
8
14
|
from workflow_engine import (
|
|
9
|
-
|
|
10
|
-
|
|
15
|
+
A2atMessages,
|
|
16
|
+
ControlPoint,
|
|
17
|
+
EventType,
|
|
18
|
+
RegistryClient,
|
|
19
|
+
RouteDecision,
|
|
20
|
+
execute_psop,
|
|
21
|
+
load_psop,
|
|
11
22
|
)
|
|
12
23
|
|
|
13
24
|
|
|
14
25
|
class MyControlPoint(ControlPoint):
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
26
|
+
def __init__(self, a2at_client):
|
|
27
|
+
self._a2at_client = a2at_client
|
|
28
|
+
|
|
29
|
+
async def on_task(self, request):
|
|
30
|
+
if request.input.text is None:
|
|
31
|
+
raise ValueError("This example expects text task input")
|
|
32
|
+
generated = await asyncio.to_thread(
|
|
33
|
+
self._a2at_client.generate_task_prompt_from_text,
|
|
34
|
+
request.input.text,
|
|
35
|
+
PRIVATE_LINE_COMPLAINT_URI,
|
|
18
36
|
)
|
|
19
|
-
return
|
|
37
|
+
return A2atMessages.from_generated(generated, [Part(text=request.instruction)])
|
|
20
38
|
|
|
21
|
-
async def on_route(self,
|
|
22
|
-
|
|
23
|
-
return RouteDecision(next_step=conditions[0].step)
|
|
39
|
+
async def on_route(self, request):
|
|
40
|
+
return RouteDecision.allow("business condition matched")
|
|
24
41
|
|
|
25
42
|
|
|
26
43
|
async def on_finish(result, events):
|
|
@@ -32,6 +49,8 @@ async def on_finish(result, events):
|
|
|
32
49
|
|
|
33
50
|
|
|
34
51
|
async def main():
|
|
52
|
+
a2at_client = A2ATClient(env_path=Path("a2at.env"))
|
|
53
|
+
|
|
35
54
|
# 1. Fetch AgentCards from the registry center
|
|
36
55
|
registry = RegistryClient(url="https://127.0.0.1:5000")
|
|
37
56
|
agent_cards = await registry.fetch_agent_cards()
|
|
@@ -48,10 +67,9 @@ async def main():
|
|
|
48
67
|
async for event in execute_psop(
|
|
49
68
|
psop=workflow,
|
|
50
69
|
agent_cards=agent_cards,
|
|
51
|
-
control_point=MyControlPoint(),
|
|
52
|
-
a2at_env_path=".env",
|
|
70
|
+
control_point=MyControlPoint(a2at_client),
|
|
53
71
|
credentials_config="agent_credentials.json",
|
|
54
|
-
runtime_intent="
|
|
72
|
+
runtime_intent="Analyze the service issue and aggregate delegated results",
|
|
55
73
|
ssl_verify=False,
|
|
56
74
|
on_finish=on_finish,
|
|
57
75
|
):
|
|
@@ -61,7 +79,7 @@ async def main():
|
|
|
61
79
|
elif etype == EventType.TASK_REQUEST:
|
|
62
80
|
print(f" Agent: {event['data']['agent']}")
|
|
63
81
|
elif etype == EventType.TASK_RESPONSE:
|
|
64
|
-
print(f"
|
|
82
|
+
print(f" Outputs: {event['data'].get('outputs', ())}")
|
|
65
83
|
elif etype == "complete":
|
|
66
84
|
print("Workflow complete!")
|
|
67
85
|
elif etype == "error":
|