Skip to content

fix toolResult Prefix Check#2174

Open
BG0527 wants to merge 2 commits into
agentscope-ai:mainfrom
BG0527:fix-toolResult-Prefix-Check
Open

fix toolResult Prefix Check#2174
BG0527 wants to merge 2 commits into
agentscope-ai:mainfrom
BG0527:fix-toolResult-Prefix-Check

Conversation

@BG0527

@BG0527 BG0527 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

关联 issue

AgentScope-Java Version

v2.0.0

Description

Background

MCP 工具执行超时后,ToolExecutor 重试 2 次均失败,最终错误结果被标记为 state=SUCCESS 而非 state=ERROR,导致 Agent 推理循环无法感知工具失败,继续基于错误数据进行推理。

Root Cause

错误处理存在两条路径,使用了不同的错误前缀:

  • 路径 AReActAgent.buildErrorToolResult() 使用 "[ERROR] " 前缀 — 能被 determineToolResultState() 识别
  • 路径 BToolExecutor.executeWithInfrastructure() 通过 ToolResultBlock.error() 产生 "Error: " 前缀 —— 不能被 determineToolResultState() 识别

determineToolResultState() 仅检查 startsWith("[ERROR]"),当 state 字段为 null 时作为 fallback 文本检测。由于 ToolResultBlock.error() 返回的 state=null(默认为 RUNNING)且前缀为 "Error: ",导致该方法始终返回 SUCCESS

Changes

  • Set ToolResultBlock.error(...) to explicitly use ToolResultState.ERROR.
  • Set ReActAgent internally built error tool results to ToolResultState.ERROR.
  • Added regression coverage for:
    • ToolResultBlock.error(...) carrying structured ERROR.
    • ReAct event emission reporting ToolResultEndEvent.state = ERROR for tools returning ToolResultBlock.error(...).

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for revieww

@BG0527 BG0527 requested a review from a team July 13, 2026 10:16
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@jujn

jujn commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

不好意思哈,我觉得这样改更好。而且应该同时关联那两个 Issue。

@BG0527

BG0527 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

不好意思哈,我觉得这样改更好。而且应该同时关联那两个 Issue。

好的我了解了,非常感谢您的评论。^_^

@jujn jujn 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

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core/tool Tool, skill, RAG abstractions area/core/agent Agent runtime, pipeline, hooks, plan labels Jul 14, 2026

@AgentScopeJavaBot AgentScopeJavaBot 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.

🤖 AI Review

@AgentScopeJavaBot AgentScopeJavaBot 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.

🤖 AI Review

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

Labels

area/core/agent Agent runtime, pipeline, hooks, plan area/core/tool Tool, skill, RAG abstractions bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants