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。
func NewNormalizer ¶
func NewNormalizer(model agentcore.ChatModel) *Normalizer
NewNormalizer 用一个 ChatModel 构造归一化器。归一化是一次性启动工具, 应传入能力较强的模型(如 ModelSet 的默认模型),不必跟随写作的弱模型。
归一化不覆盖 thinking:显式 off 本身也是只有部分模型支持的推理参数, 普通 chat 模型会拒绝它。沿用 provider/model 默认,由 normalizeMaxTokens 为不可关闭思考的模型预留输出预算。
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service 编排用户规则快照的生成与更新:归一化各来源 → 确定性合并 → 落盘。
两个调用方共用同一套逻辑:
- 开书/刷新:Build / GetOrBuild,由 Host 确定性调用。
- 运行中更新:Arbiter 提取 rules 后,Host 调用 AddRuntimeRule。
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。 返回叠加后的快照与本次的归一化候选。