Skip to content

Conversation

@tawsifkamal
Copy link
Contributor

@tawsifkamal tawsifkamal commented Mar 13, 2025

Truncates conversation history + summarizes in two instances

  1. Number of messages passed in to the LLM exceeds max_messages which is default set to 100
  2. The context limit for the LLM is approaching shortly (measured by counting tokens and measuring if the current message input tokens > max_input_tokens_for_model - 10000)

Algorithm -> similar to OpenHands summarizer

  1. Keep the first two messages (System Prompt + Human Message)
  2. Truncate the number of messages to almost half (len(state[messages])) // 2) and leave the last N messages untouched
  3. Summarize the conversation in between the first two (keep_first_messages) until the tail.

Misc

  • We are able to pass in agent_config param to CodeAgent if we want to play around with the max_messages, or keep_first_messages property
image

Sample Trace (setting max_messages = 10) -> https://smith.langchain.com/public/60c0eef2-4e46-4506-86d7-9acd48b01cbe/r

Copy link
Contributor

@jemeza-codegen jemeza-codegen left a comment

Choose a reason for hiding this comment

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

Left a few comments, overall looks good!

Copy link
Contributor

@jemeza-codegen jemeza-codegen left a comment

Choose a reason for hiding this comment

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

Looks good !

@tawsifkamal tawsifkamal merged commit a9b29fa into develop Mar 14, 2025
17 of 18 checks passed
@tawsifkamal tawsifkamal deleted the tawsif/memory-management branch March 14, 2025 19:04
@github-actions
Copy link
Contributor

🎉 This PR is included in version 0.51.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants