Skip to content

fix(tool): support Flux-returning tool methods#1171

Closed
Alexxigang wants to merge 1 commit into
agentscope-ai:mainfrom
Alexxigang:fix/flux-tool-stream-bridging
Closed

fix(tool): support Flux-returning tool methods#1171
Alexxigang wants to merge 1 commit into
agentscope-ai:mainfrom
Alexxigang:fix/flux-tool-stream-bridging

Conversation

@Alexxigang

Copy link
Copy Markdown
Contributor

Summary

  • add native Flux handling in ToolMethodInvoker instead of treating it as a synchronous object
  • stream each emitted Flux item through ToolEmitter so tool chunk callbacks receive incremental updates
  • aggregate Flux items into the final tool result while preserving sensible behavior for single-value and multi-value non-string streams
  • add regression coverage for invoker-level aggregation/chunk emission and toolkit-level async execution

Why this fix

Issue #938 happens because invokeAsync(...) only special-cases CompletableFuture and Mono. When a tool method returns Flux<?>, the current code falls through the synchronous branch, serializes the Flux object itself, and never subscribes to the stream. That means the parent agent never waits for or consumes the streamed tool output.

This change subscribes to Flux results, forwards intermediate chunks to hooks, and converts the aggregated stream output into the final ToolResultBlock returned to the LLM-facing caller.

Validation

  • mvn -pl agentscope-core '-Dtest=AsyncToolTest,ToolMethodInvokerTest' test
  • mvn -pl agentscope-core '-Dtest=ToolIntegrationTest' test

AI Assistance

  • Drafted with AI assistance and reviewed/validated locally before submission.

@Alexxigang

Copy link
Copy Markdown
Contributor Author

Friendly ping when maintainers have time. The change is ready on my side, and I'm happy to make any follow-up adjustments if review feedback comes in. Thanks!

@codecov

codecov Bot commented Apr 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.46939% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ava/io/agentscope/core/tool/ToolMethodInvoker.java 73.46% 4 Missing and 9 partials ⚠️

📢 Thoughts on this report? Let us know!

item ->
emitFluxChunk(
emitter, converter, item, itemType))
.collectList()

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.

Caution: collectList() collects the entire Flux into memory. Using this on an unbounded or extremely large stream (like a DB cursor) risks triggering an OOM.

@LearningGp LearningGp added the wait-for-response PRs that require further response label May 15, 2026
@github-actions

Copy link
Copy Markdown

Closing due to inactivity. Feel free to reopen when ready.

@github-actions github-actions Bot added the stale label May 23, 2026
@github-actions github-actions Bot closed this May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale wait-for-response PRs that require further response

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants