-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy path05_functional_workflow_with_agents.py
More file actions
51 lines (36 loc) · 1.28 KB
/
05_functional_workflow_with_agents.py
File metadata and controls
51 lines (36 loc) · 1.28 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
# Copyright (c) Microsoft. All rights reserved.
"""
Functional Workflow with Agents — Call agents inside @workflow
This sample shows how to call agents inside a functional workflow.
Agent calls are just regular async function calls — no special wrappers needed.
"""
import asyncio
from agent_framework import Agent, workflow
from agent_framework.foundry import FoundryChatClient
from azure.identity import AzureCliCredential
# <create_agents>
client = FoundryChatClient(credential=AzureCliCredential())
writer = Agent(
name="WriterAgent",
instructions="Write a short poem (4 lines max) about the given topic.",
client=client,
)
reviewer = Agent(
name="ReviewerAgent",
instructions="Review the given poem in one sentence. Is it good?",
client=client,
)
# </create_agents>
# <create_workflow>
@workflow
async def poem_workflow(topic: str) -> str:
"""Write a poem, then review it."""
poem = (await writer.run(f"Write a poem about: {topic}")).text
review = (await reviewer.run(f"Review this poem: {poem}")).text
return f"Poem:\n{poem}\n\nReview: {review}"
# </create_workflow>
async def main() -> None:
result = await poem_workflow.run("a cat learning to code")
print(result.get_outputs()[0])
if __name__ == "__main__":
asyncio.run(main())