()
| 653 | f"Send results via send_message to 'lead'.") |
| 654 | |
| 655 | def run(): |
| 656 | messages = [{"role": "user", "content": prompt}] |
| 657 | sub_tools = [ |
| 658 | {"name": "bash", "description": "Run a shell command.", |
| 659 | "input_schema": {"type": "object", |
| 660 | "properties": {"command": {"type": "string"}}, |
| 661 | "required": ["command"]}}, |
| 662 | {"name": "read_file", "description": "Read file contents.", |
| 663 | "input_schema": {"type": "object", |
| 664 | "properties": {"path": {"type": "string"}}, |
| 665 | "required": ["path"]}}, |
| 666 | {"name": "write_file", "description": "Write content to a file.", |
| 667 | "input_schema": {"type": "object", |
| 668 | "properties": {"path": {"type": "string"}, |
| 669 | "content": {"type": "string"}}, |
| 670 | "required": ["path", "content"]}}, |
| 671 | {"name": "send_message", |
| 672 | "description": "Send a message to another agent.", |
| 673 | "input_schema": {"type": "object", |
| 674 | "properties": {"to": {"type": "string"}, |
| 675 | "content": {"type": "string"}}, |
| 676 | "required": ["to", "content"]}}, |
| 677 | ] |
| 678 | sub_handlers = { |
| 679 | "bash": run_bash, "read_file": run_read, "write_file": run_write, |
| 680 | "send_message": lambda to, content: (BUS.send(name, to, content), |
| 681 | "Sent")[1], |
| 682 | } |
| 683 | |
| 684 | for _ in range(10): |
| 685 | inbox = BUS.read_inbox(name) |
| 686 | if inbox: |
| 687 | messages.append({"role": "user", |
| 688 | "content": f"<inbox>{json.dumps(inbox)}</inbox>"}) |
| 689 | try: |
| 690 | response = client.messages.create( |
| 691 | model=MODEL, system=system, messages=messages[-20:], |
| 692 | tools=sub_tools, max_tokens=8000) |
| 693 | except Exception: |
| 694 | break |
| 695 | messages.append({"role": "assistant", "content": response.content}) |
| 696 | if response.stop_reason != "tool_use": |
| 697 | break |
| 698 | results = [] |
| 699 | for block in response.content: |
| 700 | if block.type == "tool_use": |
| 701 | handler = sub_handlers.get(block.name) |
| 702 | output = handler(**block.input) if handler else "Unknown" |
| 703 | results.append({"type": "tool_result", |
| 704 | "tool_use_id": block.id, |
| 705 | "content": str(output)}) |
| 706 | messages.append({"role": "user", "content": results}) |
| 707 | |
| 708 | # Send final summary to Lead |
| 709 | summary = "Done." |
| 710 | for msg in reversed(messages): |
| 711 | if msg["role"] == "assistant" and isinstance(msg["content"], list): |
| 712 | for b in msg["content"]: |
nothing calls this directly
no test coverage detected