Skip to content

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

Open
Alexxigang wants to merge 1 commit intoagentscope-ai:mainfrom
Alexxigang:fix/flux-tool-stream-bridging
Open

fix(tool): support Flux-returning tool methods#1171
Alexxigang wants to merge 1 commit intoagentscope-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.

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.

1 participant