Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,38 +83,16 @@ public OpenAIMessage mergeToUserMessage(
StringBuilder textBuffer = new StringBuilder();
textBuffer.append(conversationHistoryPrompt);
textBuffer.append(HISTORY_START_TAG).append("\n");

// Process all messages EXCEPT the last one as history
int lastIndex = msgs.size() - 1;

// Append history messages
if (lastIndex > 0) {
for (int i = 0; i < lastIndex; i++) {
processMessage(
msgs.get(i),
roleFormatter,
toolResultConverter,
textBuffer,
allParts,
true);
}
}
textBuffer.append(HISTORY_END_TAG).append("\n");

// Process the last message (current turn)
if (lastIndex >= 0) {
// Include prefix only if there is history (multi-turn context)
// or if it's explicitly needed. For single-turn user queries,
// omitting the prefix makes it look like a standard chat request.
boolean includePrefix = lastIndex > 0;
// Include prefix only if there is history (multi-turn context)
// For single-turn user queries,
// omitting the prefix makes it look like a standard chat request.
boolean includePrefix = msgs.size() > 1;
// Process all messages as history (similar to DashScopeConversationMerger)
for (Msg msg : msgs) {
processMessage(
msgs.get(lastIndex),
roleFormatter,
toolResultConverter,
textBuffer,
allParts,
includePrefix);
msg, roleFormatter, toolResultConverter, textBuffer, allParts, includePrefix);
}
textBuffer.append(HISTORY_END_TAG).append("\n");

// Flush remaining text
if (textBuffer.length() > 0) {
Expand Down
Loading