fix(core): normalize tool call result transcripts - #2357
Conversation
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. |
|
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! |
oss-maintainer
left a comment
There was a problem hiding this comment.
LGTM. Looks good.
Automated review by "github-manager-bot"
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR adds a model-agnostic normalization layer for tool call/result message sequences before they're sent to LLM providers. It addresses a real problem: various LLM APIs reject or misbehave when tool call/result transcripts have structural issues. The normalization is inserted at both model call sites in ReActAgent (reasoning and summarizing), and is backed by 98 comprehensive tests.
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR adds a model-agnostic normalization layer for tool call/result message sequences before they're sent to LLM providers. It addresses a real problem: various LLM APIs reject or misbehave when tool call/result transcripts have structural issues. The normalization is inserted at both model call sites in ReActAgent (reasoning and summarizing), and is backed by 98 comprehensive tests.
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR adds a model-agnostic normalization layer for tool call/result message sequences before they're sent to LLM providers. It addresses a real problem: various LLM APIs reject or misbehave when tool call/result transcripts have structural issues. The normalization is inserted at both model call sites in ReActAgent (reasoning and summarizing), and is backed by 98 comprehensive tests.
101a6a5 to
c9dccaa
Compare
b3d7da9 to
f0d92bc
Compare
f0d92bc to
46f19a6
Compare
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