userrules

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

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 为不可关闭思考的模型预留输出预算。

func (*Normalizer) Normalize

func (n *Normalizer) Normalize(ctx context.Context, source, text string) (rules.Candidate, error)

Normalize 归一化一个来源。失败返回 error(含真实原因),由调用方决定降级 (Service.normalizeOrDegrade 落 degraded 候选)——技术错误不再伪装成正常结果, 终止错误(鉴权/权限等)不重试。

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service 编排用户规则快照的生成与更新:归一化各来源 → 确定性合并 → 落盘。

两个调用方共用同一套逻辑:

  • 开书/刷新:Build / GetOrBuild,由 Host 确定性调用。
  • 运行中更新:Arbiter 提取 rules 后,Host 调用 AddRuntimeRule。

func NewService

func NewService(st *store.Store, model agentcore.ChatModel, opts rules.LoadOptions) *Service

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。 返回叠加后的快照与本次的归一化候选。

func (*Service) Build

func (s *Service) Build(ctx context.Context, startupPrompt string) (*rules.Snapshot, error)

Build 从静态来源(system_defaults + rules 文件 + 启动 prompt)归一化生成快照并落盘。 开书/刷新时调用。startupPrompt 可空。

func (*Service) GetOrBuild

func (s *Service) GetOrBuild(ctx context.Context) (*rules.Snapshot, error)

GetOrBuild 返回当前快照;缺失时按 system_defaults + rules 文件初始化。 运行时读取路径统一走这里。

Jump to

Keyboard shortcuts

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