feat(llm): introduce request-local source reference aliases

Replace raw chunk/document/KB IDs in LLM context with short cN/dN/bN/wN
aliases, decode tool arguments on the way in, and expand compact <ref/>
citations to the public <kb>/<web> format before user-facing output.
This commit is contained in:
wizardchen
2026-07-16 21:23:20 +08:00
committed by lyingbug
parent 79e8f3d894
commit 014164ae44
33 changed files with 1962 additions and 149 deletions
+10 -19
View File
@@ -117,27 +117,18 @@ func LoadAgentHistory(
}
// buildUserHistoryMessage converts a stored user message into the chat.Message
// form that should appear in LLM history. It prefers RenderedContent (which
// already contains any retrieval-context augmentation from prior turns) and
// falls back to Content. When the user uploaded images, the captions extracted
// during ingestion are appended so subsequent turns retain a textual reference
// to those images even after the binary payload is gone.
// form that should appear in LLM history. It deliberately ignores
// RenderedContent: that field is a snapshot of the old prompt and retrieval
// context format, which must not be mixed into the current request protocol.
// Image captions and attachments are reconstructed from their canonical DB
// columns so useful user-provided context is retained without stale RAG data.
func buildUserHistoryMessage(m *types.Message) chat.Message {
content := m.RenderedContent
if content == "" {
content = m.Content
content := m.Content
if captions := extractImageCaptionsFromMessage(m.Images); captions != "" {
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 do not persist RenderedContent (scope envelopes are
// injected only for the current LLM call, not replayed from history).
if m.RenderedContent == "" {
if captions := extractImageCaptionsFromMessage(m.Images); captions != "" {
content += "\n\n[用户上传图片内容]\n" + captions
}
if len(m.Attachments) > 0 {
content += m.Attachments.BuildPrompt()
}
if len(m.Attachments) > 0 {
content += m.Attachments.BuildPrompt()
}
return chat.Message{Role: "user", Content: content}
}