Documentation
¶
Overview ¶
Package core 实现 loop 引擎:NewAgent 组装 Provider、Hook 与工具, Run 驱动 "model → tool → model" 循环直到完成或终止。
Index ¶
- Constants
- type Agent
- type HyperParams
- type Option
- func WithHooks(hooks ...hook.Hook) Option
- func WithHyperParams(hp HyperParams) Option
- func WithMaxIterations(n int) Option
- func WithModelWarp(warps ...provider.WarpHandler) Option
- func WithOnEvent(fn event.OnEvent) Option
- func WithStreaming(enabled bool) Option
- func WithSystemPrompt(prompt string) Option
- func WithToolWarp(warps ...types.ToolWarpHandler) Option
- func WithTools(tools ...types.Tool) Option
- type RunHandle
- type RunOption
Constants ¶
const DefaultMaxIterations = 16
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
func (*Agent) Run ¶
func (a *Agent) Run(ctx context.Context, input string, runOpts ...RunOption) (state *types.LoopState, err error)
Run 驱动整个 loop:model ↔ tool 循环,直到模型不再发起 tool call、 达到 MaxIterations、hook 置 Stop 或出错。EndHook 无论成败都会执行。 消息序列构造顺序:system 提示词 → WithHistory 历史 → 本次 input, 随后 startHook 可继续注入(如 skill)。
type HyperParams ¶
type HyperParams struct {
// MaxIterations 最大迭代次数,0 取默认 16。
MaxIterations int
// MaxConcurrency 单轮工具并发执行上限,1 为串行(默认)。
MaxConcurrency int
}
HyperParams 是 Agent 的运行超参数。
type Option ¶
type Option func(*Agent)
func WithHyperParams ¶
func WithHyperParams(hp HyperParams) Option
WithHyperParams 设置运行超参数(迭代上限、工具并发量等)。
func WithMaxIterations ¶
func WithModelWarp ¶
func WithModelWarp(warps ...provider.WarpHandler) Option
WithModelWarp 传入模型节点中间件(引擎标准能力), 在 NewAgent 时包装 provider。先注册的位于最外层。
func WithOnEvent ¶
func WithStreaming ¶
WithStreaming 启用后,Provider 若实现 StreamProvider 则走流式, chunk 通过 EventModelChunk 实时发出。
func WithSystemPrompt ¶
WithSystemPrompt 设置 agent 级系统提示词(人格、规则等), 位于消息序列最前。会话级动态注入用 skill hook 或 WithHistory。
func WithToolWarp ¶
func WithToolWarp(warps ...types.ToolWarpHandler) Option
WithToolWarp 传入工具节点中间件(引擎标准能力)。 挂载在 ToolRegistry 上:静态注册(WithTools)与 hook 运行时注入的工具 都会被包装。先注册的位于最外层。
type RunHandle ¶
type RunHandle struct {
// contains filtered or unexported fields
}
RunHandle 是 RunAsync 的异步句柄:Events 通道消费实时事件, Cancel 取消执行,Wait 获取最终结果。loop 结束后 Events 自动关闭。
func (*RunHandle) Cancel ¶
func (h *RunHandle) Cancel()
Cancel 取消执行(幂等)。loop 在当前节点收尾后以 cancelled 停止。
type RunOption ¶
RunOption 是单次 Run 的定制项。
func WithHistory ¶
WithHistory 携带历史对话消息(多轮会话延续), 历史位于本次 input 之前、system 提示词之后。 system 消息会被过滤:它们是 agent 的属性(WithSystemPrompt、skill hook), 每轮由引擎重新注入,历史快照中的 system 不应重复带入。