Skip to content

fix(core): normalize tool call result transcripts#2357

Open
Zbhbb wants to merge 7 commits into
agentscope-ai:mainfrom
Zbhbb:codex/tool-transcript-recovery
Open

fix(core): normalize tool call result transcripts#2357
Zbhbb wants to merge 7 commits into
agentscope-ai:mainfrom
Zbhbb:codex/tool-transcript-recovery

Conversation

@Zbhbb

@Zbhbb Zbhbb commented Jul 22, 2026

Copy link
Copy Markdown

AgentScope-Java Version

Current main branch.

Description

Fixes #2191.

Background

After an interruption, a tool-use block can remain in history while its tool result is missing or appears later in the transcript. Providers that require adjacent tool calls and results reject that payload.

Changes

  • Normalize outbound model transcripts without mutating stored agent state.
  • Move known tool results next to their owning assistant tool calls.
  • Insert a terminal error result only when no result exists, so the next model call can recover safely.
  • Apply the normalization to both normal ReAct reasoning and summary generation.

Validation

  • mvn -q -pl agentscope-core -am -Dtest=MessageUtilsToolTranscriptTest,HookStopAgentTest,ReActAgentNewLoopE2ETest test
  • mvn -q -T1 -pl agentscope-core -am verify

The full repository verify ran through its Java test phase, but the unrelated agentscope-builder step could not download npm 10.9.2 because the npm registry TLS handshake was terminated.

Checklist

  • Code has been formatted with mvn spotless:apply rules
  • Relevant tests are passing
  • Javadoc follows existing conventions
  • Documentation update is not needed
  • Code is ready for review

Copilot AI review requested due to automatic review settings July 22, 2026 10:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses provider rejections (e.g., OpenAI/Anthropic 400) caused by mismatched tool-call/tool-result ordering after interruptions by normalizing the outbound transcript (without mutating stored agent state) before sending messages to the model.

Changes:

  • Add MessageUtils.normalizeToolCallResults(...) to relocate tool results adjacent to their owning assistant tool calls and synthesize a terminal error tool result when missing.
  • Apply transcript normalization to both the main ReAct reasoning call path and the summarization call path in ReActAgent.
  • Add/extend tests to validate transcript normalization behavior and ensure agent state isn’t mutated by normalization.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
agentscope-core/src/main/java/io/agentscope/core/util/MessageUtils.java Introduces transcript normalization logic for tool results/tool calls.
agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java Applies normalization before model calls in reasoning + summary.
agentscope-core/src/test/java/io/agentscope/core/util/MessageUtilsToolTranscriptTest.java Adds unit tests covering tool transcript normalization scenarios.
agentscope-core/src/test/java/io/agentscope/core/agent/ReActAgentNewLoopE2ETest.java Adds an E2E assertion that normalization occurs before model invocation and does not mutate stored history.

Comment thread agentscope-core/src/main/java/io/agentscope/core/util/MessageUtils.java Outdated
@Zbhbb

Zbhbb commented Jul 22, 2026

Copy link
Copy Markdown
Author

Fixed in 5510e8c. Replaced the fully-qualified IntStream expression with a simple loop to keep the test readable.

@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

Labels

None yet

Projects

None yet

2 participants