fix(core): normalize tool call result transcripts#2357
Open
Zbhbb wants to merge 7 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
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. |
Author
|
Fixed in 5510e8c. Replaced the fully-qualified IntStream expression with a simple loop to keep the test readable. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Validation
mvn -q -pl agentscope-core -am -Dtest=MessageUtilsToolTranscriptTest,HookStopAgentTest,ReActAgentNewLoopE2ETest testmvn -q -T1 -pl agentscope-core -am verifyThe full repository
verifyran through its Java test phase, but the unrelatedagentscope-builderstep could not download npm 10.9.2 because the npm registry TLS handshake was terminated.Checklist
mvn spotless:applyrules