# n8n Workflow Connection Troubleshooting

## 🚨 **Issue: Nodes Not Connected**

The problem you're experiencing is common when testing n8n workflows. Here's how to fix it:

## 🔍 **Root Causes**

1. **Test Mode Execution** - n8n doesn't always follow connections in test mode
2. **Webhook URL Mismatch** - Your test URL doesn't match the workflow configuration
3. **Workflow Not Active** - The workflow needs to be activated to work properly

## ✅ **Solutions**

### **Solution 1: Use the Correct Webhook URL**

**Your test URL:** `http://localhost:5678/webhook-test/agent-task`  
**Correct URL:** `http://localhost:5678/webhook/agent-task`

**Fix in Postman:**
- Change URL to: `http://localhost:5678/webhook/agent-task`
- Keep the same POST method and JSON body

### **Solution 2: Activate the Workflow**

1. **In n8n interface:**
   - Make sure the workflow is **Active** (green toggle in top-right)
   - If not active, click the toggle to activate it

2. **Check webhook registration:**
   - Go to Settings → Webhooks
   - Verify `agent-task` webhook is registered

### **Solution 3: Test Properly**

**Instead of using test mode:**
1. **Activate the workflow** (green toggle)
2. **Use the webhook URL directly** in Postman
3. **Don't use the "Test" button** in n8n

## 🧪 **Correct Testing Method**

### **Step 1: Import and Activate**
1. Import `n8n_agent_system_flow_final.json`
2. **Activate the workflow** (green toggle)
3. Note the webhook URL: `http://localhost:5678/webhook/agent-task`

### **Step 2: Test with Postman**
```bash
POST http://localhost:5678/webhook/agent-task
Content-Type: application/json

{
  "task": "Build a mobile app"
}
```

### **Step 3: Test with curl**
```bash
curl -X POST http://localhost:5678/webhook/agent-task \
  -H "Content-Type: application/json" \
  -d '{"task": "Build a mobile app"}'
```

## 🔧 **Workflow Structure (Simplified)**

The final workflow has this structure:
```
Webhook → Validate Input → Normalize Input → Select Agents → Generate Responses → Create Final Response → Success Response
```

**All nodes are properly connected** and will execute in sequence when the workflow is active.

## 🚨 **Common Mistakes**

1. **Testing in n8n interface** - Use external tools instead
2. **Wrong webhook URL** - Must be `/webhook/agent-task` not `/webhook-test/agent-task`
3. **Workflow not activated** - Green toggle must be ON
4. **Using test mode** - Test mode doesn't follow connections properly

## ✅ **Verification Steps**

1. **Check workflow status:**
   - Should show "Active" in top-right corner
   - Should show green dot next to webhook node

2. **Check webhook registration:**
   - Go to Settings → Webhooks
   - Should see `agent-task` webhook listed

3. **Test with correct URL:**
   - Use `http://localhost:5678/webhook/agent-task`
   - Send POST request with JSON body

## 🎯 **Expected Response**

When working correctly, you should get:
```json
{
  "success": true,
  "task": "Build a mobile app",
  "agents_consulted": ["mobile-app-builder", "ui-designer"],
  "synthesized_plan": "# Executive Summary\n...",
  "individual_responses": [...],
  "execution_time": 1500
}
```

## 🔄 **If Still Not Working**

1. **Restart n8n:**
   ```bash
   docker-compose restart n8n
   ```

2. **Check logs:**
   ```bash
   docker-compose logs n8n
   ```

3. **Re-import workflow:**
   - Delete the current workflow
   - Import `n8n_agent_system_flow_final.json` again
   - Activate it

4. **Use simple workflow first:**
   - Import `n8n_agent_system_flow_simple.json`
   - Test with that first

## 📞 **Quick Fix Commands**

```bash
# Restart services
docker-compose restart

# Check if n8n is running
curl http://localhost:5678

# Test webhook
curl -X POST http://localhost:5678/webhook/agent-task \
  -H "Content-Type: application/json" \
  -d '{"task": "test"}'
```

---

**Remember:** Always activate the workflow and use the correct webhook URL for testing!
