Skip to content

An implementation of ChatMemory based on token size control #3424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sunyuhan1998
Copy link
Contributor

@sunyuhan1998 sunyuhan1998 commented Jun 3, 2025

Fixes #3423
As #3423 mentioned, a ChatMemory that limits the window based on token size would be more practical. This PR provides such an implementation: TokenWindowChatMemory.

This implementation limits the chat memory based on the total number of tokens. When the total token count exceeds the limit, the oldest messages are evicted.

Messages are indivisible, meaning that if the token limit is exceeded, the entire oldest message is removed.

…ding window limit: TokenWindowChatMemory.

This implementation limits the chat memory based on the total number of tokens. When the total token count exceeds the limit, the oldest messages are evicted.

Messages are indivisible, meaning that if the token limit is exceeded, the entire oldest message is removed.

Signed-off-by: Sun Yuhan <1085481446@qq.com>
@sunyuhan1998
Copy link
Contributor Author

Hi @ilayaperumalg @markpollack , what do you think of this?

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.

A ChatMemory implementation based on token size control is required.
1 participant