spring-projects / spring-projects/spring-ai

MessageChatMemoryAdvisor and PromptChatMemoryAdvisor lack a way to pass custom Message metadata

Open
#2,437 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

Expected Behavior
I am trying to implement a persistent ChatMemory myself. In my persistent storage, I want each Message to have a custom unique primary key and other accompanying metadata (I think this is also a common requirement for many people). I will specify this when I construct the ChatClientRequestSpec, and then get it from the Message parameter when implementing the ChatMemory add method.

Current Behavior
I found that there is no part in the parameters of the ChatMemory add method that can carry custom metadata for the Message. Although the metadata property is provided in AbstractMessage, unfortunately, MessageChatMemoryAdvisor and PromptChatMemoryAdvisor create a new Message object when calling the add method, and do not pass any Metadata properties.

Context

I think I can use Advisor's adviseContext to achieve this goal. I can pass the metadata in by specifying params when constructing ChatClientRequestSpec, and then get them in MessageChatMemoryAdvisor and PromptChatMemoryAdvisor by getting the adviseContext of AdvisedRequest, add them to Message, and pass them to ChatMemory.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading MessageChatMemoryAdvisor and PromptChatMemoryAdvisor, focusing on how they create Messages before calling ChatMemory.add. Trace the AdvisedRequest advice context and the ChatMemory add method to understand the proposed metadata path. Done means custom metadata supplied through ChatClientRequestSpec reaches the Message received by a persistent ChatMemory implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
ai, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.