Skip to content

Gemini grounding sources appear as separate message after assistant's response #6372

@daniel-lxs

Description

@daniel-lxs

When using the Gemini API with grounding enabled (enableGrounding: true), the grounding sources (citations) are displayed as a separate message after the assistant's response, rather than being integrated into the assistant's message itself. This creates a poor user experience where the conversation flow appears fragmented.

Current Behavior

When Gemini returns a response with grounding metadata:

  1. The assistant's response appears as one message
  2. The grounding sources appear as a separate message immediately after
  3. This creates a visual separation that makes it seem like the sources are unrelated to the response

Example of current display:

[Assistant message with response content]
[User's next message or interaction]
[Sources: [1](url1), [2](url2)]  <- Appears as separate message

Expected Behavior

The grounding sources should be integrated into the assistant's message, appearing as part of the same message block:

[Assistant message with response content]

Sources: [1](url1), [2](url2)

Technical Context

  • The issue occurs in src/api/providers/gemini.ts
  • Grounding metadata is extracted correctly via extractCitationsOnly() method
  • The sources are currently yielded as a separate text chunk in the stream
  • This separate chunk is interpreted by the UI as a new message

Proposed Solution

The sources should be appended to the assistant's message content before the final text chunk is yielded, ensuring they appear as part of the same message in the UI. This requires modifying the streaming logic to buffer and combine the content appropriately.

Impact

This affects all users who have enabled grounding/Google Search integration with Gemini models, causing a fragmented conversation experience when sources are displayed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue - Needs ScopingValid, but needs effort estimate or design input before work can start.UI/UXUI/UX related or focusedbugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions