Python: Removed DefaultAzureCredential (#490)

* Removed DefaultAzureCredential

* Renamed ad_credential to credential
This commit is contained in:
Dmytro Struk
2025-08-26 15:33:17 +00:00
committed by GitHub
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: