Python: Removed DefaultAzureCredential (#490)

* Removed DefaultAzureCredential

* Renamed ad_credential to credential
This commit is contained in:
Dmytro Struk
2025-08-26 08:33:17 -07:00
committed by GitHub
Unverified
parent 20d861076a
commit fa88641263
36 changed files with 230 additions and 148 deletions
@@ -5,7 +5,7 @@ from random import randint
from typing import Annotated
from agent_framework.azure import AzureAssistantsClient
from azure.identity import DefaultAzureCredential
from azure.identity import AzureCliCredential
from pydantic import Field
@@ -23,7 +23,9 @@ async def non_streaming_example() -> None:
# Since no assistant ID is provided, the assistant will be automatically created
# and deleted after getting a response
async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()).create_agent(
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with AzureAssistantsClient(credential=AzureCliCredential()).create_agent(
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent:
@@ -39,7 +41,7 @@ async def streaming_example() -> None:
# Since no assistant ID is provided, the assistant will be automatically created
# and deleted after getting a response
async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()).create_agent(
async with AzureAssistantsClient(credential=AzureCliCredential()).create_agent(
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent:
@@ -4,7 +4,7 @@ import asyncio
from agent_framework import AgentRunResponseUpdate, ChatClientAgent, ChatResponseUpdate, HostedCodeInterpreterTool
from agent_framework.azure import AzureAssistantsClient
from azure.identity import DefaultAzureCredential
from azure.identity import AzureCliCredential
from openai.types.beta.threads.runs import (
CodeInterpreterToolCallDelta,
RunStepDelta,
@@ -37,8 +37,10 @@ async def main() -> None:
"""Example showing how to use the HostedCodeInterpreterTool with Azure OpenAI Assistants."""
print("=== Azure OpenAI Assistants Agent with Code Interpreter Example ===")
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with ChatClientAgent(
chat_client=AzureAssistantsClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureAssistantsClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant that can write and execute Python code to solve problems.",
tools=HostedCodeInterpreterTool(),
) as agent:
@@ -7,7 +7,7 @@ from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework.azure import AzureAssistantsClient
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
from azure.identity import AzureCliCredential, get_bearer_token_provider
from openai import AsyncAzureOpenAI
from pydantic import Field
@@ -23,7 +23,7 @@ def get_weather(
async def main() -> None:
print("=== Azure OpenAI Assistants Chat Client with Existing Assistant ===")
token_provider = get_bearer_token_provider(DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default")
token_provider = get_bearer_token_provider(AzureCliCredential(), "https://cognitiveservices.azure.com/.default")
client = AsyncAzureOpenAI(
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
@@ -7,7 +7,7 @@ from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework.azure import AzureAssistantsClient
from azure.identity import DefaultAzureCredential
from azure.identity import AzureCliCredential
from pydantic import Field
@@ -31,8 +31,10 @@ async def tools_on_agent_level() -> None:
# Tools are provided when creating the agent
# The agent can use these tools for any query during its lifetime
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with ChatClientAgent(
chat_client=AzureAssistantsClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureAssistantsClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant that can provide weather and time information.",
tools=[get_weather, get_time], # Tools defined at agent creation
) as agent:
@@ -60,8 +62,10 @@ async def tools_on_run_level() -> None:
print("=== Tools Passed to Run Method ===")
# Agent created without tools
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with ChatClientAgent(
chat_client=AzureAssistantsClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureAssistantsClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant.",
# No tools defined here
) as agent:
@@ -89,8 +93,10 @@ async def mixed_tools_example() -> None:
print("=== Mixed Tools Example (Agent + Run Method) ===")
# Agent created with some base tools
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with ChatClientAgent(
chat_client=AzureAssistantsClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureAssistantsClient(credential=AzureCliCredential()),
instructions="You are a comprehensive assistant that can help with various information requests.",
tools=[get_weather], # Base tool available for all queries
) as agent:
@@ -6,7 +6,7 @@ from typing import Annotated
from agent_framework import AgentThread, ChatClientAgent
from agent_framework.azure import AzureAssistantsClient
from azure.identity import DefaultAzureCredential
from azure.identity import AzureCliCredential
from pydantic import Field
@@ -22,8 +22,10 @@ async def example_with_automatic_thread_creation() -> None:
"""Example showing automatic thread creation (service-managed thread)."""
print("=== Automatic Thread Creation Example ===")
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with ChatClientAgent(
chat_client=AzureAssistantsClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureAssistantsClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent:
@@ -46,8 +48,10 @@ async def example_with_thread_persistence() -> None:
print("=== Thread Persistence Example ===")
print("Using the same thread across multiple conversations to maintain context.\n")
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with ChatClientAgent(
chat_client=AzureAssistantsClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureAssistantsClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent:
@@ -82,8 +86,10 @@ async def example_with_existing_thread_id() -> None:
# First, create a conversation and capture the thread ID
existing_thread_id = None
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with ChatClientAgent(
chat_client=AzureAssistantsClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureAssistantsClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent:
@@ -103,7 +109,7 @@ async def example_with_existing_thread_id() -> None:
# Create a new agent instance but use the existing thread ID
async with ChatClientAgent(
chat_client=AzureAssistantsClient(thread_id=existing_thread_id, ad_credential=DefaultAzureCredential()),
chat_client=AzureAssistantsClient(thread_id=existing_thread_id, credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent:
@@ -5,7 +5,7 @@ from random import randint
from typing import Annotated
from agent_framework.azure import AzureChatClient
from azure.identity import DefaultAzureCredential
from azure.identity import AzureCliCredential
from pydantic import Field
@@ -22,7 +22,9 @@ async def non_streaming_example() -> None:
print("=== Non-streaming Response Example ===")
# Create agent with Azure Chat Client
agent = AzureChatClient(ad_credential=DefaultAzureCredential()).create_agent(
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = AzureChatClient(credential=AzureCliCredential()).create_agent(
instructions="You are a helpful weather agent.",
tools=get_weather,
)
@@ -38,7 +40,9 @@ async def streaming_example() -> None:
print("=== Streaming Response Example ===")
# Create agent with Azure Chat Client
agent = AzureChatClient(ad_credential=DefaultAzureCredential()).create_agent(
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = AzureChatClient(credential=AzureCliCredential()).create_agent(
instructions="You are a helpful weather agent.",
tools=get_weather,
)
@@ -7,7 +7,7 @@ from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework.azure import AzureChatClient
from azure.identity import DefaultAzureCredential
from azure.identity import AzureCliCredential
from pydantic import Field
@@ -31,8 +31,10 @@ async def tools_on_agent_level() -> None:
# Tools are provided when creating the agent
# The agent can use these tools for any query during its lifetime
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
chat_client=AzureChatClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureChatClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant that can provide weather and time information.",
tools=[get_weather, get_time], # Tools defined at agent creation
)
@@ -61,8 +63,10 @@ async def tools_on_run_level() -> None:
print("=== Tools Passed to Run Method ===")
# Agent created without tools
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
chat_client=AzureChatClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureChatClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant.",
# No tools defined here
)
@@ -91,8 +95,10 @@ async def mixed_tools_example() -> None:
print("=== Mixed Tools Example (Agent + Run Method) ===")
# Agent created with some base tools
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
chat_client=AzureChatClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureChatClient(credential=AzureCliCredential()),
instructions="You are a comprehensive assistant that can help with various information requests.",
tools=[get_weather], # Base tool available for all queries
)
@@ -6,7 +6,7 @@ from typing import Annotated
from agent_framework import AgentThread, ChatClientAgent, ChatMessageList
from agent_framework.azure import AzureChatClient
from azure.identity import DefaultAzureCredential
from azure.identity import AzureCliCredential
from pydantic import Field
@@ -22,8 +22,10 @@ async def example_with_automatic_thread_creation() -> None:
"""Example showing automatic thread creation (service-managed thread)."""
print("=== Automatic Thread Creation Example ===")
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
chat_client=AzureChatClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureChatClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
)
@@ -47,8 +49,10 @@ async def example_with_thread_persistence() -> None:
print("=== Thread Persistence Example ===")
print("Using the same thread across multiple conversations to maintain context.\n")
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
chat_client=AzureChatClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureChatClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
)
@@ -80,8 +84,10 @@ async def example_with_existing_thread_messages() -> None:
"""Example showing how to work with existing thread messages for Azure."""
print("=== Existing Thread Messages Example ===")
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
chat_client=AzureChatClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureChatClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
)
@@ -104,7 +110,7 @@ async def example_with_existing_thread_messages() -> None:
# Create a new agent instance but use the existing thread with its message history
new_agent = ChatClientAgent(
chat_client=AzureChatClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureChatClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
)
@@ -5,7 +5,7 @@ from random import randint
from typing import Annotated
from agent_framework.azure import AzureResponsesClient
from azure.identity import DefaultAzureCredential
from azure.identity import AzureCliCredential
from pydantic import Field
@@ -21,7 +21,9 @@ async def non_streaming_example() -> None:
"""Example of non-streaming response (get the complete result at once)."""
print("=== Non-streaming Response Example ===")
agent = AzureResponsesClient(ad_credential=DefaultAzureCredential()).create_agent(
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = AzureResponsesClient(credential=AzureCliCredential()).create_agent(
instructions="You are a helpful weather agent.",
tools=get_weather,
)
@@ -36,7 +38,9 @@ async def streaming_example() -> None:
"""Example of streaming response (get results as they are generated)."""
print("=== Streaming Response Example ===")
agent = AzureResponsesClient(ad_credential=DefaultAzureCredential()).create_agent(
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = AzureResponsesClient(credential=AzureCliCredential()).create_agent(
instructions="You are a helpful weather agent.",
tools=get_weather,
)
@@ -4,7 +4,7 @@ import asyncio
from agent_framework import ChatClientAgent, ChatResponse, HostedCodeInterpreterTool
from agent_framework.azure import AzureResponsesClient
from azure.identity import DefaultAzureCredential
from azure.identity import AzureCliCredential
from openai.types.responses.response import Response as OpenAIResponse
from openai.types.responses.response_code_interpreter_tool_call import ResponseCodeInterpreterToolCall
@@ -13,8 +13,10 @@ async def main() -> None:
"""Example showing how to use the HostedCodeInterpreterTool with Azure OpenAI Responses."""
print("=== Azure OpenAI Responses Agent with Code Interpreter Example ===")
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureResponsesClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant that can write and execute Python code to solve problems.",
tools=HostedCodeInterpreterTool(),
)
@@ -7,7 +7,7 @@ from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework.azure import AzureResponsesClient
from azure.identity import DefaultAzureCredential
from azure.identity import AzureCliCredential
from pydantic import Field
@@ -31,8 +31,10 @@ async def tools_on_agent_level() -> None:
# Tools are provided when creating the agent
# The agent can use these tools for any query during its lifetime
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureResponsesClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant that can provide weather and time information.",
tools=[get_weather, get_time], # Tools defined at agent creation
)
@@ -61,8 +63,10 @@ async def tools_on_run_level() -> None:
print("=== Tools Passed to Run Method ===")
# Agent created without tools
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureResponsesClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant.",
# No tools defined here
)
@@ -91,8 +95,10 @@ async def mixed_tools_example() -> None:
print("=== Mixed Tools Example (Agent + Run Method) ===")
# Agent created with some base tools
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureResponsesClient(credential=AzureCliCredential()),
instructions="You are a comprehensive assistant that can help with various information requests.",
tools=[get_weather], # Base tool available for all queries
)
@@ -6,7 +6,7 @@ from typing import Annotated
from agent_framework import AgentThread, ChatClientAgent
from agent_framework.azure import AzureResponsesClient
from azure.identity import DefaultAzureCredential
from azure.identity import AzureCliCredential
from pydantic import Field
@@ -22,8 +22,10 @@ async def example_with_automatic_thread_creation() -> None:
"""Example showing automatic thread creation."""
print("=== Automatic Thread Creation Example ===")
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureResponsesClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
)
@@ -49,8 +51,10 @@ async def example_with_thread_persistence_in_memory() -> None:
"""
print("=== Thread Persistence Example (In-Memory) ===")
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureResponsesClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
)
@@ -91,8 +95,10 @@ async def example_with_existing_thread_id() -> None:
# First, create a conversation and capture the thread ID
existing_thread_id = None
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureResponsesClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
)
@@ -115,7 +121,7 @@ async def example_with_existing_thread_id() -> None:
print("\n--- Continuing with the same thread ID in a new agent instance ---")
agent = ChatClientAgent(
chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()),
chat_client=AzureResponsesClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
)
@@ -5,7 +5,7 @@ from random import randint
from typing import Annotated
from agent_framework.foundry import FoundryChatClient
from azure.identity.aio import DefaultAzureCredential
from azure.identity.aio import AzureCliCredential
from pydantic import Field
@@ -23,9 +23,11 @@ async def non_streaming_example() -> None:
# Since no Agent ID is provided, the agent will be automatically created
# and deleted after getting a response
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with (
DefaultAzureCredential() as credential,
FoundryChatClient(async_ad_credential=credential).create_agent(
AzureCliCredential() as credential,
FoundryChatClient(async_credential=credential).create_agent(
name="WeatherAgent",
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -43,9 +45,11 @@ async def streaming_example() -> None:
# Since no Agent ID is provided, the agent will be automatically created
# and deleted after getting a response
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with (
DefaultAzureCredential() as credential,
FoundryChatClient(async_ad_credential=credential).create_agent(
AzureCliCredential() as credential,
FoundryChatClient(async_credential=credential).create_agent(
name="WeatherAgent",
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -11,7 +11,7 @@ from azure.ai.agents.models import (
RunStepDeltaCodeInterpreterToolCall,
RunStepDeltaToolCallObject,
)
from azure.identity.aio import DefaultAzureCredential
from azure.identity.aio import AzureCliCredential
def get_code_interpreter_chunk(chunk: AgentRunResponseUpdate) -> str | None:
@@ -37,10 +37,12 @@ async def main() -> None:
"""Example showing how to use the HostedCodeInterpreterTool with Foundry."""
print("=== Foundry Agent with Code Interpreter Example ===")
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with (
DefaultAzureCredential() as credential,
AzureCliCredential() as credential,
ChatClientAgent(
chat_client=FoundryChatClient(async_ad_credential=credential),
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a helpful assistant that can write and execute Python code to solve problems.",
tools=HostedCodeInterpreterTool(),
) as agent,
@@ -8,7 +8,7 @@ from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework.foundry import FoundryChatClient
from azure.ai.projects.aio import AIProjectClient
from azure.identity.aio import DefaultAzureCredential
from azure.identity.aio import AzureCliCredential
from pydantic import Field
@@ -25,7 +25,7 @@ async def main() -> None:
# Create the client
async with (
DefaultAzureCredential() as credential,
AzureCliCredential() as credential,
AIProjectClient(endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], credential=credential) as client,
):
# Create an agent that will persist
@@ -7,7 +7,7 @@ from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework.foundry import FoundryChatClient
from azure.identity.aio import DefaultAzureCredential
from azure.identity.aio import AzureCliCredential
from pydantic import Field
@@ -24,13 +24,15 @@ async def main() -> None:
# Since no Agent ID is provided, the agent will be automatically created
# and deleted after getting a response
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with (
DefaultAzureCredential() as credential,
AzureCliCredential() as credential,
ChatClientAgent(
chat_client=FoundryChatClient(
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
model_deployment_name=os.environ["FOUNDRY_MODEL_DEPLOYMENT_NAME"],
async_ad_credential=credential,
async_credential=credential,
agent_name="WeatherAgent",
),
instructions="You are a helpful weather agent.",
@@ -7,7 +7,7 @@ from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework.foundry import FoundryChatClient
from azure.identity.aio import DefaultAzureCredential
from azure.identity.aio import AzureCliCredential
from pydantic import Field
@@ -31,10 +31,12 @@ async def tools_on_agent_level() -> None:
# Tools are provided when creating the agent
# The agent can use these tools for any query during its lifetime
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with (
DefaultAzureCredential() as credential,
AzureCliCredential() as credential,
ChatClientAgent(
chat_client=FoundryChatClient(async_ad_credential=credential),
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a helpful assistant that can provide weather and time information.",
tools=[get_weather, get_time], # Tools defined at agent creation
) as agent,
@@ -63,10 +65,12 @@ async def tools_on_run_level() -> None:
print("=== Tools Passed to Run Method ===")
# Agent created without tools
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with (
DefaultAzureCredential() as credential,
AzureCliCredential() as credential,
ChatClientAgent(
chat_client=FoundryChatClient(async_ad_credential=credential),
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a helpful assistant.",
# No tools defined here
) as agent,
@@ -95,10 +99,12 @@ async def mixed_tools_example() -> None:
print("=== Mixed Tools Example (Agent + Run Method) ===")
# Agent created with some base tools
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with (
DefaultAzureCredential() as credential,
AzureCliCredential() as credential,
ChatClientAgent(
chat_client=FoundryChatClient(async_ad_credential=credential),
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a comprehensive assistant that can help with various information requests.",
tools=[get_weather], # Base tool available for all queries
) as agent,
@@ -6,7 +6,7 @@ from typing import Annotated
from agent_framework import AgentThread, ChatClientAgent
from agent_framework.foundry import FoundryChatClient
from azure.identity.aio import DefaultAzureCredential
from azure.identity.aio import AzureCliCredential
from pydantic import Field
@@ -22,10 +22,12 @@ async def example_with_automatic_thread_creation() -> None:
"""Example showing automatic thread creation (service-managed thread)."""
print("=== Automatic Thread Creation Example ===")
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with (
DefaultAzureCredential() as credential,
AzureCliCredential() as credential,
ChatClientAgent(
chat_client=FoundryChatClient(async_ad_credential=credential),
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent,
@@ -49,10 +51,12 @@ async def example_with_thread_persistence() -> None:
print("=== Thread Persistence Example ===")
print("Using the same thread across multiple conversations to maintain context.\n")
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with (
DefaultAzureCredential() as credential,
AzureCliCredential() as credential,
ChatClientAgent(
chat_client=FoundryChatClient(async_ad_credential=credential),
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent,
@@ -88,10 +92,12 @@ async def example_with_existing_thread_id() -> None:
# First, create a conversation and capture the thread ID
existing_thread_id = None
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with (
DefaultAzureCredential() as credential,
AzureCliCredential() as credential,
ChatClientAgent(
chat_client=FoundryChatClient(async_ad_credential=credential),
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent,
@@ -112,9 +118,9 @@ async def example_with_existing_thread_id() -> None:
# Create a new agent instance but use the existing thread ID
async with (
DefaultAzureCredential() as credential,
AzureCliCredential() as credential,
ChatClientAgent(
chat_client=FoundryChatClient(thread_id=existing_thread_id, async_ad_credential=credential),
chat_client=FoundryChatClient(thread_id=existing_thread_id, async_credential=credential),
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent,
@@ -5,7 +5,7 @@ from random import randint
from typing import Annotated
from agent_framework.azure import AzureAssistantsClient
from azure.identity import DefaultAzureCredential
from azure.identity import AzureCliCredential
from pydantic import Field
@@ -18,7 +18,9 @@ def get_weather(
async def main() -> None:
async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()) as client:
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with AzureAssistantsClient(credential=AzureCliCredential()) as client:
message = "What's the weather in Amsterdam and in Paris?"
stream = False
print(f"User: {message}")
@@ -5,7 +5,7 @@ from random import randint
from typing import Annotated
from agent_framework.azure import AzureChatClient
from azure.identity import DefaultAzureCredential
from azure.identity import AzureCliCredential
from pydantic import Field
@@ -18,7 +18,9 @@ def get_weather(
async def main() -> None:
client = AzureChatClient(ad_credential=DefaultAzureCredential())
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
client = AzureChatClient(credential=AzureCliCredential())
message = "What's the weather in Amsterdam and in Paris?"
stream = False
print(f"User: {message}")
@@ -6,7 +6,7 @@ from typing import Annotated
from agent_framework import ChatResponse
from agent_framework.azure import AzureResponsesClient
from azure.identity import DefaultAzureCredential
from azure.identity import AzureCliCredential
from pydantic import BaseModel, Field
@@ -26,7 +26,9 @@ class OutputStruct(BaseModel):
async def main() -> None:
client = AzureResponsesClient(ad_credential=DefaultAzureCredential())
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
client = AzureResponsesClient(credential=AzureCliCredential())
message = "What's the weather in Amsterdam and in Paris?"
stream = True
print(f"User: {message}")
@@ -5,7 +5,7 @@ from random import randint
from typing import Annotated
from agent_framework.foundry import FoundryChatClient
from azure.identity.aio import DefaultAzureCredential
from azure.identity.aio import AzureCliCredential
from pydantic import Field
@@ -18,7 +18,9 @@ def get_weather(
async def main() -> None:
async with FoundryChatClient(async_ad_credential=DefaultAzureCredential()) as client:
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with FoundryChatClient(async_credential=AzureCliCredential()) as client:
message = "What's the weather in Amsterdam and in Paris?"
stream = False
print(f"User: {message}")
@@ -4,7 +4,7 @@ import asyncio
from agent_framework.foundry import FoundryChatClient
from agent_framework.openai import OpenAIChatClient
from azure.identity.aio import DefaultAzureCredential
from azure.identity.aio import AzureCliCredential
async def suspend_resume_service_managed_thread() -> None:
@@ -13,9 +13,11 @@ async def suspend_resume_service_managed_thread() -> None:
# Foundry Chat Client is used as an example here,
# other chat clients can be used as well.
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with (
DefaultAzureCredential() as credential,
FoundryChatClient(async_ad_credential=credential).create_agent(
AzureCliCredential() as credential,
FoundryChatClient(async_credential=credential).create_agent(
name="Joker", instructions="You are good at telling jokes."
) as agent,
):
@@ -15,7 +15,7 @@ from agent_framework.workflow import (
WorkflowContext,
handler,
)
from azure.identity import DefaultAzureCredential
from azure.identity import AzureCliCredential
"""
The following sample demonstrates a basic workflow that simulates
@@ -93,7 +93,9 @@ async def main():
"""Main function to run the group chat workflow."""
# Step 1: Create the executors.
chat_client = AzureChatClient(ad_credential=DefaultAzureCredential())
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
chat_client = AzureChatClient(credential=AzureCliCredential())
writer = AgentExecutor(
chat_client.create_agent(
instructions=(
@@ -18,7 +18,7 @@ from agent_framework.workflow import (
WorkflowContext,
handler,
)
from azure.identity import DefaultAzureCredential
from azure.identity import AzureCliCredential
"""
The following sample demonstrates a basic workflow that simulates
@@ -150,7 +150,9 @@ class CriticGroupChatManager(Executor):
async def main():
"""Main function to run the group chat workflow."""
# Step 1: Create the executors.
chat_client = AzureChatClient(ad_credential=DefaultAzureCredential())
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
chat_client = AzureChatClient(credential=AzureCliCredential())
writer = AgentExecutor(
chat_client.create_agent(
instructions=(