NewExecutionPlanManager 创建执行计划管理器
(agent *Agent)
| 49 | |
| 50 | // NewExecutionPlanManager 创建执行计划管理器 |
| 51 | func NewExecutionPlanManager(agent *Agent) *ExecutionPlanManager { |
| 52 | // 创建生成器和执行器 |
| 53 | generator := executionplan.NewGenerator(agent.provider, agent.toolMap) |
| 54 | executor := executionplan.NewExecutor( |
| 55 | agent.toolMap, |
| 56 | executionplan.WithOnStepStart(func(plan *executionplan.ExecutionPlan, step *executionplan.Step) { |
| 57 | agentLog.Debug(context.Background(), "execution plan step started", map[string]any{ |
| 58 | "plan_id": plan.ID, |
| 59 | "step_index": step.Index, |
| 60 | "step_id": step.ID, |
| 61 | "tool_name": step.ToolName, |
| 62 | "description": step.Description, |
| 63 | }) |
| 64 | }), |
| 65 | executionplan.WithOnStepComplete(func(plan *executionplan.ExecutionPlan, step *executionplan.Step) { |
| 66 | agentLog.Debug(context.Background(), "execution plan step completed", map[string]any{ |
| 67 | "plan_id": plan.ID, |
| 68 | "step_index": step.Index, |
| 69 | "step_id": step.ID, |
| 70 | "duration_ms": step.DurationMs, |
| 71 | }) |
| 72 | }), |
| 73 | executionplan.WithOnStepFailed(func(plan *executionplan.ExecutionPlan, step *executionplan.Step, err error) { |
| 74 | agentLog.Warn(context.Background(), "execution plan step failed", map[string]any{ |
| 75 | "plan_id": plan.ID, |
| 76 | "step_index": step.Index, |
| 77 | "step_id": step.ID, |
| 78 | "error": err.Error(), |
| 79 | }) |
| 80 | }), |
| 81 | ) |
| 82 | |
| 83 | return &ExecutionPlanManager{ |
| 84 | agent: agent, |
| 85 | generator: generator, |
| 86 | executor: executor, |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | // SetCallbacks 设置回调函数 |
| 91 | func (m *ExecutionPlanManager) SetCallbacks( |
no test coverage detected