# 🚀 Postman Guide for n8n Agent System

## 📋 Basic Setup

### **Request Configuration**
- **Method**: `POST`
- **URL**: `http://localhost:5678/webhook/agent-task-v2`
- **Headers**:
  ```
  Content-Type: application/json
  ```

## 🎯 Request Examples

### **1. Simple Message Input**
```json
{
  "message": "Help me build a mobile app for food delivery"
}
```

### **2. Task + Context Input**
```json
{
  "task": "Create a marketing strategy for a new product launch",
  "context": "SaaS startup, B2B market, 6-month timeline"
}
```

### **3. Full Structured Input**
```json
{
  "task": "Design a database schema for an e-commerce platform",
  "context": "High-traffic site, multiple payment methods, inventory management",
  "user_id": "developer_123"
}
```

### **4. Question Format**
```json
{
  "message": "How do I implement user authentication in a React app?"
}
```

### **5. Problem Statement**
```json
{
  "message": "Our website is loading slowly and users are complaining. What should I do?"
}
```

### **6. Project Planning**
```json
{
  "task": "Plan a complete digital transformation for a retail company",
  "context": "Traditional brick-and-mortar store, 50 employees, wants to go digital"
}
```

## 🔧 Postman Collection Setup

### **Step 1: Create New Collection**
1. Open Postman
2. Click "New" → "Collection"
3. Name it: "n8n Agent System"

### **Step 2: Create Requests**

#### **Request 1: Simple Message**
- **Name**: "Simple Message Test"
- **Method**: POST
- **URL**: `http://localhost:5678/webhook/agent-task-v2`
- **Headers**: `Content-Type: application/json`
- **Body** (raw JSON):
```json
{
  "message": "Help me build a mobile app for food delivery"
}
```

#### **Request 2: Task + Context**
- **Name**: "Task with Context"
- **Method**: POST
- **URL**: `http://localhost:5678/webhook/agent-task-v2`
- **Headers**: `Content-Type: application/json`
- **Body** (raw JSON):
```json
{
  "task": "Create a marketing strategy for a new product launch",
  "context": "SaaS startup, B2B market, 6-month timeline"
}
```

#### **Request 3: Question Format**
- **Name**: "Question Format"
- **Method**: POST
- **URL**: `http://localhost:5678/webhook/agent-task-v2`
- **Headers**: `Content-Type: application/json`
- **Body** (raw JSON):
```json
{
  "message": "How do I implement user authentication in a React app?"
}
```

## 📊 Expected Response Format

### **Successful Response**
```json
{
  "success": true,
  "task": "Help me build a mobile app for food delivery",
  "context": "",
  "user_id": "anonymous",
  "agents_consulted": ["mobile-developer", "ui-ux-designer", "product-manager"],
  "synthesized_plan": "## Executive Summary\n[Comprehensive plan with phases and priorities]",
  "individual_responses": [
    {
      "agent": "mobile-developer",
      "response": "[Detailed technical recommendations]"
    },
    {
      "agent": "ui-ux-designer", 
      "response": "[Design and user experience guidance]"
    },
    {
      "agent": "product-manager",
      "response": "[Product strategy and planning advice]"
    }
  ],
  "timestamp": "2025-10-04T00:30:00.000Z",
  "execution_time": 15000
}
```

### **Error Response**
```json
{
  "success": false,
  "error": "Invalid input: Task is required",
  "received_data": {
    "task": "Help me build a mobile app",
    "context": "",
    "user_id": "anonymous",
    "timestamp": 1759538010530
  },
  "suggestion": "Please provide a task or message in your request.",
  "timestamp": "2025-10-04T00:30:00.000Z"
}
```

## 🧪 Testing Scenarios

### **Scenario 1: Mobile App Development**
```json
{
  "message": "I want to build a mobile app for food delivery with real-time tracking"
}
```

### **Scenario 2: E-commerce Platform**
```json
{
  "task": "Build an e-commerce platform",
  "context": "B2C retail, multiple payment methods, inventory management, 3-month timeline"
}
```

### **Scenario 3: AI Integration**
```json
{
  "message": "How can I integrate AI chatbots into my customer service?"
}
```

### **Scenario 4: Marketing Strategy**
```json
{
  "task": "Create a digital marketing strategy",
  "context": "New SaaS product, B2B market, limited budget, 6-month campaign"
}
```

### **Scenario 5: Technical Problem**
```json
{
  "message": "My React app is slow and users are complaining about performance"
}
```

## 🔍 Troubleshooting

### **Common Issues**

1. **404 Error**: "Webhook not registered"
   - **Solution**: Make sure the workflow is imported and activated in n8n

2. **Validation Error**: "Task is required"
   - **Solution**: The workflow needs to be updated with the latest version

3. **Timeout Error**: Request takes too long
   - **Solution**: Increase timeout to 60+ seconds, check if Ollama is running

4. **Connection Error**: Cannot connect to localhost
   - **Solution**: Verify n8n is running on port 5678

### **Debug Steps**

1. **Check n8n Status**: http://localhost:5678
2. **Verify Workflow**: Make sure it's imported and active
3. **Test Ollama**: `curl http://localhost:11434/api/tags`
4. **Check Logs**: Look at n8n execution logs

## 📝 Tips for Testing

1. **Start Simple**: Begin with basic message inputs
2. **Add Context**: Include relevant context for better results
3. **Test Different Formats**: Try both `message` and `task` fields
4. **Check Response Time**: Note execution times for performance
5. **Review Agent Selection**: See which agents are chosen for different tasks

## 🎯 Success Indicators

- ✅ **Status Code**: 200
- ✅ **Success Field**: true
- ✅ **Agents Consulted**: Array of agent names
- ✅ **Synthesized Plan**: Comprehensive action plan
- ✅ **Individual Responses**: Detailed agent recommendations
- ✅ **Execution Time**: Reasonable response time (< 30 seconds)
