Python: Fix as_agent() not defaulting name/description from client properties#4484
Open
giles17 wants to merge 3 commits intomicrosoft:mainfrom
Open
Python: Fix as_agent() not defaulting name/description from client properties#4484giles17 wants to merge 3 commits intomicrosoft:mainfrom
as_agent() not defaulting name/description from client properties#4484giles17 wants to merge 3 commits intomicrosoft:mainfrom
Conversation
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>
as_agent() not defaulting name/description from client properties
as_agent() not defaulting name/description from client propertiesas_agent() not defaulting name/description from client properties
Member
Python Test Coverage Report •
Python Unit Test Overview
|
|||||||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
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 defaultname/descriptionfromself.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.
python/packages/azure-ai/agent_framework_azure_ai/_chat_client.py
Outdated
Show resolved
Hide resolved
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>
Contributor
There was a problem hiding this comment.
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>
dmytrostruk
approved these changes
Mar 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AzureAIClient.as_agent()andAzureAIAgentClient.as_agent()now fall back toself.agent_nameandself.agent_descriptionwhenname/descriptionare not explicitly passed. This ensuresAgent.nameis 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 resultingAgent.namewasNonebecauseas_agent()never consulted the client's storedagent_name. This caused OpenTelemetry spans to recordagent_name=Noneinstead of the actual agent name.Fix
One-line change in each client's
as_agent()override:name=name or self.agent_namedescription=description or self.agent_descriptionThis matches the pattern already used by
AzureAIProjectAgentProvider._to_chat_agent_from_details(), which explicitly passes the same name to both the client constructor and theAgentconstructor.Tests
Added 6 new unit tests (3 per client) covering:
NoneAll 191 azure-ai tests pass.
Fixes #4471