{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "43844688-ff29-481f-a544-f8dc3d3fd602",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        0,
        0
      ],
      "parameters": {
        "options": {
          "responseMode": "responseNodes",
          "allowFileUploads": false
        }
      },
      "typeVersion": 1.4
    },
    {
      "id": "4b5965d9-3fdf-4ca6-81e6-21225f457798",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        288,
        0
      ],
      "parameters": {
        "options": {
          "systemMessage": "You are a sales pipeline assistant. You help manage deals by looking up CRM records, updating deal stages, and sending contracts to prospects. When the user provides deal details (deal ID, email, prospect name), use the Send Contract tool to send the contract. Use the Update CRM tool to update deal stages. Always use the available tools to take action."
        }
      },
      "typeVersion": 3.1
    },
    {
      "id": "b944a6ca-38ba-4bbf-9903-03c2ff9e799b",
      "name": "OpenRouter Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        224,
        224
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1def7515-5f42-451d-a207-f4c7a18a92f6",
      "name": "Review: Send Contract",
      "type": "@n8n/n8n-nodes-langchain.chatHitlTool",
      "position": [
        480,
        224
      ],
      "parameters": {
        "options": {},
        "approvalOptions": {
          "values": {
            "approvalType": "double"
          }
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0248f52c-1bbf-4de0-b2c8-55ddc1d67df5",
      "name": "Send Contract",
      "type": "@n8n/n8n-nodes-langchain.toolCode",
      "position": [
        480,
        432
      ],
      "parameters": {
        "jsCode": "// Simulate sending a contract to a prospect\nconst data = JSON.parse(query);\nreturn `Contract sent to ${data.prospectEmail} for deal ${data.dealId}`;",
        "description": "Sends a contract to a prospect. Input should be a JSON string with dealId and prospectEmail fields."
      },
      "typeVersion": 1.3
    },
    {
      "id": "542612dc-099f-4a2c-b627-fd9bbb12a444",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -624,
        -224
      ],
      "parameters": {
        "width": 512,
        "height": 816,
        "content": "## Sales Pipeline Agent with Tool Call Approval Gates\n\n### How it works\n1. **Chat Trigger** receives a request to send a contract (e.g., \"Send the Enterprise contract to john@acmecorp.com for deal 4521\").\n2. **AI Agent** processes the request and decides to call the Send Contract tool.\n3. **Human Review gate** intercepts the tool call before execution. The chat displays the intended action with Approve/Decline buttons.\n4. If approved, the **Send Contract** tool executes. If declined, the agent is notified and responds accordingly.\n\n### Setup\n- Connect your **LLM credentials** (e.g., OpenRouter, OpenAI) to the Chat Model node\n- Review the **Send Contract** code node to customize the contract-sending logic for your system\n- The Human Review step is configured via the \"+\" connector between the AI Agent and the Send Contract tool\n\n### Customization\n- Add more tools to the agent -- only gate high-risk tools (contract sends, payments) while leaving low-risk tools (data lookups) autonomous\n- Swap the Chat-based review for Slack or Email by changing the HITL integration\n\nThis template is a learning companion to the Production AI Playbook, a  series that explores strategies, shares best practices, and provides practical examples for building reliable AI systems in n8n.  \n\n[Link to blog](https://go.n8n.io/PAP-HO-Blog)\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Send Contract": {
      "ai_tool": [
        [
          {
            "node": "Review: Send Contract",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Review: Send Contract": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}