mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: (samples): adopt AzureOpenAIResponsesClient, reorganize orchestration examples, and fix workflow/orchestration bugs (#3873)
* adopt AzureOpenAIResponsesClient, reorganize orchestration examples, and fix workflow/orchestration bugs * Updates * add comment
This commit is contained in:
committed by
GitHub
Unverified
parent
8457533c69
commit
1b10b051fd
@@ -23,10 +23,11 @@ The workflow:
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
|
||||
from agent_framework.azure import AzureOpenAIChatClient
|
||||
from agent_framework.azure import AzureOpenAIResponsesClient
|
||||
from agent_framework.declarative import (
|
||||
AgentExternalInputRequest,
|
||||
AgentExternalInputResponse,
|
||||
@@ -164,7 +165,11 @@ async def main() -> None:
|
||||
plugin = TicketingPlugin()
|
||||
|
||||
# Create Azure OpenAI client
|
||||
client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
client = AzureOpenAIResponsesClient(
|
||||
project_endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
|
||||
deployment_name=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
|
||||
credential=AzureCliCredential(),
|
||||
)
|
||||
|
||||
# Create agents with structured outputs
|
||||
self_service_agent = client.as_agent(
|
||||
@@ -260,7 +265,9 @@ async def main() -> None:
|
||||
async for event in stream:
|
||||
if event.type == "output":
|
||||
data = event.data
|
||||
source_id = getattr(event, "source_executor_id", "")
|
||||
# source_executor_id is only available on request_info events.
|
||||
# For output events, use executor_id to identify the emitting node.
|
||||
source_id = event.executor_id or ""
|
||||
|
||||
# Check if this is a SendActivity output (activity text from log_ticket, log_route, etc.)
|
||||
if "log_" in source_id.lower():
|
||||
|
||||
@@ -22,9 +22,10 @@ Usage:
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from agent_framework.azure import AzureOpenAIChatClient
|
||||
from agent_framework.azure import AzureOpenAIResponsesClient
|
||||
from agent_framework.declarative import WorkflowFactory
|
||||
from azure.identity import AzureCliCredential
|
||||
from pydantic import BaseModel, Field
|
||||
@@ -122,7 +123,11 @@ class ManagerResponse(BaseModel):
|
||||
async def main() -> None:
|
||||
"""Run the deep research workflow."""
|
||||
# Create Azure OpenAI client
|
||||
client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
client = AzureOpenAIResponsesClient(
|
||||
project_endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
|
||||
deployment_name=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
|
||||
credential=AzureCliCredential(),
|
||||
)
|
||||
|
||||
# Create agents
|
||||
research_agent = client.as_agent(
|
||||
|
||||
@@ -6,12 +6,13 @@ function tools assigned. Exits the loop when the user enters "exit".
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Annotated, Any
|
||||
|
||||
from agent_framework import FileCheckpointStorage, tool
|
||||
from agent_framework.azure import AzureOpenAIChatClient
|
||||
from agent_framework.azure import AzureOpenAIResponsesClient
|
||||
from agent_framework_declarative import ExternalInputRequest, ExternalInputResponse, WorkflowFactory
|
||||
from azure.identity import AzureCliCredential
|
||||
from pydantic import Field
|
||||
@@ -62,7 +63,11 @@ def get_item_price(name: Annotated[str, Field(description="Menu item name")]) ->
|
||||
|
||||
async def main():
|
||||
# Create agent with tools
|
||||
client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
client = AzureOpenAIResponsesClient(
|
||||
project_endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
|
||||
deployment_name=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
|
||||
credential=AzureCliCredential(),
|
||||
)
|
||||
menu_agent = client.as_agent(
|
||||
name="MenuAgent",
|
||||
instructions="Answer questions about menu items, specials, and prices.",
|
||||
|
||||
@@ -13,9 +13,10 @@ Demonstrates sequential multi-agent pipeline:
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from agent_framework.azure import AzureOpenAIChatClient
|
||||
from agent_framework.azure import AzureOpenAIResponsesClient
|
||||
from agent_framework.declarative import WorkflowFactory
|
||||
from azure.identity import AzureCliCredential
|
||||
|
||||
@@ -49,7 +50,11 @@ Return the final polished version."""
|
||||
|
||||
async def main() -> None:
|
||||
"""Run the marketing workflow with real Azure AI agents."""
|
||||
client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
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",
|
||||
|
||||
@@ -15,14 +15,15 @@ The workflow loops until the teacher gives congratulations or max turns reached.
|
||||
Prerequisites:
|
||||
- Azure OpenAI deployment with chat completion capability
|
||||
- Environment variables:
|
||||
AZURE_OPENAI_ENDPOINT: Your Azure OpenAI endpoint
|
||||
AZURE_OPENAI_DEPLOYMENT_NAME: Your deployment name (optional, defaults to gpt-4o)
|
||||
AZURE_AI_PROJECT_ENDPOINT: Your Azure AI Foundry Agent Service (V2) project endpoint
|
||||
AZURE_AI_MODEL_DEPLOYMENT_NAME: Your model deployment name
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from agent_framework.azure import AzureOpenAIChatClient
|
||||
from agent_framework.azure import AzureOpenAIResponsesClient
|
||||
from agent_framework.declarative import WorkflowFactory
|
||||
from azure.identity import AzureCliCredential
|
||||
|
||||
@@ -51,7 +52,11 @@ Focus on building understanding, not just getting the right answer."""
|
||||
async def main() -> None:
|
||||
"""Run the student-teacher workflow with real Azure AI agents."""
|
||||
# Create chat client
|
||||
client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
client = AzureOpenAIResponsesClient(
|
||||
project_endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
|
||||
deployment_name=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
|
||||
credential=AzureCliCredential(),
|
||||
)
|
||||
|
||||
# Create student and teacher agents
|
||||
student_agent = client.as_agent(
|
||||
|
||||
Reference in New Issue
Block a user