Documentation
¶
Overview ¶
Package agent 提供 Agent 门面:主循环 Runner + 会话记忆 + 运行时 保障(预算、结构化输出)的组合体。
Agent 自身实现 capability.Capability —— 一个 Agent 可以作为工具挂到 另一个 Agent 的能力面上,天然支持 sub-agent / supervisor 多智能体拓扑。
Index ¶
- func RawHistory(all []*schema.Message) (raw []*schema.Message, beyondView int)
- type Agent
- func (a *Agent) AsLambda(ctx context.Context) (*compose.Lambda, error)
- func (a *Agent) AsTool(ctx context.Context) (tool.BaseTool, error)
- func (a *Agent) Description() string
- func (a *Agent) Interrupt(sessionID string)
- func (a *Agent) Meta() capability.Meta
- func (a *Agent) Name() string
- func (a *Agent) Run(ctx context.Context, sessionID, input string) (string, error)
- func (a *Agent) Steer(sessionID, msg string)
- func (a *Agent) Stream(ctx context.Context, sessionID, input string) (*schema.StreamReader[*schema.Message], error)
- func (a *Agent) WaitCompactions()
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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) Run ¶
Run 执行一轮对话:注入运行上下文 → 加载会话历史 → 运行主循环 → (可选)结构化输出校验 → 回写历史(含本轮工具轨迹)。 同会话的并发轮被串行化;滚动摘要异步执行,不阻塞本轮返回。
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 的可选项。
Click to show internal directories.
Click to hide internal directories.