runTask 启动任务
(ctx context.Context, input map[string]any)
| 218 | |
| 219 | // runTask 启动任务 |
| 220 | func (t *TaskTool) runTask(ctx context.Context, input map[string]any) (any, error) { |
| 221 | description := GetStringParam(input, "description", "") |
| 222 | subagentType := GetStringParam(input, "subagent_type", "") |
| 223 | prompt := GetStringParam(input, "prompt", "") |
| 224 | model := GetStringParam(input, "model", "") |
| 225 | timeoutMinutes := GetIntParam(input, "timeout_minutes", 30) |
| 226 | async := GetBoolParam(input, "async", true) |
| 227 | |
| 228 | if subagentType == "" { |
| 229 | return NewClaudeErrorResponse(errors.New("subagent_type is required for run action")), nil |
| 230 | } |
| 231 | if prompt == "" { |
| 232 | return NewClaudeErrorResponse(errors.New("prompt is required for run action")), nil |
| 233 | } |
| 234 | |
| 235 | // 验证子代理类型 |
| 236 | validSubagents := []string{"general-purpose", "Explore", "Plan"} |
| 237 | subagentValid := slices.Contains(validSubagents, subagentType) |
| 238 | if !subagentValid { |
| 239 | return NewClaudeErrorResponse( |
| 240 | fmt.Errorf("invalid subagent_type: %s", subagentType), |
| 241 | "支持的代理类型: general-purpose, Explore, Plan", |
| 242 | ), nil |
| 243 | } |
| 244 | |
| 245 | start := time.Now() |
| 246 | taskExecutor := GetGlobalTaskExecutor() |
| 247 | |
| 248 | if taskExecutor.executorFactory != nil { |
| 249 | return t.executeWithTaskExecutor(ctx, taskExecutor, subagentType, prompt, model, description, timeoutMinutes, 100, async, start) |
| 250 | } |
| 251 | |
| 252 | return t.executeWithSubagentManager(ctx, subagentType, prompt, model, description, "", timeoutMinutes, 100, async, start) |
| 253 | } |
| 254 | |
| 255 | // executeWithTaskExecutor 使用新的 TaskExecutor 执行(真正的子 Agent) |
| 256 | func (t *TaskTool) executeWithTaskExecutor(ctx context.Context, executor *TaskExecutor, subagentType, prompt, model, description string, timeoutMinutes, priority int, async bool, start time.Time) (any, error) { |
no test coverage detected