Skip to content

Commit 31e2155

Browse files
authored
adding more agent creation traces (#44263)
* adding more agent creation traces * change based on review comments
1 parent 2f728ba commit 31e2155

File tree

2 files changed

+69
-10
lines changed

2 files changed

+69
-10
lines changed

sdk/ai/azure-ai-projects/azure/ai/projects/telemetry/_ai_project_instrumentor.py

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@
4040
GEN_AI_RUN_STEP_END_TIMESTAMP,
4141
GEN_AI_RUN_STEP_STATUS,
4242
GEN_AI_AGENT_VERSION,
43+
GEN_AI_AGENT_HOSTED_CPU,
44+
GEN_AI_AGENT_HOSTED_MEMORY,
45+
GEN_AI_AGENT_HOSTED_IMAGE,
46+
GEN_AI_AGENT_HOSTED_PROTOCOL,
47+
GEN_AI_AGENT_HOSTED_PROTOCOL_VERSION,
48+
AGENT_TYPE_PROMPT,
49+
AGENT_TYPE_WORKFLOW,
50+
AGENT_TYPE_HOSTED,
51+
AGENT_TYPE_UNKNOWN,
52+
GEN_AI_AGENT_TYPE,
4353
ERROR_MESSAGE,
4454
OperationName,
4555
start_span,
@@ -530,6 +540,11 @@ def start_create_agent_span( # pylint: disable=too-many-locals
530540
structured_inputs: Optional[Any] = None,
531541
agent_type: Optional[str] = None,
532542
workflow_yaml: Optional[str] = None,
543+
hosted_cpu: Optional[str] = None,
544+
hosted_memory: Optional[str] = None,
545+
hosted_image: Optional[str] = None,
546+
hosted_protocol: Optional[str] = None,
547+
hosted_protocol_version: Optional[str] = None,
533548
) -> "Optional[AbstractSpan]":
534549
span = start_span(
535550
OperationName.CREATE_AGENT,
@@ -551,7 +566,19 @@ def start_create_agent_span( # pylint: disable=too-many-locals
551566
if description:
552567
span.add_attribute(GEN_AI_AGENT_DESCRIPTION, description)
553568
if agent_type:
554-
span.add_attribute("gen_ai.agent.type", agent_type)
569+
span.add_attribute(GEN_AI_AGENT_TYPE, agent_type)
570+
571+
# Add hosted agent specific attributes
572+
if hosted_cpu:
573+
span.add_attribute(GEN_AI_AGENT_HOSTED_CPU, hosted_cpu)
574+
if hosted_memory:
575+
span.add_attribute(GEN_AI_AGENT_HOSTED_MEMORY, hosted_memory)
576+
if hosted_image:
577+
span.add_attribute(GEN_AI_AGENT_HOSTED_IMAGE, hosted_image)
578+
if hosted_protocol:
579+
span.add_attribute(GEN_AI_AGENT_HOSTED_PROTOCOL, hosted_protocol)
580+
if hosted_protocol_version:
581+
span.add_attribute(GEN_AI_AGENT_HOSTED_PROTOCOL_VERSION, hosted_protocol_version)
555582

556583
# Extract response schema from text parameter if available
557584
response_schema = None
@@ -647,19 +674,41 @@ def _create_agent_span_from_parameters(
647674
workflow_yaml = definition.get("workflow") # Extract workflow YAML for workflow agents
648675
# toolset = definition.get("toolset")
649676

677+
# Extract hosted agent specific attributes
678+
hosted_cpu = definition.get("cpu")
679+
hosted_memory = definition.get("memory")
680+
hosted_image = definition.get("image")
681+
hosted_protocol = None
682+
hosted_protocol_version = None
683+
container_protocol_versions = definition.get("container_protocol_versions")
684+
if container_protocol_versions and len(container_protocol_versions) > 0:
685+
# Extract protocol and version from first entry
686+
protocol_record = container_protocol_versions[0]
687+
if hasattr(protocol_record, "protocol"):
688+
hosted_protocol = getattr(protocol_record, "protocol", None)
689+
elif isinstance(protocol_record, dict):
690+
hosted_protocol = protocol_record.get("protocol")
691+
692+
if hasattr(protocol_record, "version"):
693+
hosted_protocol_version = getattr(protocol_record, "version", None)
694+
elif isinstance(protocol_record, dict):
695+
hosted_protocol_version = protocol_record.get("version")
696+
650697
# Determine agent type from definition
651-
# Check for workflow first (most specific)
698+
# Check for hosted agent first (most specific - has container/image configuration)
652699
agent_type = None
653-
if workflow_yaml:
654-
agent_type = "workflow"
700+
if hosted_image or hosted_cpu or hosted_memory:
701+
agent_type = AGENT_TYPE_HOSTED
702+
elif workflow_yaml:
703+
agent_type = AGENT_TYPE_WORKFLOW
655704
elif instructions or model:
656705
# Prompt agent - identified by having instructions and/or a model.
657706
# Note: An agent with only a model (no instructions) is treated as a prompt agent,
658707
# though this is uncommon. Typically prompt agents have both model and instructions.
659-
agent_type = "prompt"
708+
agent_type = AGENT_TYPE_PROMPT
660709
else:
661710
# Unknown type - set to "unknown" to indicate we couldn't determine it
662-
agent_type = "unknown"
711+
agent_type = AGENT_TYPE_UNKNOWN
663712

664713
# Extract reasoning effort and summary from reasoning if available
665714
reasoning_effort = None
@@ -739,6 +788,11 @@ def _create_agent_span_from_parameters(
739788
structured_inputs=structured_inputs,
740789
agent_type=agent_type,
741790
workflow_yaml=workflow_yaml,
791+
hosted_cpu=hosted_cpu,
792+
hosted_memory=hosted_memory,
793+
hosted_image=hosted_image,
794+
hosted_protocol=hosted_protocol,
795+
hosted_protocol_version=hosted_protocol_version,
742796
)
743797

744798
def trace_create_agent(self, function, *args, **kwargs):

sdk/ai/azure-ai-projects/azure/ai/projects/telemetry/_utils.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@
7474
GEN_AI_RESPONSE_OBJECT = "gen_ai.response.object"
7575
GEN_AI_TOKEN_TYPE = "gen_ai.token.type"
7676
GEN_AI_MESSAGE_ROLE = "gen_ai.message.role"
77+
GEN_AI_AGENT_TYPE = "gen_ai.agent.type"
78+
GEN_AI_CONVERSATION_ITEM_TYPE = "gen_ai.conversation.item.type"
79+
GEN_AI_AGENT_HOSTED_CPU = "gen_ai.agent.hosted.cpu"
80+
GEN_AI_AGENT_HOSTED_MEMORY = "gen_ai.agent.hosted.memory"
81+
GEN_AI_AGENT_HOSTED_IMAGE = "gen_ai.agent.hosted.image"
82+
GEN_AI_AGENT_HOSTED_PROTOCOL = "gen_ai.agent.hosted.protocol"
83+
GEN_AI_AGENT_HOSTED_PROTOCOL_VERSION = "gen_ai.agent.hosted.protocol_version"
7784

7885
# Event names
7986
GEN_AI_USER_MESSAGE_EVENT = "gen_ai.input.messages"
@@ -88,15 +95,13 @@
8895
GEN_AI_CLIENT_OPERATION_DURATION = "gen_ai.client.operation.duration"
8996
GEN_AI_CLIENT_TOKEN_USAGE = "gen_ai.client.token.usage"
9097

91-
# Additional attribute names for agents
92-
GEN_AI_AGENT_TYPE = "gen_ai.agent.type"
93-
GEN_AI_CONVERSATION_ITEM_TYPE = "gen_ai.conversation.item.type"
94-
9598
# Constant attribute values
9699
AZURE_AI_AGENTS_SYSTEM = "az.ai.agents"
97100
AZURE_AI_AGENTS_PROVIDER = "azure.ai.agents"
98101
AGENT_TYPE_PROMPT = "prompt"
99102
AGENT_TYPE_WORKFLOW = "workflow"
103+
AGENT_TYPE_HOSTED = "hosted"
104+
AGENT_TYPE_UNKNOWN = "unknown"
100105

101106

102107
class OperationName(Enum):

0 commit comments

Comments
 (0)