Skip to content

fix(sdk): @agent decorator no longer overwrites enclosing @workflow name#4288

Merged
dvirski merged 3 commits into
mainfrom
dr/fix(sdk)-@agent-decorator-no-longer-overwrites-enclosing-@workflow-name
Jun 21, 2026
Merged

fix(sdk): @agent decorator no longer overwrites enclosing @workflow name#4288
dvirski merged 3 commits into
mainfrom
dr/fix(sdk)-@agent-decorator-no-longer-overwrites-enclosing-@workflow-name

Conversation

@dvirski

@dvirski dvirski commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

The @agent decorator unconditionally called set_workflow_name(entity_name),
clobbering the workflow_name attached to the OTel context by an enclosing
@workflow. Child LLM spans then read the agent name as their workflow name,
making (agent_name, workflow_name) groupings collapse: the same agent
running under two different workflows became indistinguishable.

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Improved observability trace naming so workflow names are applied only to the appropriate span types, preventing agent spans from overwriting workflow context.
  • Tests

    • Added regression coverage verifying workflow/agent name behavior for nested and standalone agents, including distinct workflow names across multiple workflows.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8da6b9e4-0eda-4731-a6c2-fb0a9cd3f444

📥 Commits

Reviewing files that changed from the base of the PR and between b9c79bc and 14915ca.

📒 Files selected for processing (1)
  • packages/traceloop-sdk/tests/test_agent_workflow_context.py

📝 Walkthrough

Walkthrough

In _setup_span, the branching logic for OpenTelemetry context assignment is split by span kind using an if/elif structure: WORKFLOW spans set the workflow name, while AGENT spans set only the agent name without overwriting the workflow context. A new test module verifies that agents nested inside workflows inherit the workflow's workflow_name, that the same agent under different workflows maintains distinct workflow_name values, and that standalone agents do not set workflow_name.

Changes

AGENT span workflow name separation

Layer / File(s) Summary
Workflow name assignment by span kind
packages/traceloop-sdk/traceloop/sdk/decorators/base.py
WORKFLOW span kind sets the workflow name; AGENT span kind sets only the agent name. The prior unconditional workflow name assignment for AGENT spans is removed, preventing nested agents from overwriting the established workflow context.
Regression tests for context isolation
packages/traceloop-sdk/tests/test_agent_workflow_context.py
Three test cases verify: (1) agents nested in workflows inherit the workflow TRACELOOP_WORKFLOW_NAME without clobbering it; (2) the same agent name under two workflows produces distinct workflow_name values per workflow; (3) a bare agent without an enclosing workflow does not set workflow_name while still setting the agent name attribute.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 A workflow name was set with care,
But agents overwrote it — most unfair!
Now AGENT stays humble, sets agent alone,
The workflow_name keeps its throne,
Three tests ensure no chaos is shown! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.46% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: fixing the @agent decorator to prevent overwriting an enclosing @workflow's name.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dr/fix(sdk)-@agent-decorator-no-longer-overwrites-enclosing-@workflow-name

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment on lines +144 to +145
if context_api.get_value("workflow_name") is None:
set_workflow_name(entity_name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so if "workflow_name" is none we set entity_name as workflow name.

But if it's not None? It's never set?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was to keep the previous behavior in which agent spans that had no workflow parent were populating workflow name with the agent name itself, instead of leaving it empty.

But that's actually a wrong behavior.

After checking the web app and making sure it won't break anything. I removed this block.
It make senes that an agent span that's not part of a workflow will have empty workflow name.

Comment thread packages/traceloop-sdk/traceloop/sdk/decorators/base.py Outdated
@dvirski dvirski merged commit fb292d0 into main Jun 21, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants