Skip to content
Open
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 @@ -1474,8 +1474,9 @@ def as_agent(

Keyword Args:
id: The unique identifier for the agent. Will be created automatically if not provided.
name: The name of the agent.
description: A brief description of the agent's purpose.
name: The name of the agent. Defaults to the client's ``agent_name`` when None.
description: A brief description of the agent's purpose. Defaults to the client's
``agent_description`` when None.
instructions: Optional instructions for the agent.
tools: The tools to use for the request.
default_options: A TypedDict containing chat options.
Expand All @@ -1488,8 +1489,8 @@ def as_agent(
"""
return super().as_agent(
id=id,
name=name,
description=description,
name=self.agent_name if name is None else name,
description=self.agent_description if description is None else description,
instructions=instructions,
tools=tools,
default_options=default_options,
Expand Down
9 changes: 5 additions & 4 deletions python/packages/azure-ai/agent_framework_azure_ai/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,8 +1181,9 @@ def as_agent(

Keyword Args:
id: The unique identifier for the agent. Will be created automatically if not provided.
name: The name of the agent.
description: A brief description of the agent's purpose.
name: The name of the agent. Defaults to the client's ``agent_name`` when None.
description: A brief description of the agent's purpose. Defaults to the client's
``agent_description`` when None.
instructions: Optional instructions for the agent.
tools: The tools to use for the request.
default_options: A TypedDict containing chat options.
Expand All @@ -1195,8 +1196,8 @@ def as_agent(
"""
return super().as_agent(
id=id,
name=name,
description=description,
name=self.agent_name if name is None else name,
description=self.agent_description if description is None else description,
instructions=instructions,
tools=tools,
default_options=default_options,
Expand Down
42 changes: 42 additions & 0 deletions python/packages/azure-ai/tests/test_azure_ai_agent_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,48 @@ async def test_azure_ai_chat_client_prepare_options_merges_instructions_from_mes
assert "concise" in instructions_text.lower()


def test_as_agent_uses_client_agent_name_as_default(mock_agents_client: MagicMock) -> None:
"""Test that as_agent() defaults Agent.name to client.agent_name when name is not provided."""
client = create_test_azure_ai_chat_client(mock_agents_client, agent_name="my_agent")
client.agent_description = "my description"

agent = client.as_agent(instructions="You are helpful.")

assert agent.name == "my_agent"
assert agent.description == "my description"


def test_as_agent_explicit_name_overrides_client_agent_name(mock_agents_client: MagicMock) -> None:
"""Test that an explicit name passed to as_agent() takes precedence over client.agent_name."""
client = create_test_azure_ai_chat_client(mock_agents_client, agent_name="client_name")
client.agent_description = "client description"

agent = client.as_agent(name="explicit_name", description="explicit description", instructions="You are helpful.")

assert agent.name == "explicit_name"
assert agent.description == "explicit description"


def test_as_agent_no_name_anywhere(mock_agents_client: MagicMock) -> None:
"""Test that Agent.name is None when neither as_agent name nor client.agent_name is provided."""
client = create_test_azure_ai_chat_client(mock_agents_client)

agent = client.as_agent(instructions="You are helpful.")

assert agent.name is None


def test_as_agent_empty_string_preserves_explicit_value(mock_agents_client: MagicMock) -> None:
"""Test that empty-string name/description are preserved and do not fall back to client defaults."""
client = create_test_azure_ai_chat_client(mock_agents_client, agent_name="client_name")
client.agent_description = "client description"

agent = client.as_agent(name="", description="", instructions="You are helpful.")

assert agent.name == ""
assert agent.description == ""


async def test_azure_ai_chat_client_inner_get_response(mock_agents_client: MagicMock) -> None:
"""Test _inner_get_response method."""
client = create_test_azure_ai_chat_client(mock_agents_client, agent_id="test-agent")
Expand Down
42 changes: 42 additions & 0 deletions python/packages/azure-ai/tests/test_azure_ai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,48 @@ def test_update_agent_name_and_description(mock_project_client: MagicMock) -> No
mock_update.assert_called_once_with(None)


def test_as_agent_uses_client_agent_name_as_default(mock_project_client: MagicMock) -> None:
"""Test that as_agent() defaults Agent.name to client.agent_name when name is not provided."""
client = create_test_azure_ai_client(mock_project_client, agent_name="my_agent")
client.agent_description = "my description"

agent = client.as_agent(instructions="You are helpful.")

assert agent.name == "my_agent"
assert agent.description == "my description"


def test_as_agent_explicit_name_overrides_client_agent_name(mock_project_client: MagicMock) -> None:
"""Test that an explicit name passed to as_agent() takes precedence over client.agent_name."""
client = create_test_azure_ai_client(mock_project_client, agent_name="client_name")
client.agent_description = "client description"

agent = client.as_agent(name="explicit_name", description="explicit description", instructions="You are helpful.")

assert agent.name == "explicit_name"
assert agent.description == "explicit description"


def test_as_agent_no_name_anywhere(mock_project_client: MagicMock) -> None:
"""Test that Agent.name is None when neither as_agent name nor client.agent_name is provided."""
client = create_test_azure_ai_client(mock_project_client)

agent = client.as_agent(instructions="You are helpful.")

assert agent.name is None


def test_as_agent_empty_string_preserves_explicit_value(mock_project_client: MagicMock) -> None:
"""Test that empty-string name/description are preserved and do not fall back to client defaults."""
client = create_test_azure_ai_client(mock_project_client, agent_name="client_name")
client.agent_description = "client description"

agent = client.as_agent(name="", description="", instructions="You are helpful.")

assert agent.name == ""
assert agent.description == ""


async def test_async_context_manager(mock_project_client: MagicMock) -> None:
"""Test async context manager functionality."""
client = create_test_azure_ai_client(mock_project_client, should_close_client=True)
Expand Down