Skip to content

feat(weave): trace Claude Agent SDK subagents - #7666

Merged
rgao-coreweave merged 4 commits into
masterfrom
rgao/claude-agent-sdk-python-subagent-tracing
Aug 5, 2026
Merged

feat(weave): trace Claude Agent SDK subagents#7666
rgao-coreweave merged 4 commits into
masterfrom
rgao/claude-agent-sdk-python-subagent-tracing

Conversation

@rgao-coreweave

@rgao-coreweave rgao-coreweave commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Represent Claude Agent SDK Agent and legacy Task calls as nested Python GenAI SubAgent spans.
  • Route delegated assistant messages, tools, nested agents, and results through their parent_tool_use_id ancestry.
  • Preserve model, prompt, result, error, description, and tool-call metadata on each subagent span.
  • Keep parallel subagents off the ambient OTel context while explicitly parenting their child LLM, tool, and subagent spans.

Stack

master
└── #7666 subagent tracing (this PR)
    └── #7665 async-iterable multi-turn tracing

This PR is directly based on master. #7665 is intentionally stacked on this branch.

Before and after

The same 24-span cassette replay was run on master and this PR. mission_control launches researcher, analyst, and reviewer concurrently; reviewer launches a nested fact_checker. Together they run WebSearch, WebFetch, Bash, Python, Read, and Checklist tools before the root agent synthesizes the result.

image image

In each link, select the Trace tree button (the branch icon) above the trace panel. The default flamegraph groups overlapping siblings, which can obscure the parent hierarchy.

Run Spans invoke_agent spans Maximum depth Result
master (fc63e44005) 24 1 1 All 23 operation spans are direct children of mission_control; delegate calls appear as ordinary Agent / Task tools.
Subagent-only head (7c2d3b987d) 24 5 3 Delegate chats and tools are grouped under their agents, including mission_control → reviewer → fact_checker → Read.

The resulting topology is:

mission_control
├── researcher
│   ├── WebSearch
│   └── WebFetch
├── analyst
│   ├── Bash
│   └── Python
└── reviewer
    ├── fact_checker
    │   └── Read
    └── Checklist

The parallel-subagent regression covers delegates closing in completion order rather than launch-stack order. The integration starts them with SubAgent.start(set_current=False): explicitly threaded child spans retain the hierarchy above, while unrelated application work remains under the root turn.

Testing

  • Source-asserted live Weave replay on master and the subagent-only head; queried span counts, parent IDs, and maximum depths match the table above.
  • Complete Claude Agent SDK cassette suites (OTel and calls-based) plus the conversation SubAgent suite: 46 passed on Python 3.11.
  • Ruff 0.15.5 check and format verification passed for all changed Python files.

Breaking changes

None.

Copy link
Copy Markdown
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.80952% with 34 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../integrations/claude_agent_sdk/otel_integration.py 79.39% 15 Missing and 19 partials ⚠️

📢 Thoughts on this report? Let us know!

@w-b-hivemind

w-b-hivemind Bot commented Jul 30, 2026

Copy link
Copy Markdown

HiveMind Sessions

9 sessions · 34s · $0.13

Session Agent Duration Tokens Cost Lines
Delegate Query To Researcher Subagent
ef9998ce-7878-4452-abbd-69f4885f30e8
claude 7s 245 $0.03 +0 -0
Code Word Memory Test
8c3c91e2-e1d9-4af2-8a19-51f1f86c7a68
claude 4s 11 $0.01 +0 -0
Identifying Square Color and Number
4b9b11a0-b60a-40d4-957e-b091cc5826e3
claude 2s 19 $0.01 +0 -0
Researcher Subagent Planet Query
3c2f7791-bf4d-4bc9-bcec-71b23e676766
claude 4s 241 $0.02 +0 -0
Code Word Memory Test
7d0bf574-da29-4a3c-891d-0f50d3858c37
claude 3s 20 $0.00 +0 -0
Identify Square Color and Number
f98e3dd3-ac85-4a24-b1db-c2a9d6c747a6
claude 1s 19 $0.00 +0 -0
Delegating Research Query To Subagent
f5e3f591-72e7-441a-92a8-e700d4c9ce5e
claude 5s 241 $0.03 +0 -0
Code Word Memory Test
aff0f637-4f11-443b-b080-3d6a25d1d7db
claude 3s 20 $0.01 +0 -0
Identifying Square Color and Number
816fef1d-a71a-46bf-a6d8-4ff6196d7aa8
claude 1s 19 $0.01 +0 -0
Total 34s 835 $0.13 +0 -0
Screenshots

