Documentation
¶
Index ¶
- func FormatResult(r *AgentResult) string
- type AgentLoop
- type AgentResult
- type ExecStep
- type Option
- type PlanExecutor
- type PlanOption
- func WithPlanCallback(fn func(steps []PlanStep)) PlanOption
- func WithPlanMaxPlanRounds(n int) PlanOption
- func WithPlanMaxReplans(n int) PlanOption
- func WithPlanMaxRoundsPerStep(n int) PlanOption
- func WithPlanMaxSteps(n int) PlanOption
- func WithPlanPersistPath(path string) PlanOption
- func WithPlanStepCallback(fn func(step *ExecStep)) PlanOption
- func WithPlanSystemPrompt(prompt string) PlanOption
- type PlanResult
- type PlanStep
- type Step
- type StepStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AgentLoop ¶
type AgentLoop struct {
// contains filtered or unexported fields
}
AgentLoop ReAct 循环引擎 执行模式:思考 → 行动 → 观察 → 循环,直到 Agent 给出最终回答
func NewAgentLoop ¶
func NewAgentLoop(model chatmodel.BaseModel, registry *tools.ToolRegistry, opts ...Option) *AgentLoop
NewAgentLoop 创建 ReAct 循环引擎
type AgentResult ¶
AgentResult ReAct 循环执行结果
type ExecStep ¶
type ExecStep struct {
PlanStep PlanStep
AgentResult *AgentResult
Status StepStatus
Error string
Duration time.Duration
}
ExecStep 执行步骤记录
type Option ¶
type Option func(*AgentLoop)
Option AgentLoop 配置选项
func WithMaxMessages ¶
WithMaxMessages 设置消息窗口大小(防止长任务内存膨胀,0=不限制) 保留系统消息 + 最近 N 条消息
type PlanExecutor ¶
type PlanExecutor struct {
// contains filtered or unexported fields
}
PlanExecutor Plan-and-Execute 策略引擎 Phase 1: LLM 生成执行计划(自然语言步骤) Phase 2: 验证计划(依赖检查) Phase 3: 逐步执行,每步用 ReAct 循环 Phase 4: 验证结果,必要时重规划
func NewPlanExecutor ¶
func NewPlanExecutor(model chatmodel.BaseModel, registry *tools.ToolRegistry, opts ...PlanOption) *PlanExecutor
NewPlanExecutor 创建 Plan-and-Execute 引擎
func (*PlanExecutor) Run ¶
func (pe *PlanExecutor) Run(ctx context.Context, goal string) (*PlanResult, error)
Run 执行 Plan-and-Execute 流程
type PlanOption ¶
type PlanOption func(*PlanExecutor)
PlanOption PlanExecutor 配置选项
func WithPlanCallback ¶
func WithPlanCallback(fn func(steps []PlanStep)) PlanOption
func WithPlanMaxPlanRounds ¶
func WithPlanMaxPlanRounds(n int) PlanOption
func WithPlanMaxReplans ¶
func WithPlanMaxReplans(n int) PlanOption
func WithPlanMaxRoundsPerStep ¶
func WithPlanMaxRoundsPerStep(n int) PlanOption
func WithPlanMaxSteps ¶
func WithPlanMaxSteps(n int) PlanOption
func WithPlanPersistPath ¶
func WithPlanPersistPath(path string) PlanOption
func WithPlanStepCallback ¶
func WithPlanStepCallback(fn func(step *ExecStep)) PlanOption
func WithPlanSystemPrompt ¶
func WithPlanSystemPrompt(prompt string) PlanOption
type PlanResult ¶
type PlanResult struct {
Answer string
Steps []*ExecStep
PlanSteps []PlanStep
Rounds int // 总 ReAct 轮次
Replans int // 重规划次数
Usage schema.Usage
}
PlanResult 规划执行结果
type PlanStep ¶
type PlanStep struct {
ID string `json:"id"`
Description string `json:"description"`
DependsOn []string `json:"depends_on,omitempty"`
}
PlanStep 计划中的单个步骤
type Step ¶
type Step struct {
Round int
Thinking string // Agent 的思考内容
ToolCalls []schema.ToolCall // 本轮工具调用
ToolResults []schema.ToolResult // 工具执行结果
Response string // 最终回答(最后一轮)
Duration time.Duration
IsFinal bool // 是否是最终回答
}
Step ReAct 单步记录
type StepStatus ¶
type StepStatus string
StepStatus 步骤状态
const ( StepPending StepStatus = "pending" StepRunning StepStatus = "running" StepSuccess StepStatus = "success" StepFailed StepStatus = "failed" StepSkipped StepStatus = "skipped" )
Click to show internal directories.
Click to hide internal directories.