Skip to content

fix(claude-agent-sdk): use msg_id for tool-call parent_message_id on fallback path (#2118)#2153

Merged
BenTaylorDev merged 2 commits into
ag-ui-protocol:mainfrom
enginerd-kr:fix/issue-2118-subagent-parent-message-id
Jul 14, 2026
Merged

fix(claude-agent-sdk): use msg_id for tool-call parent_message_id on fallback path (#2118)#2153
BenTaylorDev merged 2 commits into
ag-ui-protocol:mainfrom
enginerd-kr:fix/issue-2118-subagent-parent-message-id

Conversation

@enginerd-kr

Copy link
Copy Markdown
Contributor

Fixes #2118.

Changes

  • Compute msg_id once, outside the AssistantMessage-only branch, in
    the non-streaming fallback path
  • Pass msg_id (not the stale current_message_id, already None here)
    as parent_message_id to handle_tool_use_block()

Testing

  • New test test_subagent_tool_call_gets_parent_message_id; confirmed it
    fails on the pre-fix code (parent_message_id is None)
  • Full suite: 107 passed

…fallback path

The non-streaming fallback branch (how a programmatic subagent's own turn
arrives, as a complete AssistantMessage) computes the correct assistant
message id (msg_id) to build/upsert that message, but passes the stale
current_message_id — already None on this path — into
handle_tool_use_block(), so the tool call's TOOL_CALL_START carries no
parent_message_id.

Fixes ag-ui-protocol#2118
@enginerd-kr
enginerd-kr requested a review from a team as a code owner July 10, 2026 12:53
@enginerd-kr

Copy link
Copy Markdown
Contributor Author

@jpr5 — this one wasn't pre-discussed on the issue (no response there), but the fix is small and self-contained, so I went ahead and opened it. Would appreciate a look when you have a moment.

@BenTaylorDev BenTaylorDev 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.

Verified locally (bootstrapped the Python package and ran it):

  • Correct fix: hoisting msg_id = current_message_id or str(uuid.uuid4()) above the AssistantMessage-only branch means the tool-use block's parent_message_id is the same id used to build the assistant message, so a fallback-path tool call now points at its containing message instead of None (#2118). It also stays consistent with the streaming path, and the UserMessage case is harmless (tool_use blocks only appear in AssistantMessage, so the loop won't match there).
  • RED→GREEN confirmed: reverting just parent_message_id=msg_id back to current_message_id fails the new test with assert None is not None; the fix passes it.
  • The test is solid — it asserts the id is non-null, is not the SDK's parent_tool_use_id, and is a real id present in the run's MESSAGES_SNAPSHOT (not a placeholder).
  • Full suite: 107 passed.

One coordination note (not a change request): this overlaps #2152, which edits the same fallback region — it adds unstreamed_fallback_ids.add(msg_id) right after the msg_id = … line inside the AssistantMessage branch, whereas this PR hoists msg_id out of that branch. They don't conflict semantically, but whichever lands second will need a small rebase. Worth sequencing them since both are yours.

I bless the code with a glad heart.

@github-actions

Copy link
Copy Markdown
Contributor

Python Preview Packages

Version 0.0.0.dev1783839093 published to TestPyPI.

Warning: These packages are built from contributor code that may not yet have been vetted for correctness or security. Install at your own risk and do not use in production.

Install with uv

Add the TestPyPI index to your pyproject.toml:

[[tool.uv.index]]
name = "testpypi"
url = "https://test.pypi.org/simple/"
explicit = true

Then install the packages you need:

# Core SDK
uv add 'ag-ui-protocol==0.0.0.dev1783839093' --index testpypi

# Integrations (each already depends on the matching ag-ui-protocol preview)
uv add 'ag-ui-langgraph==0.0.0.dev1783839093' --index testpypi
uv add 'ag-ui-crewai==0.0.0.dev1783839093' --index testpypi
# NOTE: ag-ui-agent-spec depends on pyagentspec (git-only, not on PyPI).
# You will need to install pyagentspec separately from its git repo.
uv add 'ag-ui-agent-spec==0.0.0.dev1783839093' --index testpypi
uv add 'ag_ui_adk==0.0.0.dev1783839093' --index testpypi
uv add 'ag_ui_strands==0.0.0.dev1783839093' --index testpypi

Install with pip

pip install \
  --index-url https://test.pypi.org/simple/ \
  --extra-index-url https://pypi.org/simple/ \
  ag-ui-protocol==0.0.0.dev1783839093

Use --extra-index-url https://pypi.org/simple/ so pip can resolve
transitive dependencies (pydantic, fastapi, etc.) from real PyPI.


Commit: 3f6cf92

@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

@ag-ui/a2a-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/a2a-middleware@2153

@ag-ui/a2ui-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/a2ui-middleware@2153

@ag-ui/event-throttle-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/event-throttle-middleware@2153

@ag-ui/mcp-apps-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/mcp-apps-middleware@2153

@ag-ui/mcp-middleware

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/mcp-middleware@2153

@ag-ui/a2a

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/a2a@2153

@ag-ui/adk

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/adk@2153

@ag-ui/ag2

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/ag2@2153

@ag-ui/agno

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/agno@2153

@ag-ui/aws-strands

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/aws-strands@2153

@ag-ui/claude-agent-sdk

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/claude-agent-sdk@2153

@ag-ui/crewai

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/crewai@2153

@ag-ui/langchain

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/langchain@2153

@ag-ui/langgraph

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/langgraph@2153

@ag-ui/llamaindex

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/llamaindex@2153

@ag-ui/mastra

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/mastra@2153

@ag-ui/pydantic-ai

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/pydantic-ai@2153

@ag-ui/vercel-ai-sdk

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/vercel-ai-sdk@2153

@ag-ui/watsonx

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/watsonx@2153

@ag-ui/a2ui-toolkit

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/a2ui-toolkit@2153

create-ag-ui-app

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/create-ag-ui-app@2153

@ag-ui/client

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/client@2153

@ag-ui/core

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/core@2153

@ag-ui/encoder

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/encoder@2153

@ag-ui/proto

pnpm add https://pkg.pr.new/ag-ui-protocol/ag-ui/@ag-ui/proto@2153

commit: 81d0b2a

@BenTaylorDev
BenTaylorDev merged commit 0960bcf into ag-ui-protocol:main Jul 14, 2026
33 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.

[Bug]: ag-ui-claude-sdk drops parentMessageId on subagent tool calls (non-streaming fallback path)

2 participants