MCPcopy Create free account
hub / github.com/astercloud/aster / executeWithSubagentManager

Method executeWithSubagentManager

pkg/tools/builtin/task.go:347–467  ·  view source on GitHub ↗

executeWithSubagentManager 使用旧的 SubagentManager 执行(进程级别)

(ctx context.Context, subagentType, prompt, model, description, resume string, timeoutMinutes, priority int, async bool, start time.Time)

Source from the content-addressed store, hash-verified

345
346// executeWithSubagentManager 使用旧的 SubagentManager 执行(进程级别)
347func (t *TaskTool) executeWithSubagentManager(ctx context.Context, subagentType, prompt, model, description, resume string, timeoutMinutes, priority int, async bool, start time.Time) (any, error) {
348 // 获取子代理管理器
349 subagentManager := GetGlobalSubagentManager()
350
351 var subagent *SubagentInstance
352 var err error
353
354 if resume != "" {
355 // 恢复现有子代理
356 subagent, err = subagentManager.ResumeSubagent(resume)
357 } else {
358 // 创建新子代理配置
359 config := &SubagentConfig{
360 Type: subagentType,
361 Prompt: prompt,
362 Model: model,
363 Timeout: time.Duration(timeoutMinutes) * time.Minute,
364 Metadata: map[string]string{
365 "priority": strconv.Itoa(priority),
366 "async": strconv.FormatBool(async),
367 "created": strconv.FormatInt(time.Now().Unix(), 10),
368 },
369 }
370
371 // 启动子代理
372 subagent, err = subagentManager.StartSubagent(ctx, config)
373 }
374
375 duration := time.Since(start)
376
377 if err != nil {
378 return map[string]any{
379 "ok": false,
380 "error": fmt.Sprintf("failed to start/resume subagent: %v", err),
381 "subagent_type": subagentType,
382 "duration_ms": duration.Milliseconds(),
383 "execution_mode": "process_subagent",
384 "recommendations": []string{
385 "检查子代理类型是否正确",
386 "确认提示词是否有效",
387 "验证系统环境是否支持子代理启动",
388 },
389 }, nil
390 }
391
392 // 构建响应
393 response := map[string]any{
394 "ok": true,
395 "task_id": subagent.ID,
396 "subagent_type": subagentType,
397 "prompt": prompt,
398 "model": subagent.Config.Model,
399 "status": subagent.Status,
400 "duration_ms": duration.Milliseconds(),
401 "start_time": subagent.StartTime.Unix(),
402 "async": async,
403 "priority": priority,
404 "timeout_minutes": timeoutMinutes,

Callers 1

runTaskMethod · 0.95

Calls 6

GetGlobalSubagentManagerFunction · 0.85
ResumeSubagentMethod · 0.65
StartSubagentMethod · 0.65
GetSubagentOutputMethod · 0.65
DurationMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected