-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfan_out_edges_all.py
More file actions
42 lines (28 loc) · 1.18 KB
/
Copy pathfan_out_edges_all.py
File metadata and controls
42 lines (28 loc) · 1.18 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
from typing import Never
from agent_framework import (
WorkflowBuilder,
WorkflowContext,
executor,
)
import asyncio
@executor
async def splitter_executor(work_message: str, ctx: WorkflowContext[str]) -> None:
await ctx.send_message(work_message)
@executor(id="summarizer")
async def summarizer(work_message: str, ctx: WorkflowContext[Never, str]) -> None:
await ctx.yield_output(f'worker 1 summarized: {work_message}')
@executor(id="sentiment_detector")
async def sentiment_detector(work_message: str, ctx: WorkflowContext[Never, str]) -> None:
await ctx.yield_output(f'worker 2 detected sentiment: {work_message}')
@executor(id="keyword_finder")
async def keyword_finder(work_message: str, ctx: WorkflowContext[Never,str]) -> None:
await ctx.yield_output(f'worker 3 found keywords: {work_message}')
async def main():
builder = WorkflowBuilder()
builder.set_start_executor(splitter_executor)
builder.add_fan_out_edges(splitter_executor, [summarizer, sentiment_detector, keyword_finder])
workflow = builder.build()
events = await workflow.run('data to work with')
print(events.get_outputs())
if __name__ == "__main__":
asyncio.run(main())