{
  "name": "Local Ollama AI Agent Chatbot",
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "id": "chat-1",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.4,
      "position": [
        -600,
        0
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.chatInput }}",
        "options": {
          "systemMessage": "You are a multilingual customer support AI agent. Reply in the same language as the user. Use tools when needed. Keep replies short, polite, and business-friendly."
        }
      },
      "id": "agent-1",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        -260,
        0
      ]
    },
    {
      "parameters": {
        "model": "llama3.2:latest",
        "options": {
          "temperature": 0.2
        }
      },
      "id": "model-1",
      "name": "Ollama Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "position": [
        -460,
        260
      ]
    },
    {
      "parameters": {
        "contextWindowLength": 10
      },
      "id": "memory-1",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        -260,
        260
      ]
    },
    {
      "parameters": {
        "description": "Lookup product pricing or quotation guidance.",
        "jsCode": "return JSON.stringify({ found: false, message: 'Replace with your own price lookup logic.' });"
      },
      "id": "tool-1",
      "name": "price_lookup",
      "type": "@n8n/n8n-nodes-langchain.toolCode",
      "typeVersion": 1.2,
      "position": [
        -40,
        260
      ]
    },
    {
      "parameters": {
        "description": "Lookup order status details.",
        "jsCode": "return JSON.stringify({ found: false, message: 'Replace with your own order status lookup logic.' });"
      },
      "id": "tool-2",
      "name": "order_status_lookup",
      "type": "@n8n/n8n-nodes-langchain.toolCode",
      "typeVersion": 1.2,
      "position": [
        180,
        260
      ]
    },
    {
      "parameters": {
        "description": "Use when the user requests human or sales support.",
        "jsCode": "return JSON.stringify({ handoff: true, message: 'Replace with your own sales handoff process.' });"
      },
      "id": "tool-3",
      "name": "sales_handoff",
      "type": "@n8n/n8n-nodes-langchain.toolCode",
      "typeVersion": 1.2,
      "position": [
        400,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const item = $input.first().json;\nlet reply = item.output || item.text || item.response || item.message?.content || '';\nreply = String(reply || '').replace(/<think>[\\s\\S]*?<\\/think>/gi, '').trim();\nreturn [{ json: { output: reply || 'Sorry, I could not generate a reply. Please try again.' } }];"
      },
      "id": "code-1",
      "name": "Format Chat Output",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        80,
        0
      ]
    }
  ],
  "connections": {
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Format Chat Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ollama Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "price_lookup": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "order_status_lookup": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "sales_handoff": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  }
}