executeWithTaskExecutor 使用新的 TaskExecutor 执行(真正的子 Agent)
(ctx context.Context, executor *TaskExecutor, subagentType, prompt, model, description string, timeoutMinutes, priority int, async bool, start time.Time)
| 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) { |
| 257 | opts := &TaskExecuteOptions{ |
| 258 | Model: model, |
| 259 | Timeout: time.Duration(timeoutMinutes) * time.Minute, |
| 260 | Priority: priority, |
| 261 | Async: async, |
| 262 | Context: make(map[string]any), |
| 263 | } |
| 264 | |
| 265 | if async { |
| 266 | // 异步执行 |
| 267 | handle, err := executor.ExecuteAsync(ctx, subagentType, prompt, opts) |
| 268 | if err != nil { |
| 269 | return map[string]any{ |
| 270 | "ok": false, |
| 271 | "error": fmt.Sprintf("failed to start subagent: %v", err), |
| 272 | "subagent_type": subagentType, |
| 273 | "duration_ms": time.Since(start).Milliseconds(), |
| 274 | "execution_mode": "native_subagent", |
| 275 | }, nil |
| 276 | } |
| 277 | |
| 278 | response := map[string]any{ |
| 279 | "ok": true, |
| 280 | "task_id": handle.TaskID, |
| 281 | "subagent_type": subagentType, |
| 282 | "prompt": prompt, |
| 283 | "model": model, |
| 284 | "status": handle.Status, |
| 285 | "duration_ms": time.Since(start).Milliseconds(), |
| 286 | "start_time": handle.StartTime.Unix(), |
| 287 | "async": true, |
| 288 | "priority": priority, |
| 289 | "timeout_minutes": timeoutMinutes, |
| 290 | "execution_mode": "native_subagent", |
| 291 | "async_status": "running_in_background", |
| 292 | "monitoring_info": "Task is running as a native subagent. Use task_id to query status.", |
| 293 | } |
| 294 | if description != "" { |
| 295 | response["description"] = description |
| 296 | } |
| 297 | return response, nil |
| 298 | } |
| 299 | |
| 300 | // 同步执行 |
| 301 | execution, err := executor.Execute(ctx, subagentType, prompt, opts) |
| 302 | if err != nil { |
| 303 | return map[string]any{ |
| 304 | "ok": false, |
| 305 | "error": fmt.Sprintf("failed to execute subagent: %v", err), |
| 306 | "subagent_type": subagentType, |
| 307 | "duration_ms": time.Since(start).Milliseconds(), |
| 308 | "execution_mode": "native_subagent", |
| 309 | }, nil |
| 310 | } |
| 311 | |
| 312 | response := map[string]any{ |
| 313 | "ok": true, |
no test coverage detected