View all sessions in HiveMind →

Run claude --resume ef9998ce-7878-4452-abbd-69f4885f30e8 to pickup where you left off.

@rgao-coreweave
rgao-coreweave marked this pull request as ready for review July 30, 2026 05:33
@rgao-coreweave
rgao-coreweave requested a review from a team as a code owner July 30, 2026 05:33
@rgao-coreweave
rgao-coreweave requested a review from a team July 30, 2026 16:49
Comment thread weave/integrations/claude_agent_sdk/otel_integration.py Outdated
@rgao-coreweave
rgao-coreweave force-pushed the rgao/claude-agent-sdk-python-subagent-tracing branch from 23b51b9 to 79d2ff0 Compare July 31, 2026 18:51
@rgao-coreweave
rgao-coreweave force-pushed the rgao/claude-agent-sdk-python-subagent-tracing branch from 79d2ff0 to 4f17c21 Compare July 31, 2026 23:01
@rgao-coreweave
rgao-coreweave force-pushed the rgao/claude-agent-sdk-python-subagent-tracing branch from 4f17c21 to d03a57b Compare July 31, 2026 23:48
@rgao-coreweave
rgao-coreweave changed the base branch from rgao/claude-agent-sdk-python-multi-turn to master August 3, 2026 16:50
@rgao-coreweave rgao-coreweave changed the title feat(weave): trace Claude Agent SDK subagents feat(weave): trace Claude Agent SDK multi-turn and subagent flows Aug 3, 2026
rgao-coreweave and others added 2 commits August 3, 2026 12:47
Parallel Agent/Task delegations close in completion order, not launch
order. SubAgent.__enter__ attached the span to the ambient OTel context
and end() detaches through ContextVar.reset, which assumes LIFO: closing
A before B left the context pointing at ended span A, so user code
running between streamed messages nested under a dead span.

Add SubAgent.start(set_current=False), which starts the span without
pushing it onto the ambient stack, and use it from the Claude Agent SDK
integration. Children nest either way, because start_llm / start_tool /
start_subagent thread an explicit parent context.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@rgao-coreweave
rgao-coreweave force-pushed the rgao/claude-agent-sdk-python-subagent-tracing branch from d03a57b to 7c2d3b9 Compare August 3, 2026 19:50
@rgao-coreweave rgao-coreweave changed the title feat(weave): trace Claude Agent SDK multi-turn and subagent flows feat(weave): trace Claude Agent SDK subagents Aug 3, 2026
@rgao-coreweave
rgao-coreweave requested a review from ro31337 August 4, 2026 05:43
Comment thread weave/integrations/claude_agent_sdk/otel_integration.py Outdated
Comment thread weave/integrations/claude_agent_sdk/otel_integration.py Outdated
Comment thread weave/integrations/claude_agent_sdk/otel_integration.py
@ro31337
ro31337 self-requested a review August 4, 2026 23:19

@ro31337 ro31337 left a comment

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.

@rgao-coreweave
rgao-coreweave merged commit 49f8c1d into master Aug 5, 2026
108 checks passed
@rgao-coreweave
rgao-coreweave deleted the rgao/claude-agent-sdk-python-subagent-tracing branch August 5, 2026 20:32
@rgao-coreweave

Copy link
Copy Markdown
Contributor Author

Approving as discussed here https://weightsandbiases.slack.com/archives/C0APFJB2H5E/p1785885124302999?thread_ts=1785849300.988039&cid=C0APFJB2H5E

Merging in, thanks for the review!

@github-actions github-actions Bot locked and limited conversation to collaborators Aug 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants