Documentation
¶
Overview ¶
Package userrules 是用户规则归一化的服务层:把各来源的自然语言规则经 LLM 单次调用 归一化成候选结构化字段,再由 rules.BuildSnapshot 确定性合并成本书快照。
分层职责:
- rules 包:纯数据 + 确定性合并(Snapshot / Candidate / BuildSnapshot / SystemDefaults)
- 本包:LLM 归一化 + 编排 + 落盘(依赖 agentcore + store + rules)
归一化是增强路径,不是主创作的前置条件:任何来源失败都降级为 raw preferences,主创作必须继续。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Normalizer ¶
type Normalizer struct {
// contains filtered or unexported fields
}
Normalizer 把单个来源的自然语言规则归一化成 rules.Candidate(单次 LLM 调用)。
func NewNormalizer ¶
func NewNormalizer(model agentcore.ChatModel) *Normalizer
NewNormalizer 用一个 ChatModel 构造归一化器。归一化是一次性启动工具, 应传入能力较强的模型(如 ModelSet 的默认模型),不必跟随写作的弱模型。
归一化是机械抽取、不需要推理:能关思考就关(腾出 max_tokens 给 JSON、省 latency 与成本)。 用模型自身的思考策略 Resolve(off)——支持关闭就关,不支持(o 系等总在思考的模型)则回落 ThinkingAuto(provider 默认),由 normalizeMaxTokens 的思考预算兜底避免截断。
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service 编排用户规则快照的生成与更新:归一化各来源 → 确定性合并 → 落盘。
两个调用方共用同一套逻辑:
- 开书/刷新(启动侧,确定性):Build / GetOrBuild,由 Host 直接调用,不经 Coordinator。
- 运行中更新(Coordinator 工具):AddRuntimeRule,save_user_rules 工具壳复用。
func NewService ¶
NewService 构造服务。model 用于归一化(应为能力较强的模型);model 为 nil 时 所有来源降级为 raw preferences(仍可产出快照,机械检查由 system_defaults 兜底)。
func (*Service) AddRuntimeRule ¶
func (s *Service) AddRuntimeRule(ctx context.Context, text string) (*rules.Snapshot, rules.Candidate, error)
AddRuntimeRule 归一化一条运行中长期规则,以最高优先级叠加到当前快照并落盘。 永不因归一化失败而报错——失败时该条降级为 raw preferences。 返回叠加后的快照与本次的归一化候选(后者供 save_user_rules 回显"理解成了什么"给用户确认)。