Skip to content

Comments

feat: add role-specific statistics to telemetry and UI#15234

Closed
jacob314 wants to merge 2 commits intomainfrom
stats_breakdown
Closed

feat: add role-specific statistics to telemetry and UI#15234
jacob314 wants to merge 2 commits intomainfrom
stats_breakdown

Conversation

@jacob314
Copy link
Contributor

@jacob314 jacob314 commented Dec 18, 2025

Summary

Add role-specific statistics to /stats and /stats model
Demos:
image
image

Colors and styling is quickly tossed together please suggest feedback for how to make this polished.

Some topics for discussion:
should we dash separate things like subagent-codebase-investigator or write it as "Subagent Codebase Investigator"?
What colors should we use for the roles?
Should we tweak the table rendering to leverage things like utilities typically using a fixed model like flash-lite so there is no need to have so many rows for their columns.
Other roles like main will tend to have multiple columns with auto model routing.
We could surface errors on a per role basis as we are tracking it for completeness but it doesn't matter that much.

Details

  • Granular LLM Call Categorization: Introduced a new LlmRole enum to classify LLM interactions (e.g., main agent, subagents, various utility functions like summarization, routing, autocomplete, etc.).
  • Enhanced Telemetry for LLM Usage: Extended the telemetry system to record and track detailed metrics (requests, errors, latency, token usage including input, output, and cache reads) for each LlmRole.
  • Improved UI for Model Statistics: Updated the CLI's ModelStatsDisplay and StatsDisplay components to visually present these role-specific LLM usage breakdowns, offering a more insightful view of model activity.
  • Widespread Integration of Role Tracking: The LlmRole parameter has been consistently integrated across numerous core components, utility functions, and client calls that interact with LLMs, ensuring comprehensive data collection.

UI changes are minimal and just intended as a starting point for UX discussions. Core work is the migration of all the code in packages/core to use the new tracking.

Related Issues

Fixes: #14538

How to Validate

Exercise various models and trigger subagents, autocomplete, and other ways Gemini CLI uses models. Make sure they are attributed correctly.

When reviewing the code in package/core make sure that we are never setting a default value for LlmRole. My instructions for the plan for Gemini CLI was to require all code to pass in a valid LlmRole value so that static analysis could catch any issues where it wasn't passed in but there was one case I had to catch manually where Gemini CLI added a default value to make it easier for tests to pass that introduced a bug where tokens that weren't from the main event loop were tagged as main event loop.

@jacob314 jacob314 requested a review from a team as a code owner December 18, 2025 02:10
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jacob314, 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 system's ability to monitor and understand LLM usage by introducing role-specific categorization for all LLM calls. This allows for a detailed breakdown of how different functional components, such as the main agent, subagents, and various internal utilities (e.g., summarizers, routers, edit correctors), consume LLM resources. The user interface has been polished to display these new granular statistics, providing users and developers with a clearer, more actionable view of model performance, token consumption, and potential cost drivers.

Highlights

  • Granular LLM Call Categorization: Introduced a new LlmRole enum to classify LLM interactions (e.g., main agent, subagents, various utility functions like summarization, routing, autocomplete, etc.).
  • Enhanced Telemetry for LLM Usage: Extended the telemetry system to record and track detailed metrics (requests, errors, latency, token usage including input, output, and cache reads) for each LlmRole.
  • Improved UI for Model Statistics: Updated the CLI's ModelStatsDisplay and StatsDisplay components to visually present these role-specific LLM usage breakdowns, offering a more insightful view of model activity.
  • Widespread Integration of Role Tracking: The LlmRole parameter has been consistently integrated across numerous core components, utility functions, and client calls that interact with LLMs, ensuring comprehensive data collection.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

@github-actions
Copy link

github-actions bot commented Dec 18, 2025

Size Change: +9.2 kB (+0.04%)

Total Size: 22 MB

Filename Size Change
./bundle/gemini.js 22 MB +9.2 kB (+0.04%)
ℹ️ View Unchanged
Filename Size
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB

compressed-size-action

Copy link
Contributor

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

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 introduces role-specific statistics for LLM calls, a valuable addition for telemetry and debugging. The changes are extensive, touching core client logic, telemetry types, and UI components to track and display these new metrics. The implementation is generally solid, with new tests to validate the UI changes.

I've identified one potential issue in the ModelStatsDisplay component that could lead to a UI crash if a model's metrics are missing the roles property. My review includes a specific comment with a suggested fix for this.

Overall, this is a well-executed feature that enhances the observability of the system.

@jacob314 jacob314 requested a review from a team as a code owner December 18, 2025 05:04
chore: updated call sites to use role parameter

UI Polish

UI: Update StatsDisplay role breakdown layout to be indented and below model row

feat: add specific LlmRole for codebase_investigator subagent

feat(cli): breakdown tokens by input/output/cache in model stats roles
Copy link
Collaborator

@abhipatel12 abhipatel12 left a comment

Choose a reason for hiding this comment

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

Thanks for making this change to track model usage by role!

Couple questions, but also not 100% sure for the primary /stats including this additional info. Could feel cluttered in a TUI

WDYT?

options: _CommonGenerateOptions,
shouldRetryOnContent: (response: GenerateContentResponse) => boolean,
errorContext: 'generateJson' | 'generateContent',
role: LlmRole = 'utility_tool' as LlmRole,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we have defaults? I could see avoiding defaults and forcing a role to callers to avoid missing attribution to a caller.

Comment on lines +189 to +191
if (!logRecord.attributes) logRecord.attributes = {};
logRecord.attributes['role'] = event.role;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this logic also set in the line above at:

const logRecord: LogRecord = event.toLogRecord(config);

The code looks like:

toLogRecord(config: Config): LogRecord {
    const attributes: LogAttributes = {
      ...getCommonAttributes(config),
      'event.name': EVENT_API_REQUEST,
      'event.timestamp': this['event.timestamp'],
      model: this.model,
      prompt_id: this.prompt.prompt_id,
      request_text: this.request_text,
    };
    if (this.role) {
      attributes['role'] = this.role;
    }
    return { body: `API request to ${this.model}.`, attributes };
  }

export enum LlmRole {
MAIN = 'main',
SUBAGENT = 'subagent',
SUBAGENT_CODEBASE_INVESTIGATOR = 'subagent_codebase_investigator',
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we use use subagent roles like this?

What will happen when users start adding subagents of their own? Will we group all custom subagents under a single category?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure about the UI of the primary /stats

For example, looking at the screenshot below, it feels crowded and slightly difficult to find the "main" stats that I'm interested in.

Utility calls could be kept within /stats model since that is way more detailed. I see an argument for "agents" b/c that will have a material impact on token usage while utility calls are typically lightweight.

Image

@gemini-cli gemini-cli bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality labels Jan 7, 2026
@jacob314 jacob314 added the 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. label Jan 22, 2026
const role =
this.definition.name === 'codebase_investigator'
? LlmRole.SUBAGENT_CODEBASE_INVESTIGATOR
: LlmRole.SUBAGENT;
Copy link
Contributor

Choose a reason for hiding this comment

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

we have another built-in subagent and users could have a lot more of other subagents they are going to build. Either we should categorized all of them into one role maybe something like (built-in-agent, local-agent, remote-agent), or use their actual names.

@sehoon38
Copy link
Contributor

wondering if we should provide a separate view for role metrics as the number of tools/agents could grow and may not fit in the screen.

@bdmorgan
Copy link
Collaborator

Automatically closing PR as it is older than 7 days and authored by a team member.

@bdmorgan bdmorgan closed this Jan 23, 2026
yunaseoul pushed a commit that referenced this pull request Feb 11, 2026
yunaseoul pushed a commit that referenced this pull request Feb 12, 2026
github-merge-queue bot pushed a commit that referenced this pull request Feb 17, 2026
@jacob314 jacob314 deleted the stats_breakdown branch February 19, 2026 07:14
thacio added a commit to thacio/auditaria that referenced this pull request Feb 19, 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. priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve model calls UX to separate out user prompts' model usage from system, tool, and/or sub-agent calls

4 participants