Renamed async_credential to credential (#2648)

This commit is contained in:
Dmytro Struk
2025-12-07 17:21:18 -08:00
committed by GitHub
Unverified
parent eb06faea2d
commit cfcb71334a
64 changed files with 266 additions and 269 deletions
@@ -122,7 +122,7 @@ class AzureAIAgentClient(BaseChatClient):
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,
@@ -144,7 +144,7 @@ class AzureAIAgentClient(BaseChatClient):
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.
@@ -162,17 +162,17 @@ class AzureAIAgentClient(BaseChatClient):
# 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(
@@ -200,11 +200,11 @@ class AzureAIAgentClient(BaseChatClient):
)
# 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
@@ -214,7 +214,7 @@ class AzureAIAgentClient(BaseChatClient):
# 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
@@ -66,7 +66,7 @@ class AzureAIClient(OpenAIBaseResponsesClient):
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,
@@ -86,7 +86,7 @@ class AzureAIClient(OpenAIBaseResponsesClient):
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.
@@ -103,17 +103,17 @@ class AzureAIClient(OpenAIBaseResponsesClient):
# 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(
@@ -135,11 +135,11 @@ class AzureAIClient(OpenAIBaseResponsesClient):
)
# 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
@@ -155,7 +155,7 @@ class AzureAIClient(OpenAIBaseResponsesClient):
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
@@ -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),
)
@@ -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),
)
@@ -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"
):
@@ -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
)
@@ -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,
)
@@ -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] = []
@@ -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] = []
@@ -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] = []
@@ -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] = []
@@ -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.")
@@ -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 = ""
@@ -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
@@ -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
@@ -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
@@ -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:
@@ -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
@@ -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:
@@ -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:
@@ -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(
@@ -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,
@@ -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
@@ -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",
)
@@ -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"
):
@@ -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(
@@ -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",
)
@@ -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.",