fix(agent): replay attachments in multi-turn history
Agent mode does not persist `rendered_content` for user messages, so when the next turn's history was rebuilt from DB, attachments uploaded in prior turns disappeared — the model only saw the raw query plus the prior assistant reply, breaking follow-up questions that referenced the file (e.g. "what is in there?"). Reconstruct the attachment prompt from the stored `Attachments` column when `RenderedContent` is empty, mirroring how image captions are already replayed. KnowledgeQA turns (which do persist `RenderedContent`) are unaffected and won't get attachments injected twice. Refs #1237
This commit is contained in:
@@ -127,8 +127,17 @@ func buildUserHistoryMessage(m *types.Message) chat.Message {
|
||||
if content == "" {
|
||||
content = m.Content
|
||||
}
|
||||
if captions := extractImageCaptionsFromMessage(m.Images); captions != "" && m.RenderedContent == "" {
|
||||
content += "\n\n[用户上传图片内容]\n" + captions
|
||||
// Only append fallbacks when RenderedContent is absent — when present, it
|
||||
// already carries the augmented version persisted by the original turn.
|
||||
// Agent-mode turns currently do not persist RenderedContent, so attachments
|
||||
// and image captions would otherwise be invisible to subsequent rounds.
|
||||
if m.RenderedContent == "" {
|
||||
if captions := extractImageCaptionsFromMessage(m.Images); captions != "" {
|
||||
content += "\n\n[用户上传图片内容]\n" + captions
|
||||
}
|
||||
if len(m.Attachments) > 0 {
|
||||
content += m.Attachments.BuildPrompt()
|
||||
}
|
||||
}
|
||||
return chat.Message{Role: "user", Content: content}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user