-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathmain.py
More file actions
105 lines (82 loc) · 2.97 KB
/
main.py
File metadata and controls
105 lines (82 loc) · 2.97 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Copyright (c) Microsoft. All rights reserved.
"""
Run the marketing copy workflow sample.
Usage:
python main.py
Demonstrates sequential multi-agent pipeline:
- AnalystAgent: Identifies key features, target audience, USPs
- WriterAgent: Creates compelling marketing copy
- EditorAgent: Polishes grammar, clarity, and tone
"""
import asyncio
import os
from pathlib import Path
from agent_framework.azure import AzureOpenAIResponsesClient
from agent_framework.declarative import WorkflowFactory
from azure.identity import AzureCliCredential
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
ANALYST_INSTRUCTIONS = """You are a product analyst. Analyze the given product and identify:
1. Key features and benefits
2. Target audience demographics
3. Unique selling propositions (USPs)
4. Competitive advantages
Be concise and structured in your analysis."""
WRITER_INSTRUCTIONS = """You are a marketing copywriter. Based on the product analysis provided,
create compelling marketing copy that:
1. Has a catchy headline
2. Highlights key benefits
3. Speaks to the target audience
4. Creates emotional connection
5. Includes a call to action
Write in an engaging, persuasive tone."""
EDITOR_INSTRUCTIONS = """You are a senior editor. Review and polish the marketing copy:
1. Fix any grammar or spelling issues
2. Improve clarity and flow
3. Ensure consistent tone
4. Tighten the prose
5. Make it more impactful
Return the final polished version."""
async def main() -> None:
"""Run the marketing workflow with real Azure AI agents."""
client = AzureOpenAIResponsesClient(
project_endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
deployment_name=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
credential=AzureCliCredential(),
)
analyst_agent = client.as_agent(
name="AnalystAgent",
instructions=ANALYST_INSTRUCTIONS,
)
writer_agent = client.as_agent(
name="WriterAgent",
instructions=WRITER_INSTRUCTIONS,
)
editor_agent = client.as_agent(
name="EditorAgent",
instructions=EDITOR_INSTRUCTIONS,
)
factory = WorkflowFactory(
agents={
"AnalystAgent": analyst_agent,
"WriterAgent": writer_agent,
"EditorAgent": editor_agent,
}
)
workflow_path = Path(__file__).parent / "workflow.yaml"
workflow = factory.create_workflow_from_yaml_path(workflow_path)
print(f"Loaded workflow: {workflow.name}")
print("=" * 60)
print("Marketing Copy Generation Pipeline")
print("=" * 60)
# Pass a simple string input - like .NET
product = "An eco-friendly stainless steel water bottle that keeps drinks cold for 24 hours."
async for event in workflow.run(product, stream=True):
if event.type == "output":
print(f"{event.data}", end="", flush=True)
print("\n" + "=" * 60)
print("Pipeline Complete")
print("=" * 60)
if __name__ == "__main__":
asyncio.run(main())