Skip to content

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

@pjyi2147

Description

@pjyi2147

Description

AzureAIClient.as_agent() does not forward self.agent_name to the ChatAgent it creates. This causes ChatAgent.name to be None even when agent_name was provided to the AzureAIClient constructor, breaking observability/telemetry.

What happened?

  • When creating an agent via AzureAIClient(agent_name="my_agent").as_agent(...), the resulting ChatAgent.name is None.
  • The _trace_agent_run decorator in observability.py reads self.name for span attributes (agent_name=self.name), which evaluates to None.
  • Telemetry spans show agent_name=None instead of the actual agent name.

What did you expect to happen?

  • ChatAgent.name should default to self.agent_name when name is not explicitly passed to as_agent().
  • Telemetry spans should correctly reflect the agent name.

Steps to reproduce:

  1. Create an AzureAIClient with agent_name set.
  2. Call .as_agent() without passing name=.
  3. Observe that ChatAgent.name is None.

Code Sample

from agent_framework_azure_ai import AzureAIClient

client = AzureAIClient(
    credential=credential,
    agent_name="my_agent",           # agent_name is set here
    model_deployment_name="gpt-4",
)

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

print(agent.name)  # None — expected: "my_agent"


**Root cause in `agent_framework_azure_ai/_client.py`:**


# AzureAIClient.__init__ stores agent_name:
self.agent_name = agent_name  # e.g. "my_agent"

# But as_agent() does NOT use it as a default:
def as_agent(self, *, name: str | None = None, ...):
    return super().as_agent(name=name, ...)  # name stays None

Error Messages / Stack Traces

No error is raised — the issue is silent. `ChatAgent.name` is simply `None`, causing telemetry spans in `_trace_agent_run` (observability.py) to record `agent_name=<agent_uuid>`.

Package Versions

agent-framework: 1.0.0b260130, agent-framework-azure-ai: 1.0.0b260130, agent-framework-core: 1.0.0b260130

Python Version

Python 3.10

Additional Context

The AzureAIClient has two separate name concepts that are not bridged:

  1. self.agent_name — used for server-side Azure AI agent creation (passed to project_client.agents.create_or_update)
  2. ChatAgent.name (from BaseAgent) — used for OpenTelemetry observability via _trace_agent_run

as_agent() creates the ChatAgent but never connects these two. The _update_agent_name_and_description method only copies ChatAgent.nameAzureAIClient.agent_name (not the other direction), and since ChatAgent.name is None, the condition if agent_name is False, so nothing happens.

Current workaround: Explicitly pass name= to as_agent():

agent = client.as_agent(name="my_agent", instructions="...")

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpythonv1.0Features being tracked for the version 1.0 GA

Type

Projects

Status

In Review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions