Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __init__(
thread_id: str | None = None,
project_endpoint: str | None = None,
model_deployment_name: str | None = None,
async_credential: AsyncTokenCredential | None = None,
credential: AsyncTokenCredential | None = None,
should_cleanup_agent: bool = True,
env_file_path: str | None = None,
env_file_encoding: str | None = None,
Expand All @@ -144,7 +144,7 @@ def __init__(
Ignored when a agents_client is passed.
model_deployment_name: The model deployment name to use for agent creation.
Can also be set via environment variable AZURE_AI_MODEL_DEPLOYMENT_NAME.
async_credential: Azure async credential to use for authentication.
credential: Azure async credential to use for authentication.
should_cleanup_agent: Whether to cleanup (delete) agents created by this client when
the client is closed or context is exited. Defaults to True. Only affects agents
created by this client instance; existing agents passed via agent_id are never deleted.
Expand All @@ -162,17 +162,17 @@ def __init__(
# Set AZURE_AI_PROJECT_ENDPOINT=https://your-project.cognitiveservices.azure.com
# Set AZURE_AI_MODEL_DEPLOYMENT_NAME=gpt-4
credential = DefaultAzureCredential()
client = AzureAIAgentClient(async_credential=credential)
client = AzureAIAgentClient(credential=credential)

# Or passing parameters directly
client = AzureAIAgentClient(
project_endpoint="https://your-project.cognitiveservices.azure.com",
model_deployment_name="gpt-4",
async_credential=credential,
credential=credential,
)

# Or loading from a .env file
client = AzureAIAgentClient(async_credential=credential, env_file_path="path/to/.env")
client = AzureAIAgentClient(credential=credential, env_file_path="path/to/.env")
"""
try:
azure_ai_settings = AzureAISettings(
Expand Down Expand Up @@ -200,11 +200,11 @@ def __init__(
)

# Use provided credential
if not async_credential:
if not credential:
raise ServiceInitializationError("Azure credential is required when agents_client is not provided.")
agents_client = AgentsClient(
endpoint=azure_ai_settings.project_endpoint,
credential=async_credential,
credential=credential,
user_agent=AGENT_FRAMEWORK_USER_AGENT,
)
should_close_client = True
Expand All @@ -214,7 +214,7 @@ def __init__(

# Initialize instance variables
self.agents_client = agents_client
self.credential = async_credential
self.credential = credential
self.agent_id = agent_id
self.agent_name = agent_name
self.agent_description = agent_description
Expand Down
16 changes: 8 additions & 8 deletions python/packages/azure-ai/agent_framework_azure_ai/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(
conversation_id: str | None = None,
project_endpoint: str | None = None,
model_deployment_name: str | None = None,
async_credential: AsyncTokenCredential | None = None,
credential: AsyncTokenCredential | None = None,
use_latest_version: bool | None = None,
env_file_path: str | None = None,
env_file_encoding: str | None = None,
Expand All @@ -86,7 +86,7 @@ def __init__(
Ignored when a project_client is passed.
model_deployment_name: The model deployment name to use for agent creation.
Can also be set via environment variable AZURE_AI_MODEL_DEPLOYMENT_NAME.
async_credential: Azure async credential to use for authentication.
credential: Azure async credential to use for authentication.
use_latest_version: Boolean flag that indicates whether to use latest agent version
if it exists in the service.
env_file_path: Path to environment file for loading settings.
Expand All @@ -103,17 +103,17 @@ def __init__(
# Set AZURE_AI_PROJECT_ENDPOINT=https://your-project.cognitiveservices.azure.com
# Set AZURE_AI_MODEL_DEPLOYMENT_NAME=gpt-4
credential = DefaultAzureCredential()
client = AzureAIClient(async_credential=credential)
client = AzureAIClient(credential=credential)

# Or passing parameters directly
client = AzureAIClient(
project_endpoint="https://your-project.cognitiveservices.azure.com",
model_deployment_name="gpt-4",
async_credential=credential,
credential=credential,
)

# Or loading from a .env file
client = AzureAIClient(async_credential=credential, env_file_path="path/to/.env")
client = AzureAIClient(credential=credential, env_file_path="path/to/.env")
"""
try:
azure_ai_settings = AzureAISettings(
Expand All @@ -135,11 +135,11 @@ def __init__(
)

# Use provided credential
if not async_credential:
if not credential:
raise ServiceInitializationError("Azure credential is required when project_client is not provided.")
project_client = AIProjectClient(
endpoint=azure_ai_settings.project_endpoint,
credential=async_credential,
credential=credential,
user_agent=AGENT_FRAMEWORK_USER_AGENT,
)
should_close_client = True
Expand All @@ -155,7 +155,7 @@ def __init__(
self.agent_description = agent_description
self.use_latest_version = use_latest_version
self.project_client = project_client
self.credential = async_credential
self.credential = credential
self.model_id = azure_ai_settings.model_deployment_name
self.conversation_id = conversation_id

Expand Down
42 changes: 21 additions & 21 deletions python/packages/azure-ai/tests/test_azure_ai_agent_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def test_azure_ai_chat_client_init_missing_project_endpoint() -> None:
agent_id=None,
project_endpoint=None, # Missing endpoint
model_deployment_name="test-model",
async_credential=AsyncMock(spec=AsyncTokenCredential),
credential=AsyncMock(spec=AsyncTokenCredential),
)


Expand All @@ -190,7 +190,7 @@ def test_azure_ai_chat_client_init_missing_model_deployment_for_agent_creation()
agent_id=None, # No existing agent
project_endpoint="https://test.com",
model_deployment_name=None, # Missing for agent creation
async_credential=AsyncMock(spec=AsyncTokenCredential),
credential=AsyncMock(spec=AsyncTokenCredential),
)


Expand Down Expand Up @@ -223,7 +223,7 @@ def test_azure_ai_chat_client_from_dict(mock_agents_client: MagicMock) -> None:


def test_azure_ai_chat_client_init_missing_credential(azure_ai_unit_test_env: dict[str, str]) -> None:
"""Test AzureAIAgentClient.__init__ when async_credential is missing and no agents_client provided."""
"""Test AzureAIAgentClient.__init__ when credential is missing and no agents_client provided."""
with pytest.raises(
ServiceInitializationError, match="Azure credential is required when agents_client is not provided"
):
Expand All @@ -232,7 +232,7 @@ def test_azure_ai_chat_client_init_missing_credential(azure_ai_unit_test_env: di
agent_id="existing-agent",
project_endpoint=azure_ai_unit_test_env["AZURE_AI_PROJECT_ENDPOINT"],
model_deployment_name=azure_ai_unit_test_env["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
async_credential=None, # Missing credential
credential=None, # Missing credential
)


Expand All @@ -246,7 +246,7 @@ def test_azure_ai_chat_client_init_validation_error(mock_azure_credential: Magic
AzureAIAgentClient(
project_endpoint="https://test.com",
model_deployment_name="test-model",
async_credential=mock_azure_credential,
credential=mock_azure_credential,
)


Expand Down Expand Up @@ -1373,7 +1373,7 @@ def get_weather(
@skip_if_azure_ai_integration_tests_disabled
async def test_azure_ai_chat_client_get_response() -> None:
"""Test Azure AI Chat Client response."""
async with AzureAIAgentClient(async_credential=AzureCliCredential()) as azure_ai_chat_client:
async with AzureAIAgentClient(credential=AzureCliCredential()) as azure_ai_chat_client:
assert isinstance(azure_ai_chat_client, ChatClientProtocol)

messages: list[ChatMessage] = []
Expand All @@ -1398,7 +1398,7 @@ async def test_azure_ai_chat_client_get_response() -> None:
@skip_if_azure_ai_integration_tests_disabled
async def test_azure_ai_chat_client_get_response_tools() -> None:
"""Test Azure AI Chat Client response with tools."""
async with AzureAIAgentClient(async_credential=AzureCliCredential()) as azure_ai_chat_client:
async with AzureAIAgentClient(credential=AzureCliCredential()) as azure_ai_chat_client:
assert isinstance(azure_ai_chat_client, ChatClientProtocol)

messages: list[ChatMessage] = []
Expand All @@ -1420,7 +1420,7 @@ async def test_azure_ai_chat_client_get_response_tools() -> None:
@skip_if_azure_ai_integration_tests_disabled
async def test_azure_ai_chat_client_streaming() -> None:
"""Test Azure AI Chat Client streaming response."""
async with AzureAIAgentClient(async_credential=AzureCliCredential()) as azure_ai_chat_client:
async with AzureAIAgentClient(credential=AzureCliCredential()) as azure_ai_chat_client:
assert isinstance(azure_ai_chat_client, ChatClientProtocol)

messages: list[ChatMessage] = []
Expand Down Expand Up @@ -1451,7 +1451,7 @@ async def test_azure_ai_chat_client_streaming() -> None:
@skip_if_azure_ai_integration_tests_disabled
async def test_azure_ai_chat_client_streaming_tools() -> None:
"""Test Azure AI Chat Client streaming response with tools."""
async with AzureAIAgentClient(async_credential=AzureCliCredential()) as azure_ai_chat_client:
async with AzureAIAgentClient(credential=AzureCliCredential()) as azure_ai_chat_client:
assert isinstance(azure_ai_chat_client, ChatClientProtocol)

messages: list[ChatMessage] = []
Expand Down Expand Up @@ -1479,7 +1479,7 @@ async def test_azure_ai_chat_client_streaming_tools() -> None:
async def test_azure_ai_chat_client_agent_basic_run() -> None:
"""Test ChatAgent basic run functionality with AzureAIAgentClient."""
async with ChatAgent(
chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()),
chat_client=AzureAIAgentClient(credential=AzureCliCredential()),
) as agent:
# Run a simple query
response = await agent.run("Hello! Please respond with 'Hello World' exactly.")
Expand All @@ -1496,7 +1496,7 @@ async def test_azure_ai_chat_client_agent_basic_run() -> None:
async def test_azure_ai_chat_client_agent_basic_run_streaming() -> None:
"""Test ChatAgent basic streaming functionality with AzureAIAgentClient."""
async with ChatAgent(
chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()),
chat_client=AzureAIAgentClient(credential=AzureCliCredential()),
) as agent:
# Run streaming query
full_message: str = ""
Expand All @@ -1516,7 +1516,7 @@ async def test_azure_ai_chat_client_agent_basic_run_streaming() -> None:
async def test_azure_ai_chat_client_agent_thread_persistence() -> None:
"""Test ChatAgent thread persistence across runs with AzureAIAgentClient."""
async with ChatAgent(
chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()),
chat_client=AzureAIAgentClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant with good memory.",
) as agent:
# Create a new thread that will be reused
Expand All @@ -1542,7 +1542,7 @@ async def test_azure_ai_chat_client_agent_thread_persistence() -> None:
async def test_azure_ai_chat_client_agent_existing_thread_id() -> None:
"""Test ChatAgent existing thread ID functionality with AzureAIAgentClient."""
async with ChatAgent(
chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()),
chat_client=AzureAIAgentClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant with good memory.",
) as first_agent:
# Start a conversation and get the thread ID
Expand All @@ -1559,7 +1559,7 @@ async def test_azure_ai_chat_client_agent_existing_thread_id() -> None:

# Now continue with the same thread ID in a new agent instance
async with ChatAgent(
chat_client=AzureAIAgentClient(thread_id=existing_thread_id, async_credential=AzureCliCredential()),
chat_client=AzureAIAgentClient(thread_id=existing_thread_id, credential=AzureCliCredential()),
instructions="You are a helpful assistant with good memory.",
) as second_agent:
# Create a thread with the existing ID
Expand All @@ -1581,7 +1581,7 @@ async def test_azure_ai_chat_client_agent_code_interpreter():
"""Test ChatAgent with code interpreter through AzureAIAgentClient."""

async with ChatAgent(
chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()),
chat_client=AzureAIAgentClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant that can write and execute Python code.",
tools=[HostedCodeInterpreterTool()],
) as agent:
Expand All @@ -1600,7 +1600,7 @@ async def test_azure_ai_chat_client_agent_code_interpreter():
async def test_azure_ai_chat_client_agent_file_search():
"""Test ChatAgent with file search through AzureAIAgentClient."""

client = AzureAIAgentClient(async_credential=AzureCliCredential())
client = AzureAIAgentClient(credential=AzureCliCredential())
file: FileInfo | None = None
vector_store: VectorStore | None = None

Expand Down Expand Up @@ -1655,7 +1655,7 @@ async def test_azure_ai_chat_client_agent_hosted_mcp_tool() -> None:
)

async with ChatAgent(
chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()),
chat_client=AzureAIAgentClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant that can help with microsoft documentation questions.",
tools=[mcp_tool],
) as agent:
Expand All @@ -1682,7 +1682,7 @@ async def test_azure_ai_chat_client_agent_hosted_mcp_tool() -> None:
async def test_azure_ai_chat_client_agent_level_tool_persistence():
"""Test that agent-level tools persist across multiple runs with AzureAIAgentClient."""
async with ChatAgent(
chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()),
chat_client=AzureAIAgentClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant that uses available tools.",
tools=[get_weather],
) as agent:
Expand All @@ -1707,7 +1707,7 @@ async def test_azure_ai_chat_client_agent_level_tool_persistence():
async def test_azure_ai_chat_client_agent_chat_options_run_level() -> None:
"""Test ChatOptions parameter coverage at run level."""
async with ChatAgent(
chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()),
chat_client=AzureAIAgentClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant.",
) as agent:
response = await agent.run(
Expand Down Expand Up @@ -1737,7 +1737,7 @@ async def test_azure_ai_chat_client_agent_chat_options_run_level() -> None:
async def test_azure_ai_chat_client_agent_chat_options_agent_level() -> None:
"""Test ChatOptions parameter coverage agent level."""
async with ChatAgent(
chat_client=AzureAIAgentClient(async_credential=AzureCliCredential()),
chat_client=AzureAIAgentClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant.",
max_tokens=100,
temperature=0.7,
Expand Down Expand Up @@ -1963,7 +1963,7 @@ def test_azure_ai_chat_client_init_with_auto_created_agents_client(
agent_id="test-agent",
project_endpoint=azure_ai_unit_test_env["AZURE_AI_PROJECT_ENDPOINT"],
model_deployment_name=azure_ai_unit_test_env["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
async_credential=mock_azure_credential,
credential=mock_azure_credential,
)

# Verify AgentsClient was created with correct parameters
Expand Down
10 changes: 5 additions & 5 deletions python/packages/azure-ai/tests/test_azure_ai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_azure_ai_client_init_auto_create_client(
client = AzureAIClient(
project_endpoint=azure_ai_unit_test_env["AZURE_AI_PROJECT_ENDPOINT"],
model_deployment_name=azure_ai_unit_test_env["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
async_credential=mock_azure_credential,
credential=mock_azure_credential,
agent_name="test-agent",
)

Expand All @@ -171,11 +171,11 @@ def test_azure_ai_client_init_missing_project_endpoint() -> None:
mock_settings.return_value.model_deployment_name = "test-model"

with pytest.raises(ServiceInitializationError, match="Azure AI project endpoint is required"):
AzureAIClient(async_credential=MagicMock())
AzureAIClient(credential=MagicMock())


def test_azure_ai_client_init_missing_credential(azure_ai_unit_test_env: dict[str, str]) -> None:
"""Test AzureAIClient.__init__ when async_credential is missing and no project_client provided."""
"""Test AzureAIClient.__init__ when credential is missing and no project_client provided."""
with pytest.raises(
ServiceInitializationError, match="Azure credential is required when project_client is not provided"
):
Expand All @@ -191,7 +191,7 @@ def test_azure_ai_client_init_validation_error(mock_azure_credential: MagicMock)
mock_settings.side_effect = ValidationError.from_exception_data("test", [])

with pytest.raises(ServiceInitializationError, match="Failed to create Azure AI settings"):
AzureAIClient(async_credential=mock_azure_credential)
AzureAIClient(credential=mock_azure_credential)


async def test_azure_ai_client_get_agent_reference_or_create_existing_version(
Expand Down Expand Up @@ -320,7 +320,7 @@ async def test_azure_ai_client_prepare_options_with_application_endpoint(
client = AzureAIClient(
project_endpoint=endpoint,
model_deployment_name="test-model",
async_credential=mock_azure_credential,
credential=mock_azure_credential,
agent_name="test-agent",
agent_version="1",
)
Expand Down
2 changes: 1 addition & 1 deletion python/packages/lab/gaia/samples/azure_ai_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def create_gaia_agent() -> AsyncIterator[ChatAgent]:
"""
async with (
AzureCliCredential() as credential,
AzureAIAgentClient(async_credential=credential).create_agent(
AzureAIAgentClient(credential=credential).create_agent(
name="GaiaAgent",
instructions="Solve tasks to your best ability. Use Bing Search to find "
"information and Code Interpreter to perform calculations and data analysis.",
Expand Down
Loading
Loading