From 425a28cf79210d15aa0af9617bbb65330594cef3 Mon Sep 17 00:00:00 2001 From: BillionClaw Date: Tue, 17 Mar 2026 02:33:32 +0800 Subject: [PATCH] fix: prevent raw AIMessage JSON from being displayed in chat when using Gemini with Retriever Tool --- packages/components/nodes/agentflow/Agent/Agent.ts | 7 +++++-- packages/server/src/utils/buildChatflow.ts | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/components/nodes/agentflow/Agent/Agent.ts b/packages/components/nodes/agentflow/Agent/Agent.ts index 63730c2d15b..ea48998c01f 100644 --- a/packages/components/nodes/agentflow/Agent/Agent.ts +++ b/packages/components/nodes/agentflow/Agent/Agent.ts @@ -1336,11 +1336,14 @@ class Agent_Agentflow implements INode { finalResponse = processedParts.filter((text) => text).join('\n') } else if (response.content && typeof response.content === 'string') { finalResponse = response.content - } else if (response.content === '') { + } else if (response.content === '' || response.content == null) { // Empty response content, this could happen when there is only image data + // or when content is null/undefined (e.g., when there are only tool_calls) finalResponse = '' } else { - finalResponse = JSON.stringify(response, null, 2) + // Fallback: extract text content using the utility function + // instead of serializing the entire response object + finalResponse = extractResponseContent(response) } // Address built in tools diff --git a/packages/server/src/utils/buildChatflow.ts b/packages/server/src/utils/buildChatflow.ts index c54c009c43a..c9f8a14f1c9 100644 --- a/packages/server/src/utils/buildChatflow.ts +++ b/packages/server/src/utils/buildChatflow.ts @@ -854,7 +854,8 @@ export const executeFlow = async ({ logger.log('[server]: Post Processing Error:', e) } } - } else if (result.json) resultText = '```json\n' + JSON.stringify(result.json, null, 2) + } else if (result.json) resultText = '```json\n' + JSON.stringify(result.json, null, 2) + '\n```' + else if (result.content) resultText = result.content else resultText = JSON.stringify(result, null, 2) const apiMessage: Omit = {