| 329 | } |
| 330 | |
| 331 | func (rt *AgentTaskRuntime) SendMessage(taskID, scopeID, prompt string) any { |
| 332 | rt.mu.Lock() |
| 333 | record := rt.records[taskID] |
| 334 | spec, ok := rt.workerSpecs[taskID] |
| 335 | if record == nil || record.ParentScopeID != scopeID || !ok { |
| 336 | rt.mu.Unlock() |
| 337 | return "Error: Worker is not reusable or has already terminated." |
| 338 | } |
| 339 | if !record.Reusable { |
| 340 | rt.mu.Unlock() |
| 341 | return "Error: Worker is not reusable or has already terminated." |
| 342 | } |
| 343 | if record.Status != "idle" { |
| 344 | rt.mu.Unlock() |
| 345 | return "Error: Worker is currently busy processing previous request." |
| 346 | } |
| 347 | rt.cancelIdleTTLLocked(taskID) |
| 348 | ctx, cancel := context.WithCancel(context.Background()) |
| 349 | rt.workers[taskID] = cancel |
| 350 | record.Status = "queued" |
| 351 | record.UpdatedAt = nowSeconds() |
| 352 | rt.workerSpecs[taskID] = spec |
| 353 | cp := *record |
| 354 | rt.mu.Unlock() |
| 355 | go rt.runWorker(ctx, taskID, prompt) |
| 356 | return &cp |
| 357 | } |
| 358 | |
| 359 | func (rt *AgentTaskRuntime) StopTask(taskID, scopeID string) any { |
| 360 | rt.mu.Lock() |