Skip to content

fix(adk): set streaming meta for agentic tool chunks#1045

Merged
shentongmartin merged 1 commit into
mainfrom
fix/agentic-tool-streaming-meta
May 28, 2026
Merged

fix(adk): set streaming meta for agentic tool chunks#1045
shentongmartin merged 1 commit into
mainfrom
fix/agentic-tool-streaming-meta

Conversation

@shentongmartin

@shentongmartin shentongmartin commented May 28, 2026

Copy link
Copy Markdown
Contributor

Agentic Tool Stream Metadata

Problem

Streamable tool results emitted through the ADK event sender were converted into AgenticMessage chunks without StreamingMeta.

Expected behavior:

  • streamed chunks from the same tool result are grouped by stream index
  • schema.ConcatAgenticMessages materializes them into one final function_tool_result block

Actual behavior:

  • every chunk looked like an independent non-streaming function_tool_result
  • materialization could not group chunks because the stream grouping signal was missing

Solution

Mark AgenticMessage chunks produced by typedToolStreamEvent and typedToolEnhancedStreamEvent with StreamingMeta{Index: 0}.

This matches the existing AgenticToolsNode.Stream behavior and gives schema.ConcatAgenticMessages the grouping signal it needs. The final materialized message still drops transient StreamingMeta; it only uses the metadata while concatenating stream chunks.

Key Insight

There are two Agentic tool streaming producers:

  • AgenticToolsNode.Stream, which already attaches StreamingMeta
  • ADK event-sender wrappers, which re-wrap tool stream chunks for user-visible events and also need to attach StreamingMeta

StreamingMeta is not persisted as final message state. It is a transient stream-concat hint used before materialization.

Summary

Problem Solution
ADK streamable tool chunks lacked StreamingMeta Set StreamingMeta{Index: 0} in typedToolStreamEvent
Enhanced streamable tool chunks had the same risk Set StreamingMeta{Index: 0} in typedToolEnhancedStreamEvent

Agentic 工具流式元数据

问题

ADK event sender 发出的 Streamable tool result 会被转换成 AgenticMessage chunk,但这些 chunk 没有 StreamingMeta

预期行为:

  • 同一个 tool result 的流式 chunk 按 stream index 分组
  • schema.ConcatAgenticMessages 将它们物化成一个最终的 function_tool_result block

实际行为:

  • 每个 chunk 都像独立的非流式 function_tool_result
  • 因缺少 stream 分组信号,物化过程无法将这些 chunk 归并到同一个 tool result

解决方案

typedToolStreamEventtypedToolEnhancedStreamEvent 生成的 AgenticMessage chunk 上设置 StreamingMeta{Index: 0}

这与现有 AgenticToolsNode.Stream 行为保持一致,并为 schema.ConcatAgenticMessages 提供正确的分组信号。最终物化后的 message 仍然不会保留临时的 StreamingMeta;它只在流式 chunk 拼接阶段使用。

关键洞察

Agentic tool streaming 有两个生产者:

  • AgenticToolsNode.Stream,它已经会设置 StreamingMeta
  • ADK event-sender wrappers,它会重新包装 tool stream chunk 作为用户可见事件,也需要设置 StreamingMeta

StreamingMeta 不是最终消息状态的一部分。它是物化前用于 stream concat 的临时分组信号。

总结

问题 解决方案
ADK streamable tool chunk 缺少 StreamingMeta typedToolStreamEvent 中设置 StreamingMeta{Index: 0}
enhanced streamable tool chunk 有同样风险 typedToolEnhancedStreamEvent 中设置 StreamingMeta{Index: 0}

@codecov

codecov Bot commented May 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.99%. Comparing base (804b9d4) to head (c04fb33).

Files with missing lines Patch % Lines
adk/wrappers.go 55.55% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1045      +/-   ##
==========================================
- Coverage   83.05%   82.99%   -0.07%     
==========================================
  Files         162      162              
  Lines       23029    23038       +9     
==========================================
- Hits        19127    19120       -7     
- Misses       2647     2659      +12     
- Partials     1255     1259       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shentongmartin shentongmartin force-pushed the fix/agentic-tool-streaming-meta branch from 2d87081 to 03613bc Compare May 28, 2026 08:23
Change-Id: I4d42e16cd420690625342d5097df4dbcae07cb8b
@shentongmartin shentongmartin force-pushed the fix/agentic-tool-streaming-meta branch from 03613bc to c04fb33 Compare May 28, 2026 08:34
Comment thread adk/wrappers.go
@shentongmartin shentongmartin merged commit 6f4057a into main May 28, 2026
17 of 19 checks passed
@shentongmartin shentongmartin deleted the fix/agentic-tool-streaming-meta branch May 28, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants