fix: persist feedback metadata on assistant messages so history reloa…#1014
fix: persist feedback metadata on assistant messages so history reloa…#1014
Conversation
…ds keep feedback actions
🦋 Changeset detectedLatest commit: 6fec173 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This comment has been minimized.
This comment has been minimized.
📝 WalkthroughWalkthroughAdds feedback metadata persistence to assistant messages, changes conversation buffer APIs to support pending-only metadata application with boolean success returns, updates agent flows to capture and retry attaching response messages when metadata application initially fails, and adds tests and a changeset entry. Changes
Sequence DiagramsequenceDiagram
participant Agent as Agent Flow
participant Buffer as ConversationBuffer
participant Feedback as Feedback System
rect rgba(100, 150, 200, 0.5)
Note over Agent,Feedback: Feedback persistence with pending-only apply and retry
Agent->>Agent: Capture latestResponseMessages
Agent->>Buffer: addMetadataToLastAssistantMessage(metadata, {requirePending: true})
Buffer->>Buffer: findLastAssistantIndex({pendingOnly: true})
alt Metadata Applied
Buffer-->>Agent: return true
Agent->>Feedback: persist feedback
else Not Applied & latestResponseMessages exist
Buffer-->>Agent: return false
Agent->>Buffer: addModelMessages(latestResponseMessages, "response")
Agent->>Buffer: addMetadataToLastAssistantMessage(metadata, {requirePending: true})
Buffer-->>Agent: return boolean
Agent->>Feedback: persist feedback (if true) or skip (if false)
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Deploying voltagent with
|
| Latest commit: |
6fec173
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://445ed29c.voltagent.pages.dev |
| Branch Preview URL: | https://fix-persist-feedback.voltagent.pages.dev |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/core/src/agent/agent.ts`:
- Around line 1022-1036: The code unsafely casts result.response?.messages and
finalResult.response?.messages to ModelMessage[] before calling
buffer.addModelMessages; add a runtime type guard that validates each item is a
valid ResponseMessage (e.g., has required discriminators/fields for
AssistantModelMessage or ToolModelMessage) and filter/map the array to only
include validated items before calling buffer.addModelMessages and before
calling buffer.addMetadataToLastAssistantMessage; update the three spots that
cast (the uses around result.response?.messages, finalResult.response?.messages,
and the third occurrence) to use this validation so only correctly typed
ModelMessage instances are passed to addModelMessages and related helpers.
…ds keep feedback actions
PR Checklist
Please check if your PR fulfills the following requirements:
Bugs / Features
What is the current behavior?
What is the new behavior?
fixes (issue)
Notes for reviewers
Summary by cubic
Persist feedback metadata on assistant messages so history reloads keep previous feedback actions. Fixes #1009.
Written for commit 6fec173. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes
Tests