offload

package
v1.3.4 Latest Latest
Warning

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

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

Documentation

Overview

Package offload 是 ToolEndHook:超大工具结果卸载到文件系统, 上下文里只保留头部摘要与文件路径,防止大输出(日志、转储、目录遍历) 撑爆上下文。写入失败时降级透传原文,绝不阻断工具执行。 结果后处理不耦合工具节点本身,故为 hook 而非 warp。

配置 ReplayTool(如 read_file)后,摘要尾部提示模型用该工具回放 卸载文件全文,且该工具自身的结果免卸载——回放的意义就是把全文 带回上下文,再卸载即死循环。

Index

Constants

View Source
const DefaultThreshold = 4096

DefaultThreshold 超过此字节数的结果触发卸载。

Variables

This section is empty.

Functions

func WithReplayTool added in v1.3.2

func WithReplayTool(name string) func(*Options)

WithReplayTool 指定回放工具名(如 read_file),摘要尾部提示模型用它回放全文。

func WithSkip added in v1.3.0

func WithSkip(names ...string) func(*Options)

WithSkip 设置免卸载名单:名单内工具的结果不做大卸载。

Types

type Hook

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

func New

func New(fsys fs.FileSystem, opts ...func(*Options)) *Hook

New 创建卸载 hook,挂载后自动处理所有工具的大结果。

func (*Hook) Name

func (h *Hook) Name() string

func (*Hook) OnToolEnd

func (h *Hook) OnToolEnd(ctx context.Context, _ *types.LoopState, result *types.ToolResult) error

type Options

type Options struct {
	// Threshold 触发阈值,默认 4096 字节。
	Threshold int
	// Dir 卸载目标目录(FS 内路径),默认 ".ezloop/offload"。
	Dir string
	// Head 保留在消息里的原文头部长度,默认 512。
	Head int
	// Skip 免卸载名单:这些工具的结果原样保留(如分身最终答案——
	// 截断成摘要会伤主循环决策)。
	Skip []string
	// ReplayTool 回放工具名(如 read_file):摘要尾部提示模型用它读回
	// 卸载文件全文,该工具的结果自动免卸载。空串(默认)不提示。
	ReplayTool string
}

Jump to

Keyboard shortcuts

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