executeAsync 异步执行子代理
(ctx context.Context, subagentType, description string, parentContext map[string]any, timeout time.Duration)
| 328 | |
| 329 | // executeAsync 异步执行子代理 |
| 330 | func (t *TaskTool) executeAsync(ctx context.Context, subagentType, description string, parentContext map[string]any, timeout time.Duration) (any, error) { |
| 331 | // 构建子代理配置 |
| 332 | config := &builtin.SubagentConfig{ |
| 333 | Type: subagentType, |
| 334 | Prompt: description, |
| 335 | Timeout: timeout, |
| 336 | ParentContext: parentContext, |
| 337 | Metadata: map[string]string{ |
| 338 | "subagent_type": subagentType, |
| 339 | "description": description, |
| 340 | }, |
| 341 | } |
| 342 | |
| 343 | // 启动子代理 |
| 344 | instance, err := t.middleware.manager.StartSubagent(ctx, config) |
| 345 | if err != nil { |
| 346 | return map[string]any{ |
| 347 | "ok": false, |
| 348 | "error": fmt.Sprintf("failed to start subagent: %v", err), |
| 349 | }, nil |
| 350 | } |
| 351 | |
| 352 | saLog.Info(ctx, "started async subagent", map[string]any{"subagent": subagentType, "task_id": instance.ID}) |
| 353 | |
| 354 | return map[string]any{ |
| 355 | "ok": true, |
| 356 | "task_id": instance.ID, |
| 357 | "subagent_type": subagentType, |
| 358 | "status": instance.Status, |
| 359 | "message": "SubAgent started in background. Use query_subagent to check status and get results.", |
| 360 | }, nil |
| 361 | } |
| 362 | |
| 363 | func (t *TaskTool) Prompt() string { |
| 364 | // 获取可用的子代理列表 |
no test coverage detected