Skip to content

Conversation

@MuriloFP
Copy link
Contributor

@MuriloFP MuriloFP commented Jan 28, 2025

Description

Added a Context token counter to the task header. It is a minimal addition that uses the same counting logic as the input and output tokens counter. It takes the total input tokens from the last message, and adds in the output tokens. This is updated every time a new message is received from the API, and covers against edge cases such as failed requests.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Tested it manually in debugging mode, added logic to prevent mistakes in edge cases.

Checklist:

  • My code follows the patterns of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation

Additional context

image

Related Issues

Reviewers


Important

Add context token counter to task header, updating with each API message in getApiMetrics.ts and displaying in TaskHeader.tsx.

  • Behavior:
    • Adds contextTokens to ApiMetrics in getApiMetrics.ts, calculated as the sum of tokensIn and tokensOut from the last api_req_started message.
    • Updates contextTokens in TaskHeader.tsx to display the total context tokens in the task header.
  • UI Components:
    • Passes contextTokens to TaskHeader in ChatView.tsx.
    • Displays contextTokens in TaskHeader.tsx under the "Context" label.

This description was created by Ellipsis for 97fe13d. It will automatically update as commits are pushed.

- Add contextTokens to ApiMetrics interface
- Calculate context size using last API request's tokens
- Display context token count in TaskHeader below total tokens
- Use exact token counts instead of character estimation

This helps users track the total size of their conversation context,
which is useful for managing context window limits.
- Only update context tokens when both input and output tokens are non-zero
- Keep previous context token count when API calls fail
- Avoid resetting counter on partial or failed responses

This makes the context token counter more resilient against edge cases
and provides more accurate context size tracking during API failures.
@changeset-bot
Copy link

changeset-bot bot commented Jan 28, 2025

⚠️ No Changeset found

Latest commit: 1ba632f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

- Only consider API requests with valid token information
- Skip messages with invalid/missing token data
- Prevent counter from resetting on action approval messages
- Ensure both tokensIn and tokensOut are valid numbers

This makes the context token counter more stable and accurate
by only updating on valid API responses with complete token data.
Copy link
Collaborator

@mrubens mrubens left a comment

Choose a reason for hiding this comment

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

Awesome, thank you!

@mrubens mrubens merged commit 3862057 into RooCodeInc:main Jan 28, 2025
4 checks passed
@MuriloFP MuriloFP deleted the feature/context-token-counter branch January 28, 2025 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants