fix: normalize message roles for local model backends (llama.cpp, Ollama)
Local backends using strict chat templates (e.g. Mistral 3) rejected Flynn's Anthropic-style tool_use/tool_result content blocks, causing 'roles must alternate' errors. Added getMessageTextWithTools() and normalizeMessagesForLocal() to serialize structured blocks to plain text, drop empty messages, and merge consecutive same-role messages. Also fixed compaction to ensure kept messages start with user role.
This commit is contained in:
@@ -53,6 +53,12 @@ export async function compactHistory(opts: {
|
||||
const toCompact = messages.slice(0, -keepCount);
|
||||
const toKeep = messages.slice(-keepCount);
|
||||
|
||||
// Ensure toKeep starts with a user message to avoid assistant→assistant
|
||||
// after the compaction summary (which has role 'assistant').
|
||||
while (toKeep.length > 0 && toKeep[0].role === 'assistant') {
|
||||
toCompact.push(toKeep.shift()!);
|
||||
}
|
||||
|
||||
const formattedConversation = toCompact.map((msg) => `${msg.role}: ${getMessageText(msg)}`).join('\n\n');
|
||||
|
||||
const tier = orchestrator.getDelegationTier('compaction');
|
||||
|
||||
Reference in New Issue
Block a user