Skip to content

fix(core):prevent openAIConversationMerger merge history message with MessageRole#737

Open
feelshana wants to merge 6 commits intoagentscope-ai:mainfrom
feelshana:dev-1.0.1
Open

fix(core):prevent openAIConversationMerger merge history message with MessageRole#737
feelshana wants to merge 6 commits intoagentscope-ai:mainfrom
feelshana:dev-1.0.1

Conversation

@feelshana
Copy link
Contributor

fix(#731)
prevent openAIConversationMerger merge history message with MessageRole

main

Description

This prevents confusion: ASSISTANT should only mean "my LLM replied to me" .
Messages from other agents should be treated as USER messages

Checklist

Please check the following items before code is ready to be reviewed.

  • 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 review

@feelshana feelshana requested a review from a team February 5, 2026 10:27
@gemini-code-assist
Copy link

Summary of Changes

Hello @feelshana, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the OpenAIConversationMerger to prevent the incorrect merging of historical messages with MessageRole information. The change ensures that only direct LLM responses are designated as ASSISTANT messages, while messages from other agents are consistently treated as USER messages, improving the accuracy and clarity of conversation history when interacting with the OpenAI API.

Highlights

  • Refined Message Role Handling: The OpenAIConversationMerger now explicitly prevents merging history messages with MessageRole information, ensuring that only direct LLM responses are classified as ASSISTANT messages.
  • Consistent Agent Message Treatment: Messages originating from other agents are now consistently treated as USER messages, improving clarity and preventing confusion in conversation history.
  • Simplified Message Prefixing: The logic for prefixing messages has been simplified by removing the roleLabel variable and its usage, now relying solely on the agentName for identification.
  • Updated Tool Result Formatting: Tool results are now formatted to directly use the agentName instead of a combined role and name, streamlining the output.
Changelog
  • agentscope-core/src/main/java/io/agentscope/core/formatter/openai/OpenAIConversationMerger.java
    • Removed the roleLabel variable and its associated logic, which previously determined the role prefix for merged messages.
    • Replaced calls to appendRoleAndName with appendNamePrefix to ensure messages are prefixed only by the agent's name.
    • Updated the formatting for tool results to directly use the agentName instead of a combined role and name.
    • Adjusted Javadoc comments for better readability.
Activity
  • No human activity (comments, reviews, etc.) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request successfully removes the usage of MessageRole when merging conversation history, using only the agent name as a prefix. This aligns with the goal of treating all non-LLM messages as user messages. The implementation is mostly correct, but I've found a couple of areas for improvement. First, a parameter has become unused due to the changes and should be removed for code cleanliness. Second, there's a minor bug in handling ToolResultBlock where a null agent name would result in the string "null" being printed. I've provided suggestions for both issues.

I am having trouble creating individual review comments. Click here to see my feedback.

agentscope-core/src/main/java/io/agentscope/core/formatter/openai/OpenAIConversationMerger.java (295)

high

If agentName is null, textBuffer.append(agentName) will append the literal string "null", leading to an output like null (tool_name): .... This is likely not the intended behavior. You should handle the case where agentName is null.

textBuffer.append(agentName != null ? agentName : "");

agentscope-core/src/main/java/io/agentscope/core/formatter/openai/OpenAIConversationMerger.java (135-138)

medium

With the removal of roleLabel, the roleFormatter parameter in processMessage is no longer used. To improve code clarity and maintainability, it should be removed from the method signature. This change should be propagated up to mergeToUserMessage and its callers, including updating the tests.

@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

❌ Patch coverage is 13.33333% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ore/formatter/openai/OpenAIConversationMerger.java 13.33% 12 Missing and 1 partial ⚠️

📢 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

Development

Successfully merging this pull request may close these issues.

1 participant