Skip to content

fix(claude-agent-sdk): Fix subagents span nesting and input#2119

Open
Luca Forstner (lforst) wants to merge 3 commits into
mainfrom
lforst/validate-github-issue-v1
Open

fix(claude-agent-sdk): Fix subagents span nesting and input#2119
Luca Forstner (lforst) wants to merge 3 commits into
mainfrom
lforst/validate-github-issue-v1

Conversation

@lforst

@lforst Luca Forstner (lforst) commented Jun 15, 2026

Copy link
Copy Markdown
Member

Example stream:

Root user:
  "Solve this using a math sub-agent"

Root assistant:
  calls Agent tool with prompt:
  "Add 15 and 27"

Sub-agent user message, parent_tool_use_id=agent-1:
  "Add 15 and 27"        <-- this is the sub-agent prompt

Sub-agent assistant:
  calls calculator tool

Sub-agent user message, parent_tool_use_id=agent-1:
  tool_result: "42"

Prev (bad):

root trace
├─ root LLM
│  └─ Agent(prompt: "Add 15 and 27")
└─ sub-agent
   ├─ LLM input: "Add 15 and 27"
   └─ LLM input: "42"                 <-- wrong: tool result treated like prompt

Now (good):

root trace
├─ root LLM
│  └─ Agent(prompt: "Add 15 and 27")
└─ sub-agent
   ├─ LLM turn 1
   │  ├─ input:
   │  │  └─ user: "Add 15 and 27"
   │  └─ output:
   │     └─ assistant tool_use: calculator
   └─ LLM turn 2
      ├─ input:
      │  ├─ user: "Add 15 and 27"
      │  ├─ assistant tool_use: calculator
      │  └─ user tool_result: "42"
      └─ output:
         └─ assistant: "The answer is 42"

Fixes #2103

@lforst Luca Forstner (lforst) marked this pull request as ready for review June 15, 2026 14:36
parent: await resolveParentSpan(toolUseID, {
agentId: input.agent_id,
preferTaskSiblingParent: shouldParentToolAsTaskSibling(parsed.toolName),
preferTaskSiblingParent: true,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

seems like preferTaskSiblingParent is always true now? Do we even need an option?

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.

wrapClaudeAgentSDK: sub-agent anthropic.messages.create span gets the ROOT conversation as input (wrong)

2 participants