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

Method Execute

pkg/middleware/subagent.go:259–295  ·  view source on GitHub ↗
(ctx context.Context, input map[string]any, tc *tools.ToolContext)

Source from the content-addressed store, hash-verified

257}
258
259func (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 同步执行子代理
298func (t *TaskTool) executeSync(ctx context.Context, subagentType, description string, parentContext map[string]any) (any, error) {

Callers

nothing calls this directly

Calls 3

executeAsyncMethod · 0.95
executeSyncMethod · 0.95
DurationMethod · 0.45

Tested by

no test coverage detected