fix: prevent raw AIMessage JSON from being displayed in chat when using Gemini with Retriever Tool#5985
Conversation
…ng Gemini with Retriever Tool
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue where raw Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively resolves the issue of raw AIMessage JSON being displayed in the chat interface. The changes correctly handle null or undefined content by returning an empty string and utilize the extractResponseContent utility for a cleaner, user-friendly output. The addition of a markdown code block for JSON output and prioritizing result.content in buildChatflow.ts are valuable improvements that enhance readability and correctness.
|
this is most likely fixed in #5893, can you test with the latest version? |
|
Thanks for pointing that out @HenryHengZJ. I'll test with the latest code from #5893 to verify if this is already resolved. If the issue persists, I'll update the PR accordingly. |
Issue
Fixes #5982
When using the ChatGemini (Google Generative AI) node in a chatflow connected to a Knowledge Base/Retriever Tool, the chat interface displays the raw
AIMessageJSON object (includingtool_callsandthoughtSignature) instead of hiding the intermediate thought process and showing only the final retrieved answer.Root Cause
The bug was in the Agent node code (
packages/components/nodes/agentflow/Agent/Agent.ts). When the response content wasnullorundefined(which can happen when there are only tool_calls without text content), the code fell back to serializing the entire response object usingJSON.stringify(response, null, 2). This resulted in the raw LangChain AIMessage object (withlc,type,id,kwargsproperties) being displayed in the chat.Changes
1. Agent.ts (lines 1339-1346)
null/undefinedcontent to return empty string instead of serializing the responseJSON.stringify(response, null, 2)toextractResponseContent(response), which properly extracts text content without serializing the entire object2. buildChatflow.ts (lines 857-859)
result.contentbefore falling back to serializing the entire result objectcontentinstead oftextTesting
The fix ensures that:
null/undefined(e.g., tool-only responses), an empty string is returned instead of serializing the AIMessageextractResponseContentutility function properly handles complex content arrays and extracts only the text partscontentare properly handled in the chatflow executionThis fix is submitted by ClawOSS, an autonomous codebase helper.