Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LoopState ¶
type LoopState struct {
Input string
Messages []Message
Tools *ToolRegistry
Iteration int
MaxIterations int
// PendingToolCalls 是本轮模型响应中待执行的调用,由引擎填充。
PendingToolCalls []ToolCall
LastResponse *ModelResponse
Usage Usage
// Metadata 供 hook 之间共享任意数据。
// 并发契约:除 OnToolStart / OnToolEnd(跨调用并发)外,引擎串行执行
// hook 回调;这两个回调内写 Metadata 须自行加锁。
Metadata map[string]any
// Emitter 由引擎注入:hook 通过它发送自定义事件到 OnEvent 回调。
// hook 回调由引擎串行调用,此路径无并发;OnToolStart / OnToolEnd
// 跨调用并发,其中发事件须遵守 OnEvent 的并发契约(快速返回、并发安全)。
Emitter event.OnEvent
// Stop 置 true 后,当前节点收尾完毕即终止 loop。
Stop bool
StopReason StopReason
StartedAt time.Time
EndedAt time.Time
}
LoopState 是贯穿整个 loop 的统一结构体,hook 可读写任意字段。 context.Context 按 Go 惯例作为独立参数传递,不放入 State。
func (*LoopState) AppendMessage ¶
type ModelRequest ¶
ModelRequest 是引擎调用 Provider 时的完整输入。
type ModelResponse ¶
ModelResponse 是模型单次响应:纯文本,或附带 tool calls 触发下一轮循环。
type StopReason ¶
type StopReason string
const ( StopCompleted StopReason = "completed" StopMaxIteration StopReason = "max_iterations" StopAborted StopReason = "aborted" StopError StopReason = "error" StopCancelled StopReason = "cancelled" )
type Tool ¶
type Tool interface {
Name() string
Description() string
ArgsSchema() json.RawMessage
Invoke(ctx context.Context, args json.RawMessage) (string, error)
}
type ToolRegistry ¶
type ToolRegistry struct {
// contains filtered or unexported fields
}
func NewToolRegistry ¶
func NewToolRegistry(tools ...Tool) *ToolRegistry
func (*ToolRegistry) List ¶
func (r *ToolRegistry) List() []Tool
func (*ToolRegistry) Register ¶
func (r *ToolRegistry) Register(t Tool)
func (*ToolRegistry) SetWarp ¶
func (r *ToolRegistry) SetWarp(warp func(Tool) Tool)
SetWarp 设置注册拦截:之后所有 Register 的工具都会被包装 (包括 hook 在运行时注入的工具,如 mcp router)。已注册的不受影响。
Click to show internal directories.
Click to hide internal directories.