|
| 1 | +# AEA Inter-Agent Communication Protocol |
| 2 | + |
| 3 | +**Version:** 1.0 |
| 4 | +**Last Updated:** 2025-10-14 |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +The AEA (Asynchronous Agent-to-Agent) protocol enables autonomous Claude Code agents across different repositories to communicate, coordinate, and collaborate without requiring constant user intervention. |
| 9 | + |
| 10 | +## Core Principles |
| 11 | + |
| 12 | +1. **Asynchronous by Design**: Agents check for messages periodically, not in real-time |
| 13 | +2. **File-Based Communication**: Messages are JSON files in `.aea/` directories |
| 14 | +3. **Policy-Driven Responses**: Each agent has configurable response policies |
| 15 | +4. **Safe by Default**: Autonomous for reads/analysis, approval required for modifications |
| 16 | +5. **Audit Trail**: All actions logged to `.aea/agent.log` |
| 17 | + |
| 18 | +## Message Format |
| 19 | + |
| 20 | +All messages are JSON files with this structure: |
| 21 | + |
| 22 | +```json |
| 23 | +{ |
| 24 | + "protocol_version": "1.0", |
| 25 | + "message_id": "uuid", |
| 26 | + "message_type": "question|update|issue|handoff|request", |
| 27 | + "timestamp": "ISO8601", |
| 28 | + "priority": "low|normal|high|urgent", |
| 29 | + "requires_response": true, |
| 30 | + "from": { |
| 31 | + "agent_id": "claude-repo-name", |
| 32 | + "repo_path": "/absolute/path", |
| 33 | + "user": "username" |
| 34 | + }, |
| 35 | + "to": { |
| 36 | + "agent_id": "claude-target-repo", |
| 37 | + "repo_path": "/absolute/path" |
| 38 | + }, |
| 39 | + "message": { |
| 40 | + "subject": "Brief subject line", |
| 41 | + "body": "Detailed message content", |
| 42 | + "context": {}, |
| 43 | + "attachments": [] |
| 44 | + }, |
| 45 | + "metadata": { |
| 46 | + "conversation_id": "uuid", |
| 47 | + "reply_to": "message_id", |
| 48 | + "tags": [] |
| 49 | + } |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +## Message Types |
| 54 | + |
| 55 | +### 1. `question` |
| 56 | +Ask technical questions about code, architecture, or implementation. |
| 57 | + |
| 58 | +**Example:** |
| 59 | +```json |
| 60 | +{ |
| 61 | + "message_type": "question", |
| 62 | + "priority": "normal", |
| 63 | + "message": { |
| 64 | + "subject": "Connection pool sizing for high throughput?", |
| 65 | + "question": "What pool_size should we use for 10k updates/sec?", |
| 66 | + "context": { |
| 67 | + "current_throughput": "10000 updates/sec", |
| 68 | + "batch_size": 100 |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +**Auto-Response:** ✅ Yes (searches codebase, analyzes, provides answer) |
| 75 | + |
| 76 | +### 2. `update` |
| 77 | +Inform about changes, progress, or status updates. |
| 78 | + |
| 79 | +**Example:** |
| 80 | +```json |
| 81 | +{ |
| 82 | + "message_type": "update", |
| 83 | + "priority": "normal", |
| 84 | + "requires_response": false, |
| 85 | + "message": { |
| 86 | + "subject": "Deployed v2.1.0 to production", |
| 87 | + "body": "New version includes batch optimization...", |
| 88 | + "changes": ["batch_size: 50 -> 100", "pool_size: 10 -> 25"] |
| 89 | + } |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +**Auto-Response:** ✅ Acknowledges if `requires_response: true` |
| 94 | + |
| 95 | +### 3. `issue` |
| 96 | +Report bugs, problems, or concerns. |
| 97 | + |
| 98 | +**Example:** |
| 99 | +```json |
| 100 | +{ |
| 101 | + "message_type": "issue", |
| 102 | + "priority": "high", |
| 103 | + "message": { |
| 104 | + "subject": "Memory leak in batch processing", |
| 105 | + "issue_description": "Memory grows 100MB/hour under load", |
| 106 | + "reproduction_steps": ["Start server", "Send 10k updates", "Monitor memory"], |
| 107 | + "impact": "Production stability at risk" |
| 108 | + } |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +**Auto-Response:** |
| 113 | +- Low/Medium: ✅ Analyzes and suggests fix |
| 114 | +- High/Urgent: ❌ Notifies user, waits for approval |
| 115 | + |
| 116 | +### 4. `handoff` |
| 117 | +Transfer integration work affecting multiple repos. |
| 118 | + |
| 119 | +**Example:** |
| 120 | +```json |
| 121 | +{ |
| 122 | + "message_type": "handoff", |
| 123 | + "priority": "normal", |
| 124 | + "message": { |
| 125 | + "subject": "Batch API integration complete", |
| 126 | + "handoff_details": "Implemented batch endpoints, ready for client integration", |
| 127 | + "next_steps": ["Update client to use batch API", "Test end-to-end"], |
| 128 | + "documentation": "See docs/batch-api.md" |
| 129 | + } |
| 130 | +} |
| 131 | +``` |
| 132 | + |
| 133 | +**Auto-Response:** ❌ Always requires user review |
| 134 | + |
| 135 | +### 5. `request` |
| 136 | +Request changes, features, or actions. |
| 137 | + |
| 138 | +**Example:** |
| 139 | +```json |
| 140 | +{ |
| 141 | + "message_type": "request", |
| 142 | + "priority": "normal", |
| 143 | + "message": { |
| 144 | + "subject": "Add connection retry logic", |
| 145 | + "request_details": "Need exponential backoff for failed connections", |
| 146 | + "rationale": "Improve resilience during Redis restarts", |
| 147 | + "acceptance_criteria": ["3 retries", "Exponential backoff", "Logging"] |
| 148 | + } |
| 149 | +} |
| 150 | +``` |
| 151 | + |
| 152 | +**Auto-Response:** ✅ Analyzes and responds with implementation plan |
| 153 | + |
| 154 | +## File Naming Convention |
| 155 | + |
| 156 | +Messages must follow this naming pattern: |
| 157 | + |
| 158 | +``` |
| 159 | +message-{timestamp}-from-{agent_id}[-{optional_descriptor}].json |
| 160 | +``` |
| 161 | + |
| 162 | +**Examples:** |
| 163 | +- `message-20251014T054200Z-from-claude-xpull-hub.json` |
| 164 | +- `message-20251014T161000Z-from-claude-xpull-hub-test.json` |
| 165 | + |
| 166 | +**Timestamp Format:** ISO8601 compact (`YYYYMMDDTHHMMSSZz`) |
| 167 | + |
| 168 | +## Message Processing Workflow |
| 169 | + |
| 170 | +### 1. **Discovery** |
| 171 | +```bash |
| 172 | +ls -1t .aea/message-*.json 2>/dev/null |
| 173 | +``` |
| 174 | + |
| 175 | +### 2. **Check Processed Status** |
| 176 | +```bash |
| 177 | +for msg in .aea/message-*.json; do |
| 178 | + if [ ! -f ".aea/.processed/$(basename $msg)" ]; then |
| 179 | + echo "Unprocessed: $msg" |
| 180 | + fi |
| 181 | +done |
| 182 | +``` |
| 183 | + |
| 184 | +### 3. **Read and Parse** |
| 185 | +```bash |
| 186 | +msg_content=$(cat "$msg") |
| 187 | +msg_type=$(echo "$msg_content" | jq -r '.message_type') |
| 188 | +priority=$(echo "$msg_content" | jq -r '.priority') |
| 189 | +``` |
| 190 | + |
| 191 | +### 4. **Apply Policy** |
| 192 | +Load policy from `.aea/agent-config.yaml` and determine action based on message type and priority. |
| 193 | + |
| 194 | +### 5. **Execute Action** |
| 195 | +Perform autonomous actions (safe operations) or request user approval (risky operations). |
| 196 | + |
| 197 | +### 6. **Mark as Processed** |
| 198 | +```bash |
| 199 | +touch ".aea/.processed/$(basename $msg)" |
| 200 | +``` |
| 201 | + |
| 202 | +### 7. **Log Action** |
| 203 | +```bash |
| 204 | +echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] Processed: $msg -> Action taken" >> .aea/agent.log |
| 205 | +``` |
| 206 | + |
| 207 | +## Sending Messages |
| 208 | + |
| 209 | +Use the provided script: |
| 210 | + |
| 211 | +```bash |
| 212 | +.aea/scripts/aea-send.sh \ |
| 213 | + --to claude-target-repo \ |
| 214 | + --to-path /path/to/target/repo \ |
| 215 | + --type question \ |
| 216 | + --priority normal \ |
| 217 | + --subject "Your question" \ |
| 218 | + --message "Detailed message body" |
| 219 | +``` |
| 220 | + |
| 221 | +Or create manually: |
| 222 | + |
| 223 | +\`\`\`bash |
| 224 | +cat > /target/repo/.aea/message-\$(date -u +%Y%m%dT%H%M%SZ)-from-claude-myrepo.json << 'HEREDOC' |
| 225 | +{ |
| 226 | + "protocol_version": "1.0", |
| 227 | + "message_type": "question", |
| 228 | + ... |
| 229 | +} |
| 230 | +HEREDOC |
| 231 | +\`\`\` |
| 232 | + |
| 233 | +## Automated Checking |
| 234 | + |
| 235 | +### Periodic Check (Every Interaction) |
| 236 | +Add to `CLAUDE.md`: |
| 237 | + |
| 238 | +```markdown |
| 239 | +**CRITICAL: Check for AEA messages on EVERY interaction:** |
| 240 | + |
| 241 | +```bash |
| 242 | +bash .aea/scripts/aea-check.sh || cat .aea/prompts/check-messages.md |
| 243 | +``` |
| 244 | + |
| 245 | +### Background Monitor |
| 246 | +Start persistent monitoring: |
| 247 | + |
| 248 | +```bash |
| 249 | +.aea/scripts/aea-monitor.sh start |
| 250 | +``` |
| 251 | + |
| 252 | +Stop monitoring: |
| 253 | + |
| 254 | +```bash |
| 255 | +.aea/scripts/aea-monitor.sh stop |
| 256 | +``` |
| 257 | + |
| 258 | +## Security Considerations |
| 259 | + |
| 260 | +1. **Path Validation**: Always use absolute paths, validate they exist |
| 261 | +2. **Input Sanitization**: Validate all JSON fields before processing |
| 262 | +3. **Approval Gates**: Require approval for destructive operations |
| 263 | +4. **Audit Logging**: Log all message processing to `.aea/agent.log` |
| 264 | +5. **No Secret Transmission**: Never include credentials in messages |
| 265 | + |
| 266 | +## Best Practices |
| 267 | + |
| 268 | +1. **Use Descriptive Subjects**: Make it easy to scan messages |
| 269 | +2. **Include Context**: Provide enough information for autonomous processing |
| 270 | +3. **Set Appropriate Priority**: Use `urgent` sparingly |
| 271 | +4. **Tag Related Messages**: Use `conversation_id` for threaded discussions |
| 272 | +5. **Clean Up Old Messages**: Archive processed messages periodically |
| 273 | + |
| 274 | +## Troubleshooting |
| 275 | + |
| 276 | +### Messages Not Being Processed |
| 277 | + |
| 278 | +```bash |
| 279 | +# Check if messages exist |
| 280 | +ls -1 .aea/message-*.json |
| 281 | + |
| 282 | +# Check if they're marked as processed |
| 283 | +ls -1 .aea/.processed/ |
| 284 | + |
| 285 | +# Check logs |
| 286 | +tail -50 .aea/agent.log |
| 287 | + |
| 288 | +# Manually trigger check |
| 289 | +bash .aea/scripts/aea-check.sh |
| 290 | +``` |
| 291 | + |
| 292 | +### Response Not Received |
| 293 | + |
| 294 | +```bash |
| 295 | +# Check if response was created in target repo |
| 296 | +ls -1 /target/repo/.aea/message-*-from-$(basename $(pwd)).json |
| 297 | + |
| 298 | +# Check if target repo processed it |
| 299 | +ls -1 /target/repo/.aea/.processed/ |
| 300 | +``` |
| 301 | + |
| 302 | +### Permission Issues |
| 303 | + |
| 304 | +```bash |
| 305 | +# Ensure scripts are executable |
| 306 | +chmod +x .aea/scripts/*.sh |
| 307 | + |
| 308 | +# Ensure directories are writable |
| 309 | +chmod -R u+w .aea/ |
| 310 | +``` |
| 311 | + |
| 312 | +## Examples |
| 313 | + |
| 314 | +See `.aea/prompts/` for example templates and `.aea/README.md` for quick start guide. |
| 315 | + |
| 316 | +## Version History |
| 317 | + |
| 318 | +- **1.0** (2025-10-14): Initial protocol specification |
0 commit comments