fix(agno): Add agent.name attribute and fix Team span attributes being overwritten by members #2516
+12
−2
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
This PR includes two changes to the Agno instrumentation:
agent.nameattribute to Agent and Team spansChanges
1. Add
agent.nameattributeAdded
SpanAttributes.AGENT_NAMEto both Agent and Team spans to properly identify the agent/team name in traces. This attribute is now set alongsideGRAPH_NODE_NAMEfor better trace visibility.Files changed:
_runs_wrapper.py: Addedyield SpanAttributes.AGENT_NAME, agent.namefor both Team and Agent casesagent.nameattribute is present2. Bug Fix: Team span attributes overwritten by members
Problem:
When a Team span was created, the
_agent_run_attributesfunction was recursively calling itself for each member Agent. This caused member Agent attributes (includingGRAPH_NODE_NAMEandAGENT_NAME) to be added to the Team's span attribute dictionary. Since dictionaries cannot have duplicate keys, the last member's attributes would overwrite the Team's attributes, resulting in incorrect Team span attributes.Root Cause:
The recursive call
yield from _agent_run_attributes(member, f".{member.name}")on line 142 was adding member attributes to the Team's span. Member Agents should have their own spans when they execute, not have their attributes added to the Team's span.Solution:
Removed the recursive call that added member attributes to the Team's span. Member Agents will now correctly have their own spans with their own attributes when they run, and the Team's span will retain the correct Team attributes.
Files changed:
_runs_wrapper.py: Removed the loop that recursively called_agent_run_attributesfor Team membersTesting
agent.nameattribute is present on Agent and Team spansImpact
agent.nameattribute is now available on all Agent and Team spans for better trace identificationNote
Add
agent.nameto Agent/Team spans and prevent Team span attributes from being overwritten by member agents; update tests accordingly._runs_wrapper.py):SpanAttributes.AGENT_NAMEalongsideGRAPH_NODE_NAMEfor bothAgentandTeamspans.Teamto prevent overwriting Team span attributes.tests/test_instrumentor.pyandtests/test_workflow_instrumentation.pyto assertagent.nameon relevant spans and validate graph relationships (Team root, agents as children).Written by Cursor Bugbot for commit 31b1dbc. This will update automatically on new commits. Configure here.