Skip to content

Conversation

@sjrl
Copy link
Contributor

@sjrl sjrl commented Oct 24, 2025

Related Issues

Proposed Changes:

  • ChatMessageStore
    • Require an index parameter to all methods. The index param is meant to be a unique identifier for the chat session whose messages should be retrieved. We require the index parameter at runtime to make it easy to handle many different chat sessions with one chat message store.
  • ChatMessageRetriever
    • Update the run method to take in a required index parameter.
    • Take in an optional new_messages parameter that will append these new messages to the end of the list of retrieved messages. This enables the pattern ChatPromptBuilder --> ChatMessageRetriever --> ChatGenerator/Agent without needing to use an OutputAdapter to combine the outputs of the ChatPromptBuilder and the ChatMessageRetriever.
    • Adds a field called is_stored to the meta of the retrieved ChatMessage's. This is used to make it easier to know which ChatMessage's to skip if the full chat history + new messages are passed into a downstream ChatMessageWriter (e.g. such as the output from Agent)
  • ChatMessageWriter
    • Update the run method to take in a required index parameter.

TODOs

  • Update last_k to either be rounds of user-agent interactions instead of last k number of messages. Or try to keep it as last_k number of messages but only return a valid list of messages. E.g. A LLM provider will complain if a Tool Result message is sent without it's corresponding Tool Call message.
  • We have a chance to duplicate the system message since it's often set in the init of components like Agent and right now it could be retrieved from the Chat Message Store. Either 1) Add init param to ChatMessageRetriever to skip/remove system message or 2) Add init param to ChatMessageWriter to not write system message
  • Would it be possible to update the ChatPromptBuilder to accept a list of messages (example below). This would allow for more flexibility in deciding how the chat history should be managed and would allow us to remove this functionality from the ChatMessageRetriever
prompt = """
{chat_history_messages}
{% message role="user" %}
{{query}}
{% endmessage %}
"""

How did you test it?

Notes for the reviewer

Checklist

@coveralls
Copy link

coveralls commented Oct 27, 2025

Pull Request Test Coverage Report for Build 18878440139

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 82 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.2%) to 71.375%

Files with Coverage Reduction New Missed Lines %
chat_message_stores/in_memory.py 1 97.22%
components/writers/chat_message_writer.py 4 83.87%
components/retrievers/chat_message_retriever.py 7 85.0%
components/agents/agent.py 70 35.37%
Totals Coverage Status
Change from base Build 18859815470: 0.2%
Covered Lines: 1142
Relevant Lines: 1600

💛 - Coveralls

@sjrl sjrl changed the title [WIP] refactor: Refactoring InMemoryChatMessageStore, ChatMessageRetriever, ChatMessageWriter feat: Update InMemoryChatMessageStore, ChatMessageRetriever, ChatMessageWriter Oct 27, 2025
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.

Add ChatMessage-Based Memory Storage and Retrieval for Agent

3 participants