From 97cc0a07dca2fb49d6327005090e37d33c225107 Mon Sep 17 00:00:00 2001 From: Dayuan Jiang <34411969+DayuanJiang@users.noreply.github.com> Date: Thu, 11 Dec 2025 17:36:18 +0900 Subject: [PATCH] fix: disable history XML replacement by default (#217) Some models (e.g. minimax) copy placeholder text instead of generating fresh XML, causing tool call validation failures and infinite loops. Added ENABLE_HISTORY_XML_REPLACE env var (default: false) to control this behavior. --- app/api/chat/route.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts index 153313b..58c3826 100644 --- a/app/api/chat/route.ts +++ b/app/api/chat/route.ts @@ -264,8 +264,13 @@ ${lastMessageText} // Fix tool call inputs for Bedrock API (requires JSON objects, not strings) const fixedMessages = fixToolCallInputs(modelMessages) - // Replace historical tool call XML with placeholders to reduce tokens and avoid confusion - const placeholderMessages = replaceHistoricalToolInputs(fixedMessages) + // Replace historical tool call XML with placeholders to reduce tokens + // Disabled by default - some models (e.g. minimax) copy placeholders instead of generating XML + const enableHistoryReplace = + process.env.ENABLE_HISTORY_XML_REPLACE === "true" + const placeholderMessages = enableHistoryReplace + ? replaceHistoricalToolInputs(fixedMessages) + : fixedMessages // Filter out messages with empty content arrays (Bedrock API rejects these) // This is a safety measure - ideally convertToModelMessages should handle all cases