agent

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: 21 Imported by: 0

Documentation

Overview

Package agent 提供 Agent 门面:主循环 Runner + 会话记忆 + 运行时 保障(预算、结构化输出)的组合体。

Agent 自身实现 capability.Capability —— 一个 Agent 可以作为工具挂到 另一个 Agent 的能力面上,天然支持 sub-agent / supervisor 多智能体拓扑。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RawHistory

func RawHistory(all []*schema.Message) (raw []*schema.Message, beyondView int)

RawHistory 返回剔除摘要标记后的原始历史(供相关性召回等使用), 以及当前视图未包含的早期部分长度。

Types

type Agent

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

Agent 是可对外服务的最终产物。

func New

func New(name, description string, runner engine.Runner, m model.ToolCallingChatModel, opts Options) *Agent

New 组装一个 Agent。model 用于结构化输出修复与滚动摘要等门面级调用。

func (*Agent) AsLambda

func (a *Agent) AsLambda(ctx context.Context) (*compose.Lambda, error)

AsLambda 实现 capability.Capability。

func (*Agent) AsTool

func (a *Agent) AsTool(ctx context.Context) (tool.BaseTool, error)

AsTool 实现 capability.Capability。

func (*Agent) Description

func (a *Agent) Description() string

Description 返回 agent 描述。

func (*Agent) Interrupt

func (a *Agent) Interrupt(sessionID string)

Interrupt 叫停某会话正在进行的运行:下一次工具调用前生效,并取消 当前轮 ctx(终止进行中的模型调用与并行分支)。

func (*Agent) Meta

func (a *Agent) Meta() capability.Meta

Meta 实现 capability.Capability。

func (*Agent) Name

func (a *Agent) Name() string

Name 返回 agent 名。

func (*Agent) Run

func (a *Agent) Run(ctx context.Context, sessionID, input string) (string, error)

Run 执行一轮对话:注入运行上下文 → 加载会话历史 → 运行主循环 → (可选)结构化输出校验 → 回写历史(含本轮工具轨迹)。 同会话的并发轮被串行化;滚动摘要异步执行,不阻塞本轮返回。

func (*Agent) Steer

func (a *Agent) Steer(sessionID, msg string)

Steer 向某会话正在进行的运行注入一条用户插话,随下一个工具结果 送达模型(中途驾驶,不打断循环)。

func (*Agent) Stream

func (a *Agent) Stream(ctx context.Context, sessionID, input string) (*schema.StreamReader[*schema.Message], error)

Stream 流式执行一轮对话。返回的流复制两份:一份给调用方, 一份在后台聚合后回写会话历史(含本轮工具轨迹)。结构化输出与 流式互斥(用 Run)。

评审栈差异:Run 路径的终答评审(重复终止/收口守卫/拒绝核对/todo 收口)在流式下不生效——token 已经发给用户,弹回重答不可能。对终答 质量有硬要求的场景用 Run;流式是体验优先的通道。

func (*Agent) WaitCompactions

func (a *Agent) WaitCompactions()

WaitCompactions 等待在途滚动摘要完成(优雅关停与测试用)。

type Options

type Options struct {
	Store  session.Store
	Window int
	// Compaction 启用后做滚动摘要持久化:历史超阈值时把早期部分
	// 摘要成一条带 covered 标记的记录追加进 store(不删原始消息,
	// file 后端保留全量可审计);后续织入时视图 = 最新摘要 + 其后消息。
	Compaction loop.CompactionConfig
	Structured *loop.StructuredEnforcer
	Interactor runctx.Interactor
	// Approval 与 Budget 在每次运行时装入 ctx,对主循环与
	// skill/component 内部的 Ring 0 闸门统一生效。
	Approval *loop.ApprovalState
	Budget   *loop.BudgetGate
	// RecordTools 控制本轮工具轨迹随会话持久化的详略(默认 off,
	// config 层默认 summary)。
	RecordTools loop.RecordMode
	// ResultKV 是大结果暂存(digest)的后端与保留时长,由装配层注入;
	// nil = 该 agent 未配置结果暂存(digest 退化为纯截断)。
	ResultKV  store.KV
	ResultTTL time.Duration
}

Options 是 New 的可选项。

Jump to

Keyboard shortcuts

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