Skip to content

fix(core): separate sub-agent thought headers with comma and space#21689

Open
imadraude wants to merge 1 commit into
google-gemini:mainfrom
imadraude:fix/tui-subagent-status-concatenation
Open

fix(core): separate sub-agent thought headers with comma and space#21689
imadraude wants to merge 1 commit into
google-gemini:mainfrom
imadraude:fix/tui-subagent-status-concatenation

Conversation

@imadraude

Copy link
Copy Markdown
Contributor

Summary

Fixes the issue where sub-agent thought headers in the TUI were concatenated into a single string without spaces (e.g., Analyzing...Searching...). They are now separated by a comma and a space (Analyzing..., Searching...).

Details

  • Modified packages/core/src/agents/local-invocation.ts to handle THOUGHT_CHUNK events more intelligently.
  • Implemented a "growth" check: if a new thought header starts with the current content, it's treated as a continuation (incremental streaming) and replaces the old content.
  • If it's a new distinct thought, it's appended using , as a separator.
  • Added a check to skip exact duplicates.
  • Updated existing tests and added a new test case for incremental growth.

Related Issues

Fixes #21688

How to Validate

  1. Run any sub-agent (e.g., Generalist) that performs multiple steps.
  2. Observe the status line next to the 💭 icon.
  3. Multiple thought headers should now be clearly separated by commas.

Alternatively, run the updated tests:

npm test -w @google/gemini-cli-core -- src/agents/local-invocation.test.ts

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
    • Windows
    • Linux
      • npm run

@imadraude imadraude requested a review from a team as a code owner March 9, 2026 11:31
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 significantly enhances the user experience within the Terminal User Interface (TUI) by refining how sub-agent thought processes are displayed. It addresses a formatting issue that previously made sequential thoughts difficult to read, ensuring that all agent activities are presented clearly and logically. The changes improve the clarity of real-time agent feedback, making it easier for users to follow the agent's progress and decision-making.

Highlights

  • Improved TUI Readability: Fixed an issue where sub-agent thought headers in the TUI were concatenated without spaces, now separating them with a comma and a space for better readability.
  • Intelligent Thought Header Handling: Modified the local-invocation.ts file to intelligently process THOUGHT_CHUNK events, distinguishing between incremental streaming and new distinct thoughts.
  • Incremental Streaming Support: Implemented a 'growth' check where if a new thought header starts with the current content, it's treated as a continuation and replaces the old content, providing a smoother update experience.
  • Distinct Thought Separation: Ensured that new, distinct thought headers are appended using , as a separator, preventing unreadable concatenation.
  • Duplicate Prevention: Added a check to skip exact duplicate thought headers, avoiding redundant display.
  • Enhanced Test Coverage: Updated existing tests and introduced a new test case specifically for validating the incremental growth and correct separation of thought headers.
Changelog
  • packages/core/src/agents/local-invocation.test.ts
    • Updated an existing test assertion to reflect the new thought header formatting.
    • Added a new test case to verify correct handling of growing thought headers and their separation.
  • packages/core/src/agents/local-invocation.ts
    • Implemented logic to update thought content incrementally if a new chunk starts with the existing content.
    • Added a condition to append new distinct thought chunks with a ', ' separator.
    • Ensured exact duplicate thought chunks are skipped to prevent redundant display.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly identifies the need to separate sub-agent thought headers. The implementation adds the desired comma separator. However, the logic for handling incremental updates and preventing duplicates has some flaws that could lead to an incorrect display of thoughts in the UI. I've provided a suggestion to make this logic more robust, which also aligns with our guideline for using comma-separated strings for LLM-consumed data.

Comment on lines +123 to +130
if (
text.startsWith(lastItem.content) &&
lastItem.content.length > 0
) {
lastItem.content = text;
} else if (!lastItem.content.includes(text)) {
lastItem.content += (lastItem.content ? ', ' : '') + text;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current logic for updating thought content has a couple of issues that can lead to incorrect display:

  1. Incremental Update Flaw: The text.startsWith(lastItem.content) check only works for the very first thought in a sequence. If lastItem.content is "Analyzing, Searching" and the next chunk is an update to the second thought like "Searching the web", this condition will fail, and it will be incorrectly appended as a new thought.
  2. Duplicate Check Flaw: The !lastItem.content.includes(text) check is not robust. It will incorrectly drop a new thought if it happens to be a substring of the existing content (e.g., a new thought "web" would be dropped if "Searching the web" is already present).

A more robust approach is to treat the content as a list of thoughts, operating on the last thought for incremental updates and checking for full-string existence for new thoughts.

Additionally, it would be beneficial to trim() the incoming text at the start of the THOUGHT_CHUNK case to prevent formatting issues like double spaces from chunks with leading/trailing whitespace.

              const thoughts = lastItem.content.split(', ');
              const lastThought = thoughts[thoughts.length - 1];

              // Handle incremental streaming for the last thought
              if (text.startsWith(lastThought) && lastThought.length > 0) {
                thoughts[thoughts.length - 1] = text;
                lastItem.content = thoughts.join(', ');
              } else if (!thoughts.includes(text)) {
                // Append a new, distinct thought
                lastItem.content += (lastItem.content ? ', ' : '') + text;
              }
References
  1. For multi-select answers that will be consumed by an LLM, return a single comma-separated string instead of an array of strings to maintain a simpler API design. The suggested approach of joining thoughts with ', ' aligns with this principle for structured data.

@gemini-cli gemini-cli Bot added area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Mar 9, 2026
@sripasg sripasg added the size/s A small PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI: Sub-agent thought messages are always concatenated without spaces

2 participants