MCPcopy
hub / github.com/shareAI-lab/learn-claude-code / idle_poll

Function idle_poll

s19_mcp_plugin/code.py:404–432  ·  view source on GitHub ↗
(agent_name: str, messages: list,
              name: str, role: str)

Source from the content-addressed store, hash-verified

402
403
404def 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 ──

Callers 1

runFunction · 0.70

Calls 5

scan_unclaimed_tasksFunction · 0.70
claim_taskFunction · 0.70
read_inboxMethod · 0.45
getMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected