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

Metadata Loss in AdvisedRequest.toPrompt() (Spring AI v1.0.0-M6) #2355

Open
miimnoon opened this issue Mar 1, 2025 · 0 comments
Open

Metadata Loss in AdvisedRequest.toPrompt() (Spring AI v1.0.0-M6) #2355

miimnoon opened this issue Mar 1, 2025 · 0 comments

Comments

@miimnoon
Copy link

miimnoon commented Mar 1, 2025

Dear Spring AI Team,
I am reaching out to report an issue in Spring AI v1.0.0-M6 related to metadata loss when calling AdvisedRequest.toPrompt() inside an advisor method.

🔹 Problem Description:
When retrieving the Prompt from AdvisedRequest using request.toPrompt(), a new message object is created, causing all previously set metadata (conversationId, userId, etc.) to be lost.

🔹 Steps to Reproduce:
Setting Metadata in UserMessage

java
Copy
Edit
Map<String, Object> metadata = new HashMap<>();
metadata.put("conversationId", conversationId);
metadata.put("userId", userId);

UserMessage userMessage = new UserMessage(userQuery, Collections.emptyList(), metadata);

String answer = chatClient.prompt()
.messages(List.of(userMessage))
.options(options)
.call()
.content();
Retrieving Metadata in Advisor (aroundCall method)

java
Copy
Edit
@OverRide
public AdvisedResponse aroundCall(AdvisedRequest request, CallAroundAdvisorChain chain) {
Prompt prompt = request.toPrompt(); // This creates a new message object

// Attempt to retrieve metadata
Message lastMessage = prompt.getMessages().get(prompt.getMessages().size() - 1);

if (lastMessage instanceof UserMessage userMessage) {
    logger.debug("Message metadata: {}", userMessage.getMetadata()); // ❌ Always null
}

return chain.nextAroundCall(request);

}
🔹 Expected Behavior:
UserMessage metadata should persist when calling request.toPrompt().
The metadata set in UserMessage should be retrievable in the advisor.
🔹 Actual Behavior:
request.toPrompt() creates a new message object, losing all metadata.
When retrieving UserMessage from prompt.getMessages(), getMetadata() always returns null.
🔹 Environment:
Spring AI Version: 1.0.0-M6

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

No branches or pull requests

1 participant