Skip to content

Conversation

@riturajFi
Copy link
Contributor

@riturajFi riturajFi commented Oct 19, 2025

@riturajFi riturajFi marked this pull request as ready for review October 28, 2025 09:33
@riturajFi riturajFi requested a review from a team as a code owner October 28, 2025 09:33
@riturajFi
Copy link
Contributor Author

@krissetto kindly review this solution

@riturajFi
Copy link
Contributor Author

Hi @krissetto , i found out that there were some double counting issues - i am fxing them now

@krissetto
Copy link
Contributor

Hey @riturajFi! 👋 is this ready for testing? If not we should put the PR back into draft for the meantime

@riturajFi
Copy link
Contributor Author

Hi @krissetto , the PR is ready for testing - i am just adding some comments, removing some unnecessary stuff and cleaning it up

@riturajFi riturajFi force-pushed the fix/tui_token_count_fix branch from 701b6c2 to b2df510 Compare October 31, 2025 16:08
@riturajFi
Copy link
Contributor Author

Hi @krissetto , would love to see your reviews on this. Kindly suggest any changes and i shall do them asap. Would love seeing it merged.

@krissetto
Copy link
Contributor

Hey @riturajFi! I'm not at my machine right now, but I'll give it a look and try it out as soon as I can over the weekend

@riturajFi
Copy link
Contributor Author

Thanks a lot @krissetto . Please assign me one more issue in tve meanwhile. I shall work on it! It's very insignful to work on first principle projects like these.

@krissetto
Copy link
Contributor

sure! wanna take a look at #665? shouldn't require many changes

Copy link
Contributor

@krissetto krissetto left a comment

Choose a reason for hiding this comment

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

Hey @riturajFi, thanks for the contribution!

I pulled this code and ran a few tests. It looks like the counting is mostly working, but sometimes during task transfers and at the end of a request the count is not representative of the total so something unexpected is happening. I left a suggestion in the code because I think we can simplify this and make it more robust.

Also, looking at the UI aspects of this, i think it might be better to start a bit smaller in scope and only display the total count of tokens used by all sessions, in tokens and cost (ignoring context percentage for now). This way we can get your changes merged more quickly and iterate from there.

There are a few edge cases regarding what context percentage to show, how to organize the sidebar when there are more than just 1-2 sub-agent sessions, sub-agent sessions costs seem truncated, and I don't think we need the "transferred task" text either as it clutters the sidebar.

(ignore the costs all being 0 in the screenshot, I was using local models for this test)

Image

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can simplify things and don't really need this. Each session already contains its own usage data, so we could use less code to implement this total count by traversing the session tree (going from the root agent's session down to its sub-agent sessions) instead of having a separate tracking mechanism

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, even simpler and less code to implement would probably be to append the values from the emitUsageEvent events in the TUI code, and not traverse sessions at all. What do you think?

}

// formatCost renders small currency values with enough precision for tiny spends.
func formatCost(cost float64) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I don't think we need to display sub 1cent spending, shorter numbers can help with formatting in the limited sidebar space too

@riturajFi
Copy link
Contributor Author

Thanks @krissetto . I am on it

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