Documentation
¶
Index ¶
- func FormatPlan(plan *ExecutionPlan) string
- type ExecutionOptions
- type ExecutionPlan
- func (p *ExecutionPlan) AddStep(toolName, description string, params map[string]any) *Step
- func (p *ExecutionPlan) Approve(approvedBy string)
- func (p *ExecutionPlan) CanExecute() bool
- func (p *ExecutionPlan) GetCurrentStep() *Step
- func (p *ExecutionPlan) GetStep(index int) *Step
- func (p *ExecutionPlan) IsApproved() bool
- func (p *ExecutionPlan) IsCompleted() bool
- func (p *ExecutionPlan) MarkStepCompleted(index int, result any)
- func (p *ExecutionPlan) MarkStepFailed(index int, err error)
- func (p *ExecutionPlan) MarkStepStarted(index int)
- func (p *ExecutionPlan) Reject(note string)
- func (p *ExecutionPlan) Summary() PlanSummary
- type Executor
- type ExecutorOption
- func WithOnPlanComplete(fn func(plan *ExecutionPlan)) ExecutorOption
- func WithOnStepComplete(fn func(plan *ExecutionPlan, step *Step)) ExecutorOption
- func WithOnStepFailed(fn func(plan *ExecutionPlan, step *Step, err error)) ExecutorOption
- func WithOnStepStart(fn func(plan *ExecutionPlan, step *Step)) ExecutorOption
- type Generator
- type GeneratorOption
- type PlanRequest
- type PlanSummary
- type Status
- type Step
- type StepStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ExecutionOptions ¶
type ExecutionOptions struct {
// 并行执行
AllowParallel bool `json:"allow_parallel,omitempty"` // 是否允许并行执行无依赖的步骤
MaxParallelSteps int `json:"max_parallel_steps,omitempty"` // 最大并行步骤数
// 错误处理
StopOnError bool `json:"stop_on_error,omitempty"` // 出错时是否停止
ContinueOnError bool `json:"continue_on_error,omitempty"` // 出错时是否继续
// 超时控制
StepTimeoutMs int64 `json:"step_timeout_ms,omitempty"` // 单步超时(毫秒)
TotalTimeoutMs int64 `json:"total_timeout_ms,omitempty"` // 总超时(毫秒)
// 审批要求
RequireApproval bool `json:"require_approval,omitempty"` // 是否需要用户审批
AutoApprove bool `json:"auto_approve,omitempty"` // 是否自动审批
ApprovalTimeoutMs int64 `json:"approval_timeout_ms,omitempty"` // 审批超时(毫秒)
}
ExecutionOptions 执行选项
type ExecutionPlan ¶
type ExecutionPlan struct {
// 基础信息
ID string `json:"id"` // 计划唯一ID
TaskID string `json:"task_id,omitempty"` // 关联的任务ID
Name string `json:"name,omitempty"` // 计划名称
Description string `json:"description"` // 计划描述(自然语言)
// 步骤列表
Steps []Step `json:"steps"`
// 审批状态
UserApproved bool `json:"user_approved"` // 是否已用户审批
ApprovedAt *time.Time `json:"approved_at,omitempty"` // 审批时间
ApprovedBy string `json:"approved_by,omitempty"` // 审批人
RejectionNote string `json:"rejection_note,omitempty"` // 拒绝原因
// 执行状态
Status Status `json:"status"`
CurrentStep int `json:"current_step"` // 当前执行到的步骤索引
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
StartedAt *time.Time `json:"started_at,omitempty"`
CompletedAt *time.Time `json:"completed_at,omitempty"`
TotalDurationMs int64 `json:"total_duration_ms,omitempty"`
// 上下文信息
AgentID string `json:"agent_id,omitempty"` // 关联的 Agent ID
OrgID string `json:"org_id,omitempty"` // 组织 ID(多租户)
TenantID string `json:"tenant_id,omitempty"` // 租户 ID(多租户)
Metadata map[string]any `json:"metadata,omitempty"` // 自定义元数据
// 执行选项
Options *ExecutionOptions `json:"options,omitempty"`
}
ExecutionPlan 执行计划
func NewExecutionPlan ¶
func NewExecutionPlan(description string) *ExecutionPlan
NewExecutionPlan 创建新的执行计划
func (*ExecutionPlan) AddStep ¶
func (p *ExecutionPlan) AddStep(toolName, description string, params map[string]any) *Step
AddStep 添加步骤
func (*ExecutionPlan) GetCurrentStep ¶
func (p *ExecutionPlan) GetCurrentStep() *Step
GetCurrentStep 获取当前步骤
func (*ExecutionPlan) IsCompleted ¶
func (p *ExecutionPlan) IsCompleted() bool
IsCompleted 检查计划是否已完成
func (*ExecutionPlan) MarkStepCompleted ¶
func (p *ExecutionPlan) MarkStepCompleted(index int, result any)
MarkStepCompleted 标记步骤完成
func (*ExecutionPlan) MarkStepFailed ¶
func (p *ExecutionPlan) MarkStepFailed(index int, err error)
MarkStepFailed 标记步骤失败
func (*ExecutionPlan) MarkStepStarted ¶
func (p *ExecutionPlan) MarkStepStarted(index int)
MarkStepStarted 标记步骤开始
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor 执行计划执行器
func NewExecutor ¶
func NewExecutor(toolMap map[string]tools.Tool, opts ...ExecutorOption) *Executor
NewExecutor 创建执行计划执行器 toolMap: 工具名称到工具实例的映射
func (*Executor) Execute ¶
func (e *Executor) Execute(ctx context.Context, plan *ExecutionPlan, toolCtx *tools.ToolContext) error
Execute 执行计划
func (*Executor) Resume ¶
func (e *Executor) Resume(ctx context.Context, plan *ExecutionPlan, toolCtx *tools.ToolContext) error
Resume 恢复执行(从当前步骤继续)
type ExecutorOption ¶
type ExecutorOption func(*Executor)
ExecutorOption 执行器选项
func WithOnPlanComplete ¶
func WithOnPlanComplete(fn func(plan *ExecutionPlan)) ExecutorOption
WithOnPlanComplete 设置计划完成回调
func WithOnStepComplete ¶
func WithOnStepComplete(fn func(plan *ExecutionPlan, step *Step)) ExecutorOption
WithOnStepComplete 设置步骤完成回调
func WithOnStepFailed ¶
func WithOnStepFailed(fn func(plan *ExecutionPlan, step *Step, err error)) ExecutorOption
WithOnStepFailed 设置步骤失败回调
func WithOnStepStart ¶
func WithOnStepStart(fn func(plan *ExecutionPlan, step *Step)) ExecutorOption
WithOnStepStart 设置步骤开始回调
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator 执行计划生成器 使用 LLM 根据用户请求生成执行计划
func NewGenerator ¶
func NewGenerator(prov provider.Provider, toolMap map[string]tools.Tool, opts ...GeneratorOption) *Generator
NewGenerator 创建执行计划生成器 toolMap: 工具名称到工具实例的映射
func (*Generator) Generate ¶
func (g *Generator) Generate(ctx context.Context, req *PlanRequest) (*ExecutionPlan, error)
Generate 生成执行计划
func (*Generator) ValidatePlan ¶
func (g *Generator) ValidatePlan(plan *ExecutionPlan) []error
ValidatePlan 验证执行计划
type PlanRequest ¶
type PlanRequest struct {
// UserRequest 用户的原始请求
UserRequest string
// Context 附加上下文信息(可选)
Context string
// AvailableTools 可用工具列表(如果为空,使用注册表中所有工具)
AvailableTools []string
// Options 执行选项(可选)
Options *ExecutionOptions
// Metadata 自定义元数据
Metadata map[string]any
}
PlanRequest 计划生成请求
type PlanSummary ¶
type PlanSummary struct {
ID string `json:"id"`
Description string `json:"description"`
Status Status `json:"status"`
TotalSteps int `json:"total_steps"`
Completed int `json:"completed"`
Failed int `json:"failed"`
Pending int `json:"pending"`
Running int `json:"running"`
Progress float64 `json:"progress"` // 完成百分比
}
PlanSummary 计划摘要
type Status ¶
type Status string
Status 执行计划状态
const ( StatusDraft Status = "draft" // 草稿状态 StatusPendingApproval Status = "pending_approval" // 等待用户审批 StatusApproved Status = "approved" // 已审批,准备执行 StatusExecuting Status = "executing" // 执行中 StatusCompleted Status = "completed" // 执行完成 StatusFailed Status = "failed" // 执行失败 StatusCancelled Status = "canceled" // 已取消 StatusPartial Status = "partial" // 部分完成 )
type Step ¶
type Step struct {
// 基础信息
ID string `json:"id"` // 步骤唯一ID
Index int `json:"index"` // 步骤序号(从0开始)
ToolName string `json:"tool_name"` // 要调用的工具名称
Description string `json:"description"` // 步骤描述(自然语言)
// 参数
Input string `json:"input,omitempty"` // 原始输入(LLM 生成的字符串)
Parameters map[string]any `json:"parameters,omitempty"` // 解析后的参数
// 执行状态
Status StepStatus `json:"status"`
Result any `json:"result,omitempty"` // 执行结果
Error string `json:"error,omitempty"` // 错误信息
StartedAt *time.Time `json:"started_at,omitempty"` // 开始时间
CompletedAt *time.Time `json:"completed_at,omitempty"` // 完成时间
DurationMs int64 `json:"duration_ms,omitempty"` // 执行耗时(毫秒)
// 依赖关系
DependsOn []string `json:"depends_on,omitempty"` // 依赖的步骤ID列表
// 重试信息
RetryCount int `json:"retry_count,omitempty"` // 已重试次数
MaxRetries int `json:"max_retries,omitempty"` // 最大重试次数
RetryDelayMs int `json:"retry_delay_ms,omitempty"` // 重试间隔(毫秒)
}
Step 执行计划中的单个步骤
type StepStatus ¶
type StepStatus string
StepStatus 步骤状态
const ( StepStatusPending StepStatus = "pending" // 待执行 StepStatusRunning StepStatus = "running" // 执行中 StepStatusCompleted StepStatus = "completed" // 执行完成 StepStatusFailed StepStatus = "failed" // 执行失败 StepStatusSkipped StepStatus = "skipped" // 已跳过 )
Click to show internal directories.
Click to hide internal directories.