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.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,