diff --git a/core/util/messageConversion.ts b/core/util/messageConversion.ts index b94d7e63f27..dff75869933 100644 --- a/core/util/messageConversion.ts +++ b/core/util/messageConversion.ts @@ -327,7 +327,7 @@ export function convertFromUnifiedHistory( messages.push(baseMessage); - // Add tool result messages if there are completed tool calls + // Add tool result messages if there are completed tool calls, and fallback when tool output is missing if (item.toolCallStates) { for (const toolState of item.toolCallStates) { if (toolState.output && toolState.output.length > 0) { @@ -336,6 +336,12 @@ export function convertFromUnifiedHistory( content: toolState.output.map((o: any) => o.content).join("\n"), tool_call_id: toolState.toolCallId, }); + } else { + messages.push({ + role: "tool", + content: "Tool cancelled", + tool_call_id: toolState.toolCallId, + }); } } }