The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"name": "Agent Task Handoff",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "agent-handoff",
"responseMode": "responseNode",
"options": {}
},
"id": "webhook-trigger",
"name": "Webhook - Handoff Request",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
250,
300
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "SELECT id, name, status, capabilities FROM agents WHERE id = '{{ $json.to_agent_id }}' LIMIT 1",
"options": {}
},
"id": "check-agent-availability",
"name": "Check Agent Availability",
"type": "n8n-nodes-base.postgres",
"typeVersion": 2.4,
"position": [
450,
300
],
"credentials": {
"postgres": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "agent-active",
"leftValue": "={{ $json.status }}",
"rightValue": "active",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "agent-available",
"name": "Is Agent Available?",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
650,
300
]
},
{
"parameters": {
"operation": "insert",
"schema": {
"value": "public"
},
"table": {
"value": "context_handovers"
},
"columns": {
"mappingMode": "defineBelow",
"value": {
"from_agent_id": "={{ $('Webhook - Handoff Request').item.json.from_agent_id }}",
"to_agent_id": "={{ $('Webhook - Handoff Request').item.json.to_agent_id }}",
"context": "={{ $('Webhook - Handoff Request').item.json.context }}",
"status": "pending",
"created_at": "={{ $now.toISO() }}"
}
},
"options": {}
},
"id": "create-handover",
"name": "Create Handover Record",
"type": "n8n-nodes-base.postgres",
"typeVersion": 2.4,
"position": [
850,
200
],
"credentials": {
"postgres": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"topic": "prime-spark/agent/handoff",
"message": "={{ JSON.stringify({\n handover_id: $json.id,\n from_agent: $('Webhook - Handoff Request').item.json.from_agent_id,\n to_agent: $('Webhook - Handoff Request').item.json.to_agent_id,\n context: $('Webhook - Handoff Request').item.json.context,\n timestamp: $now.toISO()\n}) }}",
"options": {}
},
"id": "notify-mqtt",
"name": "Notify via MQTT",
"type": "n8n-nodes-base.mqtt",
"typeVersion": 1,
"position": [
1050,
200
],
"credentials": {
"mqtt": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"operation": "insert",
"schema": {
"value": "public"
},
"table": {
"value": "infrastructure_events"
},
"columns": {
"mappingMode": "defineBelow",
"value": {
"event_type": "agent.handoff.created",
"category": "agent",
"severity": "info",
"node": "orchestrator",
"details": "={{ JSON.stringify({\n handover_id: $('Create Handover Record').item.json.id,\n from_agent: $('Webhook - Handoff Request').item.json.from_agent_id,\n to_agent: $('Webhook - Handoff Request').item.json.to_agent_id\n}) }}"
}
}
},
"id": "log-event",
"name": "Log Infrastructure Event",
"type": "n8n-nodes-base.postgres",
"typeVersion": 2.4,
"position": [
1250,
200
],
"credentials": {
"postgres": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ JSON.stringify({\n success: true,\n handover_id: $('Create Handover Record').item.json.id,\n status: 'pending',\n message: 'Handoff request created successfully'\n}) }}",
"options": {}
},
"id": "success-response",
"name": "Success Response",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [
1450,
200
]
},
{
"parameters": {
"respondWith": "json",
"responseCode": 400,
"responseBody": "={{ JSON.stringify({\n success: false,\n error: 'Agent not available',\n agent_status: $json.status\n}) }}",
"options": {}
},
"id": "error-response",
"name": "Agent Unavailable Response",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [
850,
400
]
}
],
"connections": {
"Webhook - Handoff Request": {
"main": [
[
{
"node": "Check Agent Availability",
"type": "main",
"index": 0
}
]
]
},
"Check Agent Availability": {
"main": [
[
{
"node": "Is Agent Available?",
"type": "main",
"index": 0
}
]
]
},
"Is Agent Available?": {
"main": [
[
{
"node": "Create Handover Record",
"type": "main",
"index": 0
}
],
[
{
"node": "Agent Unavailable Response",
"type": "main",
"index": 0
}
]
]
},
"Create Handover Record": {
"main": [
[
{
"node": "Notify via MQTT",
"type": "main",
"index": 0
}
]
]
},
"Notify via MQTT": {
"main": [
[
{
"node": "Log Infrastructure Event",
"type": "main",
"index": 0
}
]
]
},
"Log Infrastructure Event": {
"main": [
[
{
"node": "Success Response",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"tags": [
{
"name": "agent",
"id": "agent-tag"
},
{
"name": "orchestration",
"id": "orchestration-tag"
},
{
"name": "prime-spark",
"id": "prime-spark-tag"
}
],
"triggerCount": 1,
"updatedAt": "2025-11-25T20:00:00.000Z",
"versionId": "1"
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
mqttpostgres
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
Agent Task Handoff. Uses postgres, mqtt, respondToWebhook. Webhook trigger; 8 nodes.
Source: https://github.com/Jupdefi/prime-spark-ai-cc/blob/f575913d8b879cdde5d000b21e725317c8ea64eb/n8n-workflows/1-agent-task-handoff.json — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
Jigsaw API key for image processing, I use this as a gatekeeper/second pair of eyes. LINK to their website https://jigsawstack.com/ SECOND A postgress DATABASE (I use Supabase) LlamaCloud for the pars
W1 - IN WhatsApp Adapter (Secure + Fast ACK). Uses postgres, redis, httpRequest. Webhook trigger; 48 nodes.
W2 - IN Instagram Adapter (Secure). Uses postgres, httpRequest. Webhook trigger; 28 nodes.
W3 - IN Messenger Adapter (Secure). Uses postgres, httpRequest. Webhook trigger; 28 nodes.
Engagement Tracking Workflow. Uses postgres, httpRequest. Webhook trigger; 22 nodes.