Dispatch incoming protocol messages by type. Returns True if teammate should stop.
(name: str, msg: dict, messages: list)
| 449 | f"Check inbox for protocol messages (shutdown_request, etc).") |
| 450 | |
| 451 | def handle_inbox_message(name: str, msg: dict, messages: list) -> bool: |
| 452 | """Dispatch incoming protocol messages by type. |
| 453 | Returns True if teammate should stop.""" |
| 454 | msg_type = msg.get("type", "message") |
| 455 | meta = msg.get("metadata", {}) |
| 456 | req_id = meta.get("request_id", "") |
| 457 | |
| 458 | if msg_type == "shutdown_request": |
| 459 | BUS.send(name, "lead", "Shutting down gracefully.", |
| 460 | "shutdown_response", |
| 461 | {"request_id": req_id, "approve": True}) |
| 462 | print(f" \033[35m[protocol] {name} approved shutdown " |
| 463 | f"({req_id})\033[0m") |
| 464 | return True # stop the loop |
| 465 | |
| 466 | if msg_type == "plan_approval_response": |
| 467 | approve = meta.get("approve", False) |
| 468 | if approve: |
| 469 | messages.append({"role": "user", |
| 470 | "content": f"[Plan approved] Proceed with the task."}) |
| 471 | else: |
| 472 | messages.append({"role": "user", |
| 473 | "content": f"[Plan rejected] Feedback: {msg['content']}"}) |
| 474 | |
| 475 | return False # continue |
| 476 | |
| 477 | def run(): |
| 478 | messages = [{"role": "user", "content": prompt}] |