Skip to content

fix(core): persist tool results before middleware stop#2380

Open
March-77 wants to merge 1 commit into
agentscope-ai:mainfrom
March-77:agent/issue-2362-persist-tool-results-on-stop
Open

fix(core): persist tool results before middleware stop#2380
March-77 wants to merge 1 commit into
agentscope-ai:mainfrom
March-77:agent/issue-2362-persist-tool-results-on-stop

Conversation

@March-77

Copy link
Copy Markdown

AgentScope-Java Version

2.0.1-SNAPSHOT

Description

Fixes #2362.

When an onActing middleware emitted RequestStopEvent after tool execution, ReActAgent returned from the acting phase before running completed results through notifyPostActingHook. The preceding tool_use therefore remained in AgentState without its matching tool_result, even though the tool had completed successfully.

This change classifies completed and suspended results before handling the stop request. For a middleware stop, completed results now pass through the normal post-acting persistence path, toolkit state is synchronized, and only then is the stop acknowledgement returned. Permission-asking behavior remains unchanged, and the stop still skips the next reasoning/model iteration.

A new end-to-end regression test executes a terminal-style tool, emits RequestStopEvent after execution, and verifies both that the tool result is present in AgentState and that only one model call occurs.

User impact

Middleware-based terminal tool flows can stop immediately without leaving orphaned tool calls or causing provider errors on the next turn.

Tests

  • mvn -pl agentscope-core -Dtest=ReActAgentNewLoopE2ETest test — 3 passed
  • mvn -pl agentscope-core test — 2219 passed, 9 skipped
  • Spotless check passed as part of the Maven builds

Compatibility and risk

No public API changes. Normal acting, suspended-tool, and permission-confirmation paths retain their existing behavior. The only ordering change is that completed results are persisted before an acting middleware stop is honored.

Checklist

  • Code has been formatted with mvn spotless:apply
  • All relevant tests are passing
  • Javadoc/comments follow project conventions
  • No documentation update is required
  • Code is ready for review

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...e/src/main/java/io/agentscope/core/ReActAgent.java 83.33% 1 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Looks good.


Automated review by "github-manager-bot"

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]:缺少「终止工具」的干净实现:onActing 停止会产生孤儿 tool_result,onModelCall/onReasoning 停止会丢失已落库记忆

2 participants