Skip to content

[Feature]: Deliver each tool result progressively as it completes during batch execution (progressiveToolResults) #3223

Closed

Description

@songdayi

AgentScope-Java is an open-source project. To involve a broader community, we recommend asking your questions in English.

Is your feature request related to a problem? Please describe.

When an LLM returns multiple tool_use blocks in a single reasoning response, AgentScope collects all tool results before emitting any ToolResultEndEvents. This means:

  1. All ToolResultEndEvents share the same createdAt timestamp — the moment the last tool finishes — so per-tool duration is indistinguishable.
  2. Downstream consumers (SSE, event pipeline, UI) see all results arrive simultaneously even if some tools completed much earlier.
  3. Per-tool latency cannot be measured from the event stream, making it impossible to display "Tool A took 50ms, Tool B took 300ms" in a dashboard.

The root cause is that ToolExecutor.executeAll() uses Flux.concat(chunks).collectList() (returning Mono<List<ToolResultBlock>>), and ReActAgent.runToolBatch() subscribes to this Mono, emitting all ToolResultEndEvents in a single batch callback after every tool has finished.

Describe the solution you'd like

Add a progressiveToolResults option to ToolkitConfig (default false for backward compatibility). When enabled:

  1. ToolExecutor gains an executeAllProgressive() method that returns Flux<ToolResultBlock> instead of Mono<List<ToolResultBlock>> — same concurrency-partitioning logic (concurrency-safe tools run in parallel via mergeSequential, unsafe tools get serial slots), just without collectList().

  2. Toolkit gains a callToolsProgressive() method delegating to executeAllProgressive().

  3. ReActAgent gains an executeToolCallsProgressive() method returning Flux<Map.Entry<ToolUseBlock, ToolResultBlock>>, with per-tool id matching. In runToolBatch(), a new if (progressive) branch emits each ToolResultEndEvent via subscribe(onNext, onError, onComplete) instead of waiting for the batch. Structured-output calls fall back to the batch path.

  4. PostActingEvent timing is unchanged — hooks still fire after all tools complete (via resultHolder), so existing hook aggregation logic is not affected.

  5. Error handling is per-tool — executeWithInfrastructure already wraps each tool in onErrorResume -> ToolResultBlock.error(...), so a single tool's failure produces an error result without terminating the stream.

Usage:

Toolkit toolkit = new Toolkit(
    ToolkitConfig.builder()
        .progressiveToolResults(true)
        .build()
);
ReActAgent agent = ReActAgent.builder()
        .model(model)
        .toolkit(toolkit)
        .build();

Before (all results delivered together):

T0: TOOL_CALL_START(A)  TOOL_CALL_START(B)  TOOL_CALL_START(C)
T1: TOOL_RESULT_END(A)  TOOL_RESULT_END(B)  TOOL_RESULT_END(C)  <- same timestamp
-> durationMs: A = B = C = T1 - T0

After (each result delivered on completion):

T0: TOOL_CALL_START(A)  TOOL_CALL_START(B)  TOOL_CALL_START(C)
T1: TOOL_RESULT_END(A)                    <- A completed first
T2:                       TOOL_RESULT_END(B)  <- B completed
T3:                                      TOOL_RESULT_END(C)  <- C completed
-> durationMs: A = T1-T0,  B = T2-T0,  C = T3-T0  <- distinct

Describe alternatives you've considered

  • Metadata-only approach (no execution model change): Record each tool's real completion time in ToolResultBlock.metadata via executeWithInfrastructure, then read it back when constructing ToolResultEndEvent. This requires zero architectural changes but events are still batch-delivered — only the timestamp is accurate, not the delivery timing. UI consumers that rely on event arrival order cannot display progressive results.

  • Change executeAll return type to Flux unconditionally: Breaking change — every caller of callTools / executeAll would need updating, including middleware, external executors, and user code.

  • PostActingEvent also progressive: Considered firing hooks per-tool on completion. Rejected because some hooks aggregate across tool results (e.g., conflict detection) and would break if fired before all results are available.

  • Naming: streamingToolResults: Initially considered but rejected because streaming in AgentScope is already associated with model-level streaming responses (streamEvents, StreamableAgent), which would cause naming confusion. progressive more accurately describes the per-tool progressive delivery semantics.

Additional context

When multiple tools are executed in a batch, tool results are not returned until all tools have finished executing. This causes a usability issue: the user's conversation appears to be hanging while waiting for tool results, even though some tools have already completed. Due to this framework limitation, completed results cannot be exposed to the user early. Exposing partial results as they become available would let users see real-time execution progress, significantly improving the user experience.

cur verison agentScope 2.0.2-subagent-bugfix

Activity

  1. added
    enhancement
    on Sep 21, 2026
  2. rudy2steiner commented on Sep 21, 2026

    @rudy2steiner
    Contributor

    i'll work on it

  3. songdayi commented on Sep 21, 2026

    @songdayi
    ContributorAuthor

    @rudy2steiner 标题写错了

    更正为 [Feature]: Deliver each tool result progressively as it completes during batch execution (progressiveToolResults)

    然后描述内容我也重新修订了

  4. changed the title [-][Feature]: Stream tool results individually as each tool completes (streamingToolResults)[/-] [+][Feature]: Deliver each tool result progressively as it completes during batch execution (progressiveToolResults)[/+] on Sep 21, 2026
  5. oss-maintainer commented on Sep 21, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: enhancement | Status: Evaluated — design questions remain (verified against main @ 8ca0080)

    Claims verified. The diagnosis is accurate on the current code:

    • ToolExecutor.executeAll() returns Mono<List<ToolResultBlock>> and collects the concatenated chunks before anything is published — agentscope-core/src/main/java/io/agentscope/core/tool/ToolExecutor.java:305-355.
    • ReActAgent subscribes once to that completed list and only then emits the ToolResultEndEvents — agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:3166-3261.
    • Per-tool failures are already isolated: individual infrastructure errors are converted to ToolResultBlock.error(...) — agentscope-core/src/main/java/io/agentscope/core/tool/ToolExecutor.java:397-406, so a per-tool error path in a progressive stream does not need new error plumbing.
    • Hook timing really is post-batch: the result holder completes before sequential PostActing processing — agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:2832-2857, :2880-2946.

    One correction: createdAt is not shared. Each event constructs its own Instant.now() — agentscope-core/src/main/java/io/agentscope/core/event/AgentEvent.java:105-113, agentscope-core/src/main/java/io/agentscope/core/event/ToolResultEndEvent.java:60-66. The timestamps are near-simultaneous and post-batch, not literally identical, so "all results share the same createdAt" overstates it. The underlying problem (delivery timing, not duration measurement) is real.

    Design points worth settling before code:

    1. Ordering. The safe lane uses mergeSequential, which preserves source order rather than completion order — agentscope-core/src/main/java/io/agentscope/core/tool/ToolExecutor.java:332-355. A progressive stream that emits on completion changes observable ordering for downstream consumers; that trade-off should be explicit in the flag's contract, not just in the implementation.
    2. Result pairing. The batch path pairs ToolUseBlock and ToolResultBlock positionally — agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:3465-3476. Completion-order delivery needs id-based pairing throughout, which is a wider change than adding a Flux variant.
    3. Structured output. Native structured output bypasses tool calls entirely (ReActAgent.java:1245-1277) and the fallback synthetic path bypasses ToolExecutor (ReActAgent.java:3511-3597). The proposal's "structured-output falls back to batch" needs a precise statement of which events a progressive consumer should expect in that mode.
    4. Concurrency safety. Concurrent sessions already share toolkit active groups and a mutable internal chunk callback — ReActAgent.java:695-699, :3115-3164. A per-subscription progressive emitter must not reuse that mutable state.

    Feasibility: feasible with a default-off ToolkitConfig flag plus additive Flux-returning methods — the existing Mono<List<...>> API and default behaviour can be preserved (ToolkitConfig.java:119-143, Toolkit.java:511-525). Non-breaking for users who do not opt in; opted-in consumers must tolerate completion-order arrival.

    Priority: medium — observable per-tool latency is a real gap for SSE/UI consumers, but there is no correctness or data-loss impact.

    @rudy2steiner you are assigned and have picked this up, so no bot-generated patch here — please take the four points above into the design (ordering + id-based pairing are the ones that can silently break consumers).


    Automated evaluation by github-manager-bot

  6. xzxiaoshan commented on Oct 23, 2026

    @xzxiaoshan
    Collaborator

    complated as #3712

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions