Skip to content

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

Open
giles17 wants to merge 3 commits intomicrosoft:mainfrom
giles17:v2-client-agent-name
Open

Python: Fix as_agent() not defaulting name/description from client properties#4484
giles17 wants to merge 3 commits intomicrosoft:mainfrom
giles17:v2-client-agent-name

Conversation

@giles17
Copy link
Contributor

@giles17 giles17 commented Mar 4, 2026

Summary

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.

Problem

When creating an agent via AzureAIClient(agent_name="my_agent").as_agent(...), the resulting Agent.name was None because as_agent() never consulted the client's stored agent_name. This caused OpenTelemetry spans to record agent_name=None instead of the actual agent name.

Fix

One-line change in each client's as_agent() override:

  • name=name or self.agent_name
  • description=description or self.agent_description

This matches the pattern already used by AzureAIProjectAgentProvider._to_chat_agent_from_details(), which explicitly passes the same name to both the client constructor and the Agent constructor.

Tests

Added 6 new unit tests (3 per client) covering:

  • Default name/description inherited from client properties
  • Explicit name/description overrides client properties
  • No name set anywhere results in None

All 191 azure-ai tests pass.

Fixes #4471

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 microsoft#4471

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 4, 2026 23:54
@giles17 giles17 changed the title Fix as_agent() not defaulting name/description from client properties Fix as_agent() not defaulting name/description from client properties Mar 4, 2026
@github-actions github-actions bot changed the title Fix as_agent() not defaulting name/description from client properties Python: Fix as_agent() not defaulting name/description from client properties Mar 4, 2026
@giles17 giles17 changed the title Python: Fix as_agent() not defaulting name/description from client properties Python: Fix as_agent() not defaulting name/description from client properties Mar 4, 2026
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Mar 4, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/azure-ai/agent_framework_azure_ai
   _chat_client.py4797484%415–416, 418, 602, 607–608, 610–611, 614, 617, 619, 624, 885–886, 888, 891, 894, 897–902, 905, 907, 915, 927–929, 933, 936–937, 945–948, 958, 966–969, 971–972, 974–975, 982, 990–991, 999–1000, 1005–1006, 1010–1017, 1022, 1025, 1033, 1039, 1047–1049, 1052, 1074–1075, 1208, 1236, 1251, 1367
   _client.py4005087%392, 394, 417, 441, 449–461, 474, 535, 550–555, 598, 614–615, 641–642, 660, 695, 697, 718–719, 722, 763, 766, 768, 859, 890, 932, 1141, 1144, 1147–1148, 1150–1153
TOTAL22607279187% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
4707 25 💤 0 ❌ 0 🔥 1m 24s ⏱️

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a telemetry/observability gap in the Azure AI Python clients by ensuring as_agent() propagates agent_name / agent_description stored on the client into the created Agent when callers don’t explicitly provide name/description.

Changes:

  • Update AzureAIClient.as_agent() to default name/description from self.agent_name / self.agent_description.
  • Update AzureAIAgentClient.as_agent() with the same defaulting behavior.
  • Add unit tests for both clients covering defaulting, explicit overrides, and the “no name set anywhere” case.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
python/packages/azure-ai/agent_framework_azure_ai/_client.py Default Agent.name/description from client properties when not provided to as_agent().
python/packages/azure-ai/agent_framework_azure_ai/_chat_client.py Apply the same defaulting logic for the agent-based chat client’s as_agent().
python/packages/azure-ai/tests/test_azure_ai_client.py Add unit tests verifying AzureAIClient.as_agent() defaulting/override behavior.
python/packages/azure-ai/tests/test_azure_ai_agent_client.py Add unit tests verifying AzureAIAgentClient.as_agent() defaulting/override behavior.

You can also share your feedback on Copilot code review. Take the survey.

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>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@giles17 giles17 enabled auto-merge March 5, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: AzureAIClient.as_agent() does not use agent_name for ChatAgent.name

4 participants