Python: Fix as_agent() not defaulting name/description from client properties (#4484)

* Fix as_agent() not defaulting name/description from client properties

AzureAIClient.as_agent() and AzureAIAgentClient.as_agent() now fall back
to self.agent_name and self.agent_description when name/description are
not explicitly passed. This ensures Agent.name is populated for
telemetry spans without requiring callers to repeat the name.

Fixes #4471

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Address review: use is None checks instead of truthiness

Switch from name or self.agent_name to explicit is None checks so
that callers can intentionally pass empty strings without them being
replaced by client defaults. Added edge-case tests for empty strings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Update docstrings to document name/description defaulting behavior

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Giles Odigwe
2026-03-05 12:12:11 -08:00
committed by GitHub
Unverified
parent 8bf4235f4e
commit ce7b5b17c1
4 changed files with 94 additions and 8 deletions
@@ -1461,8 +1461,9 @@ class AzureAIAgentClient(
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.
@@ -1475,8 +1476,8 @@ class AzureAIAgentClient(
"""
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,
@@ -1189,8 +1189,9 @@ class RawAzureAIClient(RawOpenAIResponsesClient[AzureAIClientOptionsT], Generic[
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.
@@ -1203,8 +1204,8 @@ class RawAzureAIClient(RawOpenAIResponsesClient[AzureAIClientOptionsT], Generic[
"""
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,