{
  "name": "cos3-document-qa",
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "id": "78f1377a-8913-4201-8d3a-657ff5ad51d9",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.1,
      "position": [
        240,
        380
      ],
      "webhookId": "1af5f194-a82a-488e-861d-ac6d0542f60e"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "14af397e-bec6-4b1f-8368-f55ea3bf5517",
              "name": "documentUrl",
              "value": "https://en.wikipedia.org/wiki/Large_language_model",
              "type": "string"
            }
          ]
        }
      },
      "id": "ede3b173-e6a6-464b-b1d5-4aaa6cd04230",
      "name": "Document URL",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        460,
        380
      ]
    },
    {
      "parameters": {
        "url": "={{ $json.documentUrl }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "text"
            }
          }
        }
      },
      "id": "e76528d6-c82a-457e-be03-ad6f348860dc",
      "name": "Fetch Document",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        680,
        380
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "b998a8b1-f225-475c-9a46-c6e3f1017a0b",
              "name": "documentContent",
              "value": "={{ $json.data.substring(0, 12000) }}",
              "type": "string"
            },
            {
              "id": "2226764a-a5dc-42bc-ae0d-1fa25a962db7",
              "name": "userQuestion",
              "value": "={{ $('When chat message received').first().json.chatInput }}",
              "type": "string"
            }
          ]
        }
      },
      "id": "2758b418-ce9b-416f-b306-5905e65fa475",
      "name": "Prepare Context",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        900,
        380
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.userQuestion }}",
        "options": {
          "systemMessage": "You are a research assistant. You have been given the following document.\n\nDOCUMENT:\n{{ $json.documentContent }}\n\nAnswer based ONLY on the document. Always quote the relevant passage. If the answer is not in the document, say so."
        }
      },
      "id": "1c6cf3a8-3f08-4b6f-992d-3e77cab394ec",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        1120,
        380
      ]
    },
    {
      "parameters": {
        "model": "llama-3.3-70b-versatile",
        "options": {
          "temperature": 0.2
        }
      },
      "id": "71c08340-5624-4a7d-881b-0c2801236f41",
      "name": "Groq",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "typeVersion": 1,
      "position": [
        1120,
        560
      ],
      "credentials": {
        "groqApi": {
          "id": "groq-shared-cred",
          "name": "Groq (shared, students)"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('When chat message received').first().json.sessionId }}",
        "contextWindowLength": 8
      },
      "id": "71087254-c706-4118-b200-970ffad76795",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        1320,
        560
      ]
    },
    {
      "parameters": {
        "content": "## Session 03 — AI that reads your documents\n\n**To use your own document:**\nEdit the **Document URL** node and paste any URL — a Wikipedia page, a research paper, or any public webpage.\n\nThe workflow fetches the page and gives the first ~12,000 characters to the AI as context.\n\n**Session key:** already set correctly — each browser tab gets its own conversation memory.",
        "height": 220,
        "width": 400
      },
      "id": "13b924cd-dfff-43c7-9595-ad836664ae24",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        240,
        120
      ]
    }
  ],
  "connections": {
    "When chat message received": {
      "main": [
        [
          {
            "node": "Document URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Document URL": {
      "main": [
        [
          {
            "node": "Fetch Document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Document": {
      "main": [
        [
          {
            "node": "Prepare Context",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Context": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}