(ctx context.Context, input map[string]any, tc *tools.ToolContext)
| 257 | } |
| 258 | |
| 259 | func (t *TaskTool) Execute(ctx context.Context, input map[string]any, tc *tools.ToolContext) (any, error) { |
| 260 | description, ok := input["description"].(string) |
| 261 | if !ok { |
| 262 | return nil, errors.New("description must be a string") |
| 263 | } |
| 264 | |
| 265 | subagentType, ok := input["subagent_type"].(string) |
| 266 | if !ok { |
| 267 | return nil, errors.New("subagent_type must be a string") |
| 268 | } |
| 269 | |
| 270 | // 获取上下文(可选) |
| 271 | parentContext := make(map[string]any) |
| 272 | if contextData, ok := input["context"].(map[string]any); ok { |
| 273 | parentContext = contextData |
| 274 | } |
| 275 | |
| 276 | // 检查是否异步执行 |
| 277 | async := false |
| 278 | if asyncVal, ok := input["async"].(bool); ok { |
| 279 | async = asyncVal |
| 280 | } |
| 281 | |
| 282 | // 获取超时设置 |
| 283 | timeout := t.middleware.defaultTimeout |
| 284 | if timeoutVal, ok := input["timeout"].(float64); ok { |
| 285 | timeout = time.Duration(timeoutVal) * time.Second |
| 286 | } |
| 287 | |
| 288 | // 如果启用了管理器且请求异步执行 |
| 289 | if t.middleware.manager != nil && async { |
| 290 | return t.executeAsync(ctx, subagentType, description, parentContext, timeout) |
| 291 | } |
| 292 | |
| 293 | // 同步执行(原有逻辑) |
| 294 | return t.executeSync(ctx, subagentType, description, parentContext) |
| 295 | } |
| 296 | |
| 297 | // executeSync 同步执行子代理 |
| 298 | func (t *TaskTool) executeSync(ctx context.Context, subagentType, description string, parentContext map[string]any) (any, error) { |
nothing calls this directly
no test coverage detected