executeSync 同步执行子代理
(ctx context.Context, subagentType, description string, parentContext map[string]any)
| 296 | |
| 297 | // executeSync 同步执行子代理 |
| 298 | func (t *TaskTool) executeSync(ctx context.Context, subagentType, description string, parentContext map[string]any) (any, error) { |
| 299 | // 获取子代理 |
| 300 | subagent, err := t.middleware.GetSubAgent(subagentType) |
| 301 | if err != nil { |
| 302 | return map[string]any{ |
| 303 | "ok": false, |
| 304 | "error": fmt.Sprintf("failed to get subagent: %v", err), |
| 305 | }, nil |
| 306 | } |
| 307 | |
| 308 | saLog.Info(ctx, "delegating task", map[string]any{"subagent": subagentType, "description": description}) |
| 309 | |
| 310 | // 执行任务 |
| 311 | result, err := subagent.Execute(ctx, description, parentContext) |
| 312 | if err != nil { |
| 313 | return map[string]any{ |
| 314 | "ok": false, |
| 315 | "error": fmt.Sprintf("subagent execution failed: %v", err), |
| 316 | "subagent_type": subagentType, |
| 317 | }, nil |
| 318 | } |
| 319 | |
| 320 | saLog.Info(ctx, "subagent completed task", map[string]any{"subagent": subagentType}) |
| 321 | |
| 322 | return map[string]any{ |
| 323 | "ok": true, |
| 324 | "subagent_type": subagentType, |
| 325 | "result": result, |
| 326 | }, nil |
| 327 | } |
| 328 | |
| 329 | // executeAsync 异步执行子代理 |
| 330 | func (t *TaskTool) executeAsync(ctx context.Context, subagentType, description string, parentContext map[string]any, timeout time.Duration) (any, error) { |
no test coverage detected