Skip to content

Commit 5152e36

Browse files
authored
Agent workflow sample updates and other minor updates (#44507)
1 parent 6b0f3fc commit 5152e36

File tree

5 files changed

+35
-47
lines changed

5 files changed

+35
-47
lines changed

sdk/ai/azure-ai-projects/samples/agents/sample_workflow_multi_agent.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
from azure.identity import DefaultAzureCredential
3030
from azure.ai.projects import AIProjectClient
3131
from azure.ai.projects.models import (
32-
AgentReference,
3332
PromptAgentDefinition,
3433
ResponseStreamEventType,
3534
WorkflowAgentDefinition,
35+
ItemType,
3636
)
3737

3838
load_dotenv()
@@ -68,7 +68,6 @@
6868
print(f"Agent created (id: {student_agent.id}, name: {student_agent.name}, version: {student_agent.version})")
6969

7070
# Create Multi-Agent Workflow
71-
7271
workflow_yaml = f"""
7372
kind: workflow
7473
trigger:
@@ -138,7 +137,7 @@
138137
"""
139138

140139
workflow = project_client.agents.create_version(
141-
agent_name="student-teacherworkflow",
140+
agent_name="student-teacher-workflow",
142141
definition=WorkflowAgentDefinition(workflow=workflow_yaml),
143142
)
144143

@@ -149,28 +148,23 @@
149148

150149
stream = openai_client.responses.create(
151150
conversation=conversation.id,
152-
extra_body={"agent": AgentReference(name=workflow.name).as_dict()},
151+
extra_body={"agent": {"name": workflow.name, "type": "agent_reference"}},
153152
input="1 + 1 = ?",
154153
stream=True,
155154
metadata={"x-ms-debug-mode-enabled": "1"},
156155
)
157156

158157
for event in stream:
159-
if event.type == ResponseStreamEventType.RESPONSE_OUTPUT_TEXT_DONE:
160-
print("\t", event.text)
161-
elif (
158+
print(f"Event {event.sequence_number} type '{event.type}'", end="")
159+
if (
162160
event.type == ResponseStreamEventType.RESPONSE_OUTPUT_ITEM_ADDED
163-
and event.item.type == "workflow_action"
164-
and (event.item.action_id == "teacher_agent" or event.item.action_id == "student_agent")
165-
):
166-
print(f"********************************\nActor - '{event.item.action_id}' :")
167-
# feel free to uncomment below to see more events
168-
# elif event.type == ResponseStreamEventType.RESPONSE_OUTPUT_ITEM_ADDED and event.item.type == "workflow_action":
169-
# print(f"Workflow Item '{event.item.action_id}' is '{event.item.status}' - (previous item was : '{event.item.previous_action_id}')")
170-
# elif event.type == ResponseStreamEventType.RESPONSE_OUTPUT_ITEM_DONE and event.item.type == "workflow_action":
171-
# print(f"Workflow Item '{event.item.action_id}' is '{event.item.status}' - (previous item was: '{event.item.previous_action_id}')")
172-
# elif event.type == ResponseStreamEventType.RESPONSE_OUTPUT_TEXT_DELTA:
173-
# print(event.delta)
161+
or event.type == ResponseStreamEventType.RESPONSE_OUTPUT_ITEM_DONE
162+
) and event.item.type == ItemType.WORKFLOW_ACTION:
163+
print(
164+
f": item action ID '{event.item.action_id}' is '{event.item.status}' (previous action ID: '{event.item.previous_action_id}')",
165+
end="",
166+
)
167+
print("", flush=True)
174168

175169
openai_client.conversations.delete(conversation_id=conversation.id)
176170
print("Conversation deleted")
@@ -183,4 +177,3 @@
183177

184178
project_client.agents.delete_version(agent_name=teacher_agent.name, agent_version=teacher_agent.version)
185179
print("Teacher Agent deleted")
186-
# [END create_multi_agent_workflow]

sdk/ai/azure-ai-projects/samples/agents/sample_workflow_multi_agent_async.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
from azure.identity.aio import DefaultAzureCredential
3131
from azure.ai.projects.aio import AIProjectClient
3232
from azure.ai.projects.models import (
33-
AgentReference,
3433
PromptAgentDefinition,
3534
ResponseStreamEventType,
3635
WorkflowAgentDefinition,
36+
ItemType,
3737
)
3838

3939
load_dotenv()
@@ -50,7 +50,7 @@ async def main():
5050
):
5151

5252
teacher_agent = await project_client.agents.create_version(
53-
agent_name="teacher-agent",
53+
agent_name="teacher-agent-async",
5454
definition=PromptAgentDefinition(
5555
model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
5656
instructions="""You are a teacher that create pre-school math question for student and check answer.
@@ -61,7 +61,7 @@ async def main():
6161
print(f"Agent created (id: {teacher_agent.id}, name: {teacher_agent.name}, version: {teacher_agent.version})")
6262

6363
student_agent = await project_client.agents.create_version(
64-
agent_name="student-agent",
64+
agent_name="student-agent-async",
6565
definition=PromptAgentDefinition(
6666
model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
6767
instructions="""You are a student who answers questions from the teacher.
@@ -139,7 +139,7 @@ async def main():
139139
"""
140140

141141
workflow = await project_client.agents.create_version(
142-
agent_name="student-teacherworkflow",
142+
agent_name="student-teacher-workflow-async",
143143
definition=WorkflowAgentDefinition(workflow=workflow_yaml),
144144
)
145145

@@ -150,28 +150,23 @@ async def main():
150150

151151
stream = await openai_client.responses.create(
152152
conversation=conversation.id,
153-
extra_body={"agent": AgentReference(name=workflow.name).as_dict()},
153+
extra_body={"agent": {"name": workflow.name, "type": "agent_reference"}},
154154
input="1 + 1 = ?",
155155
stream=True,
156156
metadata={"x-ms-debug-mode-enabled": "1"},
157157
)
158158

159159
async for event in stream:
160-
if event.type == ResponseStreamEventType.RESPONSE_OUTPUT_TEXT_DONE:
161-
print("\t", event.text)
162-
elif (
160+
print(f"Event {event.sequence_number} type '{event.type}'", end="")
161+
if (
163162
event.type == ResponseStreamEventType.RESPONSE_OUTPUT_ITEM_ADDED
164-
and event.item.type == "workflow_action"
165-
and (event.item.action_id == "teacher_agent" or event.item.action_id == "student_agent")
166-
):
167-
print(f"********************************\nActor - '{event.item.action_id}' :")
168-
# feel free to uncomment below to see more events
169-
# elif event.type == ResponseStreamEventType.RESPONSE_OUTPUT_ITEM_ADDED and event.item.type == "workflow_action":
170-
# print(f"Workflow Item '{event.item.action_id}' is '{event.item.status}' - (previous item was : '{event.item.previous_action_id}')")
171-
# elif event.type == ResponseStreamEventType.RESPONSE_OUTPUT_ITEM_DONE and event.item.type == "workflow_action":
172-
# print(f"Workflow Item '{event.item.action_id}' is '{event.item.status}' - (previous item was: '{event.item.previous_action_id}')")
173-
# elif event.type == ResponseStreamEventType.RESPONSE_OUTPUT_TEXT_DELTA:
174-
# print(event.delta)
163+
or event.type == ResponseStreamEventType.RESPONSE_OUTPUT_ITEM_DONE
164+
) and event.item.type == ItemType.WORKFLOW_ACTION:
165+
print(
166+
f": item action ID '{event.item.action_id}' is '{event.item.status}' (previous action ID: '{event.item.previous_action_id}')",
167+
end="",
168+
)
169+
print("", flush=True)
175170

176171
await openai_client.conversations.delete(conversation_id=conversation.id)
177172
print("Conversation deleted")

sdk/ai/azure-ai-projects/samples/agents/telemetry/sample_agent_basic_with_console_tracing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
from azure.identity import DefaultAzureCredential
4444
from azure.ai.projects import AIProjectClient
45-
from azure.ai.projects.models import PromptAgentDefinition, AgentReference
45+
from azure.ai.projects.models import PromptAgentDefinition
4646
from openai.types.responses.response_input_text import ResponseInputText
4747
from openai.types.responses.response_output_text import ResponseOutputText
4848

@@ -106,15 +106,15 @@ def display_conversation_item(item: Any) -> None:
106106
request = "Hello, tell me a joke."
107107
response = openai_client.responses.create(
108108
conversation=conversation.id,
109-
extra_body={"agent": AgentReference(name=agent.name).as_dict()},
109+
extra_body={"agent": {"name": agent.name, "type": "agent_reference"}},
110110
input=request,
111111
)
112112
print(f"Answer: {response.output}")
113113

114114
response = openai_client.responses.create(
115115
conversation=conversation.id,
116116
input="Tell another one about computers.",
117-
extra_body={"agent": AgentReference(name=agent.name).as_dict()},
117+
extra_body={"agent": {"name": agent.name, "type": "agent_reference"}},
118118
)
119119
print(f"Answer: {response.output}")
120120

sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from dotenv import load_dotenv
3434
from azure.identity import DefaultAzureCredential
3535
from azure.ai.projects import AIProjectClient
36-
from azure.ai.projects.models import AgentReference, PromptAgentDefinition, ComputerUsePreviewTool
36+
from azure.ai.projects.models import PromptAgentDefinition, ComputerUsePreviewTool
3737

3838
# Import shared helper functions
3939
from computer_use_util import (
@@ -101,7 +101,7 @@
101101
],
102102
}
103103
],
104-
extra_body={"agent": AgentReference(name=agent.name).as_dict()},
104+
extra_body={"agent": {"name": agent.name, "type": "agent_reference"}},
105105
truncation="auto",
106106
)
107107

@@ -151,7 +151,7 @@
151151
},
152152
}
153153
],
154-
extra_body={"agent": AgentReference(name=agent.name).as_dict()},
154+
extra_body={"agent": {"name": agent.name, "type": "agent_reference"}},
155155
truncation="auto",
156156
)
157157

sdk/ai/azure-ai-projects/samples/agents/tools/sample_agent_computer_use_async.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from dotenv import load_dotenv
3535
from azure.identity.aio import DefaultAzureCredential
3636
from azure.ai.projects.aio import AIProjectClient
37-
from azure.ai.projects.models import AgentReference, PromptAgentDefinition, ComputerUsePreviewTool
37+
from azure.ai.projects.models import PromptAgentDefinition, ComputerUsePreviewTool
3838
from computer_use_util import (
3939
SearchState,
4040
load_screenshot_assets,
@@ -103,7 +103,7 @@ async def main():
103103
],
104104
}
105105
],
106-
extra_body={"agent": AgentReference(name=agent.name).as_dict()},
106+
extra_body={"agent": {"name": agent.name, "type": "agent_reference"}},
107107
truncation="auto",
108108
)
109109

@@ -155,7 +155,7 @@ async def main():
155155
},
156156
}
157157
],
158-
extra_body={"agent": AgentReference(name=agent.name).as_dict()},
158+
extra_body={"agent": {"name": agent.name, "type": "agent_reference"}},
159159
truncation="auto",
160160
)
161161

0 commit comments

Comments
 (0)