Documentation
¶
Index ¶
- func AgentIdentity(t AgentType) string
- func Allowlist(t AgentType) map[string]bool
- func BuildAlwaysSkillsContent(meta []skill.SkillMeta, store *skill.Store, novelID int64) string
- func BuildSkillCatalog(meta []skill.SkillMeta) string
- func NovelProfile(ctx context.Context, db *gorm.DB, novelID int64) (string, error)
- func NovelState(ctx context.Context, db *gorm.DB, novelID int64) (string, error)
- type AgentType
- type SystemMessages
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AgentIdentity ¶
System1 返回指定 Agent 的系统提示词。 提示词描述系统整体结构和 Agent 职责,具体工具用法由 MCP 工具的 Description 负责。 AgentIdentity 构建 Agent 的身份提示(原 System1)。
func BuildAlwaysSkillsContent ¶
BuildAlwaysSkillsContent 拼合所有 always 模式的 skill 正文,作为常驻系统消息注入。 不包含 YAML frontmatter,只拼接 body 内容。
func BuildSkillCatalog ¶
BuildSkillCatalog 将 auto 模式的 skill 元数据格式化为 LLM 可用的技能目录。 manual 和 always 模式的 skill 不出现在目录中。 按 novel > user > builtin 分组输出,每组只列出 name 和 description。
func NovelProfile ¶
NovelProfile 构建小说稳定设定快照(设定+偏好),独立 system 消息。 与 NovelState 区分:Profile 装长期稳定内容(设定/偏好),State 装动态内容(goink.md)。 KV cache 友好:Profile 跨轮稳定,State 每轮可能变。
调用方负责事务外构建(compress 模式):传入的 db 应为带 ctx 的非事务句柄, 避免在事务内调用导致 SQLite 单连接池死锁。
设定软上限 12k token(setting.SettingsTokenBudget)、偏好软上限 8k token(preference.PreferencesTokenBudget): 超预算时按 updated_at DESC 保留最近活跃的,丢弃最久未活动的。这里用 slog.Default() 记 warn,best-effort 不阻塞流程。 拼接顺序:设定在前、偏好在后(与 system 消息注入顺序一致)。
v2:设定取消 is_global,全部归属当前小说(只查 novel_id = ?); 偏好保留 is_global(用户级容器,含全局+小说级,仍查 is_global OR novel_id)。 排序改 updated_at DESC:用户最近更新过的旧条目也能被保留(不被截断),比 created_at 更符合"活跃=保留"语义。
func NovelState ¶
NovelState 构建小说动态状态快照(原 System3),每轮对话开头注入。 只包含基本信息 + 故事状态文档(goink.md)。 稳定内容(设定/偏好)由 NovelProfile 注入,与 NovelState 分离以优化 KV cache。 具体数据(角色、时间线等)由 MCP 工具按需提供。
调用方负责事务外构建(compress 模式):传入的 db 应为带 ctx 的非事务句柄, 避免在事务内调用导致 SQLite 单连接池死锁。
Types ¶
type SystemMessages ¶
type SystemMessages struct {
Identity string // AgentIdentity(system1 提示词)
Always string // 常驻技能正文
Catalog string // auto 模式技能目录
Profile string // NovelProfile(设定+偏好,稳定)
State string // NovelState(基础信息+goink.md,动态)
}
SystemMessages 是注入对话的 system 消息集合。 chat 和 compress 共用此结构,避免重复构建逻辑(呼应踩坑 16)。
func BuildSystemMessages ¶
func BuildSystemMessages(ctx context.Context, db *gorm.DB, novelID int64, skillStore *skill.Store) (*SystemMessages, error)
BuildSystemMessages 统一构建 main agent 的 system 消息。 chat 和 compress 共用此函数,避免重复实现。
全部在事务外构建(compress 模式):传入的 db 应为带 ctx 的非事务句柄, 避免在事务内调用导致 SQLite 单连接池死锁(呼应踩坑 13/15)。 skillStore 为 nil 时跳过 Always/Catalog。
容错:Profile/State 构建失败时对应字段为空(写入时跳过),不阻断对话。 返回的 error 是聚合错误,调用方可用于 log,但 msg 仍可使用。
注意:本函数固定使用 MainAgent 的 Identity,不适用于 subagent。 subagent 路径请直接调 AgentIdentity(at) + NovelProfile + NovelState。