Skip to content

fix(ReActAgent): preserve user chunk callback when using copied toolkit#894

Merged
LearningGp merged 7 commits intoagentscope-ai:mainfrom
JGoP-L:codex/fix-issue-870-chunk-callback
Mar 20, 2026
Merged

fix(ReActAgent): preserve user chunk callback when using copied toolkit#894
LearningGp merged 7 commits intoagentscope-ai:mainfrom
JGoP-L:codex/fix-issue-870-chunk-callback

Conversation

@JGoP-L
Copy link
Contributor

@JGoP-L JGoP-L commented Mar 9, 2026

AgentScope-Java Version

1.0.10-SNAPSHOT

Description

Fixes #870.

Previously, when a user configured a chunk callback via Toolkit#setChunkCallback(...) and then passed that toolkit into ReActAgent.builder().toolkit(toolkit).build(), the callback could be overwritten by the internal callback registered by ReActAgent during tool execution.

This PR separates user-defined chunk callbacks from framework-internal chunk callbacks so both can work together:

  • preserve user callbacks across Toolkit.copy()
  • keep ActingChunkEvent emission in ReActAgent
  • add a regression test in ToolEmitterIntegrationTest

How to test

mvn -pl agentscope-core -Dtest=ToolEmitterIntegrationTest test

@JGoP-L JGoP-L requested review from a team and Copilot March 9, 2026 04:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a regression where user-configured Toolkit#setChunkCallback(...) was effectively overwritten by ReActAgent during tool execution, ensuring both user chunk callbacks and ActingChunkEvent hook emission work simultaneously (issue #870).

Changes:

  • Split tool chunk callback handling into user vs framework-internal callbacks in ToolExecutor.
  • Added Toolkit#setInternalChunkCallback(...) so ReActAgent can emit ActingChunkEvent without overwriting user callbacks.
  • Preserved user chunk callbacks across Toolkit.copy() and added a regression test covering the real ReActAgent copied-toolkit scenario.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
agentscope-core/src/main/java/io/agentscope/core/tool/ToolExecutor.java Separates user/internal chunk callbacks and composes an effective callback for ToolEmitter.
agentscope-core/src/main/java/io/agentscope/core/tool/Toolkit.java Adds internal chunk-callback API and preserves user chunk callback during copy().
agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java Registers an internal chunk callback (instead of overwriting the user callback) to emit ActingChunkEvent.
agentscope-core/src/test/java/io/agentscope/core/tool/ToolEmitterIntegrationTest.java Adds integration regression test verifying both user callback and ActingChunkEvent receive tool-emitted chunks under ReActAgent.

@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ain/java/io/agentscope/core/tool/ToolExecutor.java 95.83% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Collaborator

@LearningGp LearningGp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@LearningGp LearningGp merged commit 9542f42 into agentscope-ai:main Mar 20, 2026
6 checks passed
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.

[Bug]:Toolkit#setChunkCallback not triggered due to missing callback invocation in AgentScope 1.0.9

3 participants