Help us shape the future of Go! Take the 2026 Go Developer Survey

agentcfg

package
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentIdentity

func AgentIdentity(t AgentType) string

System1 返回指定 Agent 的系统提示词。 提示词描述系统整体结构和 Agent 职责,具体工具用法由 MCP 工具的 Description 负责。 AgentIdentity 构建 Agent 的身份提示(原 System1)。

func Allowlist

func Allowlist(t AgentType) map[string]bool

Allowlist 返回指定 Agent 的工具白名单。

func BuildAlwaysSkillsContent

func BuildAlwaysSkillsContent(meta []skill.SkillMeta, store *skill.Store, novelID int64) string

BuildAlwaysSkillsContent 拼合所有 always 模式的 skill 正文,作为常驻系统消息注入。 不包含 YAML frontmatter,只拼接 body 内容。

func BuildSkillCatalog

func BuildSkillCatalog(meta []skill.SkillMeta) string

BuildSkillCatalog 将 auto 模式的 skill 元数据格式化为 LLM 可用的技能目录。 manual 和 always 模式的 skill 不出现在目录中。 按 novel > user > builtin 分组输出,每组只列出 name 和 description。

func NovelProfile

func NovelProfile(ctx context.Context, db *gorm.DB, novelID int64) (string, error)

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

func NovelState(ctx context.Context, db *gorm.DB, novelID int64) (string, error)

NovelState 构建小说动态状态快照(原 System3),每轮对话开头注入。 只包含基本信息 + 故事状态文档(goink.md)。 稳定内容(设定/偏好)由 NovelProfile 注入,与 NovelState 分离以优化 KV cache。 具体数据(角色、时间线等)由 MCP 工具按需提供。

调用方负责事务外构建(compress 模式):传入的 db 应为带 ctx 的非事务句柄, 避免在事务内调用导致 SQLite 单连接池死锁。

Types

type AgentType

type AgentType int

AgentType 定义 Agent 类型。

const (
	MainAgent   AgentType = iota // 主创作助手
	ReviewAgent                  // 章节审稿人
	MemoryAgent                  // 记忆检索分析员
)

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。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL