package
Version:
v0.4.0
Opens a new window with list of versions in this module.
Published: Oct 18, 2026
License: MIT
Opens a new window with license information.
Imports: 2
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
Documentation
¶
Package conversation 多轮会话历史的通用原语:滚动窗口切分、历史渲染、
摘要拼接。面向「模型无状态、连续性归运行时」的会话形态——verbatim 注入
只保留最近 N 轮,更早轮次交由调用方滚动压缩成摘要(摘要生成策略归调用方,
本包只做确定性切分与文本拼装)。
View Source
const (
QuestionCap = 200
AnswerCap = 400
)
渲染截断上限(rune):单轮注入不吞噬上下文预算。
Combine 滚动摘要 + verbatim 轮次 → 注入文本。summary 为空且无 recent 时
返回空串(调用方跳过注入)。
Render 会话历史 → 注入文本("用户:/助手:" 行 + 单轮截断)。
历史内容来自用户输入(攻击者可控),调用方必须把返回值放入数据区围栏。
type Turn struct {
Question string `json:"question"`
Answer string `json:"answer"`
At string `json:"at,omitempty"`
}
Turn 单轮问答(问答形态覆盖审查追问/客服/助手类会话;statement 型对话
可把 Question 留空)。
func Split(history []Turn, keep int) (recent, evicted []Turn)
Split 按 verbatim 窗口切分:recent=最近 keep 条(原样注入);evicted=其余
(应滚动压缩进摘要)。keep<=0 视为全 verbatim、无淘汰。
Source Files
¶
Click to show internal directories.
Click to hide internal directories.