Skip to content

[Backport 2.0.x]: Progressive tool call events (#3712) and AsyncToolMiddleware offload fix #4429

Done

Description

@Acerola-1
    **Describe the bug**
    On `2.0.x`, tool result events (`ToolResultTextDeltaEvent` / `ToolResultDataDeltaEvent` /
    `ToolResultEndEvent`) are emitted only after the entire tool batch finishes, blocking fast tools
    behind slower tools in the same batch (originally tracked in #3223 and fixed on `main` in #3712).

    Additionally, when backporting progressive tool call events to `2.0.x`:
    1. `ToolExecutor.execute(...)` evaluates `executeCore(...)` eagerly under the default `NoopTracer`,
    causing non-deferred `AgentTool` invocations to run at assembly time and preventing retry
    re-invocation.
    2. With progressive result events, if a fast tool completes before `AsyncToolMiddleware`'s
    `offloadTimeout` while a slow tool triggers offload, `AsyncToolMiddleware` overwrites the fast
    tool's result with a background placeholder in context, emits duplicate placeholder events, and
    tracks the already-finished fast tool in `AsyncToolRegistry`.

    **To Reproduce**
    1. Run a parallel tool batch containing a fast tool and a slow tool via
    `ReActAgent.streamEvents(...)` on `2.0.x`.
    2. Observe that the fast tool's result events wait until the slow tool finishes; and with
    `AsyncToolMiddleware`, when the slow tool exceeds `offloadTimeout`, the fast tool is mistakenly
    offloaded too.

    **Expected behavior**
    - Emit `ToolResultStartEvent` when each tool actually starts executing (when its turn arrives in
    sequential batches) and emit each completed tool's result events immediately before ordered batch
    settlement (`PostActing`, context updates, and next reasoning still wait for the full batch).
    - Keep `2.0.x` event compatibility (`ToolResultTextDeltaEvent`/`ToolResultDataDeltaEvent` for
    streaming chunks and `ToolResultEndEvent(RUNNING)` for suspended external tools).
    - Preserve pre-timeout completed tool results in `AsyncToolMiddleware` without duplicating
    placeholder events or registering them in `AsyncToolRegistry`.

    **Environment (please complete the following information):**
    - AgentScope-Java Version: 2.0.6-SNAPSHOT (branch `2.0.x`)
    - Java Version: 17
    - OS: macOS

    **Additional context**
    Backport of PR #3712 (`db0b67eb8`) from `main` to `2.0.x`. I'd like to submit a PR targeting
    `2.0.x` for this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions