Skip to content
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

feat: Add message history truncation #364

Merged
merged 2 commits into from
Dec 26, 2024

Conversation

johnjcsmith
Copy link
Contributor

@johnjcsmith johnjcsmith commented Dec 23, 2024

Adds handleContextWindowOverflow which truncates the chat history to ensure that it fits within the models context window.

This will work through the message history removing the oldest message until it is within the context window and ensures that the history remains valid:

  • Removes an agent message's subsequent invocation results
  • Ensuring the conversation starts with a human message

This only works on the messages that are fetched from the database (currently last 100).
It should be a final guard to make sure what we are sending the model is not going to overflow.

Ideally we will also implement some history summarisation.

@johnjcsmith johnjcsmith force-pushed the 351-message-history-truncation branch from 820a8cf to 1e84d5c Compare December 23, 2024 10:44
@johnjcsmith johnjcsmith force-pushed the 351-message-history-truncation branch 4 times, most recently from c0b6d1a to 92d9d57 Compare December 23, 2024 22:03
@johnjcsmith johnjcsmith force-pushed the 351-message-history-truncation branch 4 times, most recently from e8593c5 to 99b295b Compare December 23, 2024 22:32
@johnjcsmith johnjcsmith force-pushed the 351-message-history-truncation branch from 99b295b to f3b7487 Compare December 23, 2024 22:36
@johnjcsmith johnjcsmith merged commit 2489bf7 into main Dec 26, 2024
27 checks passed
@johnjcsmith johnjcsmith deleted the 351-message-history-truncation branch December 26, 2024 21:34
johnjcsmith added a commit that referenced this pull request Dec 26, 2024
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