Skip to content

feature(tool): pregressive tool call events - #3712

Merged
jujn merged 6 commits into
agentscope-ai:mainfrom
rudy2steiner:progressive_tool_result_event
Oct 22, 2026
Merged

jujn merged 6 commits into
agentscope-ai:mainfrom
rudy2steiner:progressive_tool_result_event

Conversation

@rudy2steiner

Copy link
Copy Markdown
Contributor

Background

Addresses #3223

Previously, ReActAgent emitted tool result events only after the entire batch completed. A fast tool's result stayed invisible while a slower tool was running, delaying updates in SSE clients and UIs. Event timestamps were generated after batch completion; they were not necessarily identical.

This change lets consumers receive each completed tool's result immediately while preserving the batch boundary for conversation updates and subsequent reasoning.

Why this approach

This implementation uses a callback to deliver results earlier while keeping the existing batch aggregation and consumption flow.

The proposed Flux APIs are feasible, but sharing their implementation with the old Mono<List<...>> API would require refactoring the existing execution flow. Restoring the final list order would not alone prove compatibility: concurrency limits, serial isolation, subscription timing, errors, retries, timeouts, and cancellation would also need regression testing. Keeping the old implementation separate would avoid that refactor but leave two execution paths to maintain.

The callback runs before the existing mergeSequential / collectList aggregation. This preserves the ordered batch result used by the agent and limits the scope of regression testing.

Progressive events are enabled by default, without a flag. Events may arrive in completion order; consumers should match them by toolCallId. PostActing, context updates, and the next model call still wait for the whole batch.

Changes

  • Add ToolExecutionCallback with optional onStart, onProgress, and onResult notifications, plus Toolkit.callToolsWithCallback(...). Preserve existing chunk callback signatures through an adapter.
  • Notify final results from ToolExecutor before ordered aggregation, after existing retry, timeout, and tool error handling.
  • Route local tool progress and final result events through an invocation-scoped callback in ReActAgent. Preserve existing batch Start timing and skip result Delta/End events for suspended results.
  • Include synthetic generate_response results in callback publication without duplicating ordinary tool events. Native structured output continues to bypass tool dispatch; provider results and permission denials retain their existing event conversion.
  • Add coverage for early completion, ordered batch settlement, serial Start timing, mixed structured output, observation failures, callback failures, retries, cancellation, and callback isolation across concurrent executions.
  • Update the English and Chinese tool/event documentation.

@mintlify

mintlify Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 73c9041.

Approve preview

…error fallback

The batch-level onErrorResume in executeToolCalls re-processes every tool
call after an infrastructure failure (e.g. SessionLogException): calls that
already resolved through the executor's doOnNext received a second round of
delta/end events, and their real result was replaced by a synthetic error
in the returned list, so the event stream and the model-visible message
disagreed (events said SUCCESS, message said error).

Track resolved results per call id inside ReActAgent's per-batch
ToolResultCallback (created fresh per batch, so the shared Toolkit stays
stateless): onResult records the first resolution and skips later ones,
and the fallback backfills real results for resolved calls instead of
synthesizing errors. Recording before the suspended check also keeps tools
that suspended earlier alive as suspended instead of demoting them to
errors, so the HITL flow survives the batch error. The structured-output
missing-result fallback now fires onResult as well so no End event arrives
orphaned.
xzxiaoshan and others added 2 commits October 22, 2026 22:16
onStart was declared on the new ToolExecutionCallback interface but never
invoked by the executor — the only caller was ReActAgent looping over
approved calls at batch admission. ToolResultStartEvent therefore meant
"batch admitted" rather than "this tool is running": in sequential
batches a late tool's Start event preceded its actual execution by the
full duration of the preceding tools, so End(t2) - Start(t0) still mixed
in queue wait and per-tool latency remained unmeasurable (agentscope-ai#3223's
original motivation, only half-fixed by progressive results).

Fire onStart from a doOnSubscribe on the outermost per-tool mono in
ToolExecutor.executeAll (outside the retry wrapper, so one logical
invocation emits it exactly once), remove the admission loop in
ReActAgent, and add the same hook to the structured-output path, which
bypasses executeAll. onStart is idempotent in the callback, and the batch
error fallback fires it defensively for queued calls that never reached
the executor, so no End event arrives orphaned.

Parallel mode (the default) is unaffected in practice: mergeSequential
subscribes to every tool eagerly, so the executor-fired Start lands at
essentially the same moment as before. Queue previews should read
ToolCallStartEvent, which fires even earlier while the model streams the
tool_use blocks. Docs restored to the honest "tool starts executing"
semantics in both languages. Release notes are left to the release
process.
@jujn
jujn merged commit db0b67e into agentscope-ai:main Oct 22, 2026
5 of 6 checks passed
kyy-logs added a commit to kyy-logs/agentscope-java that referenced this pull request Oct 26, 2026
The merge of main into this branch dropped `import java.util.function.BiConsumer;`
from ReActAgent. agentscope-ai#3712 removed the last upstream usages of the type and the import
with them, while the permission helpers added here still use it, so both builds
failed to compile at ReActAgent.java:842 and 855.
chickenlj added a commit that referenced this pull request Nov 30, 2026
) (#4430)

Fixes #4429
Backports #3712 (`db0b67eb8`, addressing #3223) from `main` to `2.0.x`
as a fix release, with `2.0.x` compatibility adaptations and an
`AsyncToolMiddleware` regression fix.

Co-authored-by: Chickenlj <[email protected]>
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.

3 participants