# agent: Fix conversation token usage and estimate unsent message \(\#28878\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/0286b8ab3eeae8bb8ca89e770a39ff524488b298)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 0286b8ab3eeae8bb8ca89e770a39ff524488b298

Requested commit: 0286b8ab3eeae8bb8ca89e770a39ff524488b298

Commit: 0286b8ab3eeae8bb8ca89e770a39ff524488b298

Tree: 91e940afb054a269e29a51763c6787e5425c1ea2

Author: Agus Zubiaga

Committer: GitHub

## Message

```
agent: Fix conversation token usage and estimate unsent message (#28878)

The UI was mistakenly using the cumulative token usage for the token
counter. It will now display the last request token count, plus an
estimation of the tokens in the message editor and context entries that
haven't been sent yet.


https://github.com/user-attachments/assets/0438c501-b850-4397-9135-57214ca3c07a

Additionally, when the user edits a message, we'll display the actual
token count up to it and estimate the tokens in the new message.

Note: We don't currently estimate the delta when switching profiles. In
the future, we want to use the count tokens API to measure every part of
the request and display a breakdown.

Release Notes:

- agent: Made the token count more accurate and added back estimation of
used tokens as you type and add context.

---------

Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
Co-authored-by: Danilo Leal <daniloleal09@gmail.com>
```

## Parents

- [8de53bd89f490137fecf1b7db36c65155c47782d](https://git.cafe/gitcafe/zed/commit/8de53bd89f490137fecf1b7db36c65155c47782d?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/0286b8ab3eeae8bb8ca89e770a39ff524488b298?format=markdown)
