(agent_name: str, messages: list,
name: str, role: str)
| 402 | |
| 403 | |
| 404 | def idle_poll(agent_name: str, messages: list, |
| 405 | name: str, role: str) -> str: |
| 406 | for _ in range(IDLE_TIMEOUT // IDLE_POLL_INTERVAL): |
| 407 | time.sleep(IDLE_POLL_INTERVAL) |
| 408 | inbox = BUS.read_inbox(agent_name) |
| 409 | if inbox: |
| 410 | for msg in inbox: |
| 411 | if msg.get("type") == "shutdown_request": |
| 412 | req_id = msg.get("metadata", {}).get("request_id", "") |
| 413 | BUS.send(name, "lead", "Shutting down.", |
| 414 | "shutdown_response", |
| 415 | {"request_id": req_id, "approve": True}) |
| 416 | return "shutdown" |
| 417 | messages.append({"role": "user", |
| 418 | "content": "<inbox>" + json.dumps(inbox) + "</inbox>"}) |
| 419 | return "work" |
| 420 | unclaimed = scan_unclaimed_tasks() |
| 421 | if unclaimed: |
| 422 | task_data = unclaimed[0] |
| 423 | result = claim_task(task_data["id"], agent_name) |
| 424 | if "Claimed" in result: |
| 425 | wt_info = "" |
| 426 | if task_data.get("worktree"): |
| 427 | wt_info = f"\nWork directory: {WORKTREES_DIR / task_data['worktree']}" |
| 428 | messages.append({"role": "user", |
| 429 | "content": f"<auto-claimed>Task {task_data['id']}: " |
| 430 | f"{task_data['subject']}{wt_info}</auto-claimed>"}) |
| 431 | return "work" |
| 432 | return "timeout" |
| 433 | |
| 434 | |
| 435 | # ── Teammate Thread ── |
no test coverage detected