Repository navigation
Expand file tree
/
Copy pathverify_sdk.py
More file actions
69 lines (57 loc) · 2.23 KB
/
Copy pathverify_sdk.py
File metadata and controls
69 lines (57 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""End-to-end verification of workflow-engine SDK using mocks (no real agents).
Verifies: import, step_type case parsing, execute_psop event flow,
workflow_complete lifecycle, ControlPoint decision dispatch, on_finish hook.
"""
import asyncio
from importlib.metadata import version
from packaging.version import Version
from workflow_engine import (
ControlPoint, MessageContent, RouteDecision, StubWorkflowEngineClient, Workflow, execute_psop,
)
class MyCP(ControlPoint):
async def on_task(self, request):
return MessageContent.text(request.instruction)
async def on_route(self, request):
return RouteDecision.allow("condition matched")
def build_workflow():
return Workflow.from_dict({
"name": "verify_flow",
"steps": [
{"name": "s1", "layer": 0, "step_type": "ALLSUCCESS",
"subtasks": [{"agent": "A", "description": "do A"}],
"next": [{"step": "s2", "condition": "A ok"}]},
{"name": "s2", "layer": 1, "step_type": "allsuccess",
"subtasks": [{"agent": "B", "description": "do B"}],
"next": []},
],
})
async def on_finish(result, events):
print(f"on_finish: success={result.success}, events={len(events)}")
async def main():
a2at_version = Version(version("a2a-t-sdk"))
assert Version("1.1.0") <= a2at_version < Version("2")
print(f"a2a-t-sdk: {a2at_version}")
wf = build_workflow()
print(f"step s1 type: {wf.steps[0].step_type}")
print(f"step s2 type: {wf.steps[1].step_type} (input was 'allsuccess')")
stub = StubWorkflowEngineClient()
events = []
async for ev in execute_psop(
psop=wf,
agent_cards=[],
control_point=MyCP(),
engine_client=stub,
runtime_intent="verify",
on_finish=on_finish,
):
events.append(ev["type"])
print("event sequence:", events)
ok = events[0] == "start" and events[-1] == "close"
ok = ok and "complete" in events
ok = ok and "workflow_complete" in events
ok = ok and len(stub.sent) == 2
print("sent messages:", len(stub.sent))
print("VERIFICATION:", "PASS" if ok else "FAIL")
assert ok, f"event flow unexpected: {events}"
if __name__ == "__main__":
asyncio.run(main())