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

Method StopSubagent

pkg/tools/builtin/subagent_manager.go:231–264  ·  view source on GitHub ↗

StopSubagent 停止子代理

(taskID string)

Source from the content-addressed store, hash-verified

229
230// StopSubagent 停止子代理
231func (sm *FileSubagentManager) StopSubagent(taskID string) error {
232 sm.mu.Lock()
233 defer sm.mu.Unlock()
234
235 instance, exists := sm.agents[taskID]
236 if !exists {
237 return fmt.Errorf("subagent not found: %s", taskID)
238 }
239
240 if instance.Status != "running" {
241 return fmt.Errorf("subagent is not running, current status: %s", instance.Status)
242 }
243
244 // 发送终止信号
245 if instance.PID > 0 {
246 proc, err := os.FindProcess(instance.PID)
247 if err == nil {
248 _ = proc.Signal(os.Interrupt) // 发送SIGINT信号
249 }
250 }
251
252 // 等待进程退出
253 time.Sleep(2 * time.Second)
254
255 // 更新状态
256 now := time.Now()
257 instance.Status = "stopped"
258 instance.EndTime = &now
259 instance.Duration = now.Sub(instance.StartTime)
260 instance.LastUpdate = now
261 _ = sm.saveSubagent(instance)
262
263 return nil
264}
265
266// ListSubagents 列出所有子代理
267func (sm *FileSubagentManager) ListSubagents() ([]*SubagentInstance, error) {

Callers 1

CleanupSubagentMethod · 0.95

Calls 1

saveSubagentMethod · 0.95

Tested by

no test coverage detected