session

package
v0.0.0-...-1c978d5 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package session 定义会话历史存储的契约与工厂,不含具体后端实现。 历史织入由 agent 运行时自动完成(模型无感知)——该不该带历史不是模型 的决策,是流程保证。后端(inmemory/file/redis/…)在 impl/session/* 下实现 并 init 自注册,消费方只经 New 工厂拿 Store,不直接构造具体后端。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(typ string, f Factory)

Register 注册存储类型(inmemory/file/redis/自定义):实现方 init 自注册, 空导入(或经 agent-kit/std)即可在配置里以 store: <type> 引用。

func RegisterRetriever

func RegisterRetriever(name string, f RetrieverFactory)

RegisterRetriever 注册检索策略(bigram/向量/rerank/自定义):实现方 init 自注册,空导入即可在配置里以 retriever: <name> 引用。

func Trim

func Trim(msgs []*schema.Message, window int) []*schema.Message

Trim 按窗口裁剪消息(window<=0 不裁剪),供各 Store 后端复用。

Types

type Factory

type Factory func(conf map[string]any, window int) (Store, error)

Factory 按配置构造存储。window 为保留的最近消息条数,<=0 不裁剪 (裁剪只影响 Load 结果,持久化后端应保留全量记录)。

type FullLoader

type FullLoader interface {
	LoadAll(ctx context.Context, sessionID string) ([]*schema.Message, error)
}

FullLoader 是可选扩展:返回不裁剪的全量历史。实现它的后端可享受 滚动摘要持久化与会话内相关性召回;内置 inmemory/file/redis 均已实现。

type Retriever

type Retriever interface {
	Retrieve(ctx context.Context, history []*schema.Message, input string, topK int) []string
}

Retriever 是窗外会话召回的检索策略契约:从历史消息中找出与本轮 输入相关的片段。查询构造(要不要扩展/改写输入)也是实现的职责。

这是 Ring 1 扩展点:检索是"同一契约、多种实现、坏了只降质量"的 纯函数,语义召回(向量/rerank)注册后即可在配置里以名字引用; 织入视图的重建(摘要/锚定/窗口)则是 Ring 0 不变量,不在此开放。 内置词法保底 bigram 在 impl/session/bigram。

func NewRetriever

func NewRetriever(name string, conf map[string]any) (Retriever, error)

NewRetriever 按名字构造检索器,空名默认 bigram(内置词法保底)。

type RetrieverFactory

type RetrieverFactory func(conf map[string]any) (Retriever, error)

RetrieverFactory 按配置构造检索器。

type Store

type Store interface {
	Load(ctx context.Context, sessionID string) ([]*schema.Message, error)
	Append(ctx context.Context, sessionID string, msgs ...*schema.Message) error
	Clear(ctx context.Context, sessionID string) error
}

Store 是会话历史存储的最小契约。Load 返回窗口裁剪后的最近消息。

func New

func New(typ string, conf map[string]any, window int) (Store, error)

New 按类型构造存储,空类型默认 inmemory。后端未注册时 fail-fast(提示 空导入 impl 后端或 agent-kit/std)。

Jump to

Keyboard shortcuts

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