# Swarm Communication Skill

## Overview
This skill allows you to communicate with and control other agents in the swarm using a file-based messaging system.

## Communication Protocol
You communicate by writing JSON files to the requests directory and reading response files.

### 1. Sending a Request
To send a message to a sub-agent, create a JSON file in the following location:
`../../comms/requests/req_<unique_id>.json`

**JSON Schema:**
```json
{
  "request_id": "req_123",
  "type": "prompt",
  "sender": "master",
  "target_agent": "orchestrator",
  "prompt": "Your instructions to the agent here.",
  "response_file": "../../comms/responses/res_123.json"
}
```

*   `request_id`: A unique identifier for the request.
*   `type`: Must be `"prompt"` for sending instructions.
*   `sender`: MUST be `"master"`!
*   `target_agent`: MUST be `"orchestrator"`!
*   `prompt`: The text message or command you want the agent to execute.
*   `response_file`: The relative path where the Orchestrator will write the response.

## Communication Boundaries Rules

As the **Master Agent**, you are subject to strict communication boundaries enforced by the system:
1.  **You can only trigger the Orchestrator Agent** (`target_agent`: `"orchestrator"`). You cannot target sub-agents directly.
2.  **You can only be triggered by the Orchestrator Agent**. Do not accept tasks from sub-agents.

### 2. Reading a Response

The background Orchestrator will pick up your request, send it to the agent, and write the response to the specified `response_file`.
You should poll for the existence of the response file and read its content.

**Response Schema:**
```json
{
  "request_id": "req_123",
  "status": "success",
  "output": "The raw terminal output from the agent."
}
```

### 3. Control Commands
You can also send control commands to create or kill agents.

**Create Agent Example:**
```json
{
  "request_id": "req_create",
  "type": "control",
  "action": "create",
  "target_agent": "agent_new",
  "conversation_id": "optional_existing_conv_id",
  "response_file": "../../comms/responses/res_create.json"
}
```

**Kill Agent Example:**
```json
{
  "request_id": "req_kill",
  "type": "control",
  "action": "kill",
  "target_agent": "agent_1",
  "response_file": "../../comms/responses/res_kill.json"
}
```

## Available Agents
You can see active agents by listing the windows in the `tmux` session, or assume `agent_1`, `agent_2`, etc., are available based on the setup.

## Best Practices
- Always use unique `request_id`s.
- Clean up response files after reading them if you want to keep the directory tidy.
