Skip to content

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

Open
dvirski wants to merge 1 commit into
mainfrom
dr/fix(sdk)-@agent-decorator-no-longer-overwrites-enclosing-@workflow-name
Open

fix(sdk): @agent decorator no longer overwrites enclosing @workflow name#4288
dvirski wants to merge 1 commit 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.

Now @agent only sets workflow_name when one is not already in context,
preserving fallback behavior for bare @agent (no enclosing @workflow) while
fixing the nested case.

Summary by CodeRabbit

  • Refactor
    • Enhanced trace context handling to improve accuracy when recording workflow and agent names in observability data.

@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: f4ab96f0-cb9b-442f-a546-e4879dbc3e6a

📥 Commits

Reviewing files that changed from the base of the PR and between fc33f1c and ab43b80.

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

📝 Walkthrough

Walkthrough

In _setup_span, the branching logic for OpenTelemetry context assignment is split by span kind: WORKFLOW now exclusively sets the workflow name, while AGENT sets the agent name and only writes the workflow name when one is not already present in the context.

Changes

AGENT span workflow name conditional assignment

Layer / File(s) Summary
Conditional workflow_name write for AGENT spans
packages/traceloop-sdk/traceloop/sdk/decorators/base.py
WORKFLOW span kind sets only the workflow name; AGENT span kind sets the agent name and sets workflow name only if workflow_name is absent from the current context, preventing nested agents from overwriting an already-established workflow name.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

🐇 A workflow name was set with care,
But agents overwrote it — most unfair!
Now AGENT checks before it writes,
"Is workflow_name here? Then I shan't fight."
The context stays tidy, the root name holds tight. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main bug fix: preventing the @agent decorator from overwriting the workflow name set by an enclosing @workflow decorator.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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?

if tlp_span_kind == TraceloopSpanKindValues.AGENT:
elif tlp_span_kind == TraceloopSpanKindValues.AGENT:
set_agent_name(entity_name)
if context_api.get_value("workflow_name") is None:

@galzilber galzilber Jun 18, 2026

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.

const it please no magic strings

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.

3 participants