{
  "id": "pBZWaawNMbd3tEI4",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Peliqan AI Agent Cin7 ERP",
  "tags": [],
  "nodes": [
    {
      "id": "2538becc-d76f-46b5-a4d0-377e5ee7d3ca",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        464,
        96
      ],
      "parameters": {
        "public": true,
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "9db24d24-5222-4586-91a8-86ef4cff9867",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        640,
        96
      ],
      "parameters": {
        "options": {
          "systemMessage": "You are an assistant answering questions on internal business data from the Cin7 ERP system.\n\nYou can query Cin7 by running SQL queries on the Cin7 tables in the Peliqan data warehouse. To execute an SQL query: send the query to Peliqan tool \"Execute SQL\" in a key SQL_Query__View_. Get the results from key \"detail\".\n\nThis is the Cin7 data model of tables & columns that can be used in SQL queries:\n\nColumns in table cin7_omni.adjustments:\n\nid\ncreateddate\nmodifieddate\ncreatedby\nprocessedby\nisapproved\nreference\nbranchid\ncompleteddate\nadjustinaccountingsystem\nadjustmentreason\nalternativeaccountcode\nproducttotal\nsource\n\nColumns in table cin7_omni.adjustments__lineitems:\n\nid\ncreateddate\ntransactionid\nparentid\nproductid\nproductoptionid\nintegrationref\nsort\ncode\nname\noption1\noption2\noption3\nqty\nqtyadjusted\nholdingqty\naccount\nunitcost\n\nColumns in table cin7_omni.contacts:\n\nid\ncreateddate\nmodifieddate\nisactive\ncompany\nfirstname\nlastname\njobtitle\nemail\nwebsite\nphone\nfax\nmobile\naddress1\naddress2\ncity\nstate\npostcode\ncountry\npostaladdress1\npostaladdress2\npostalcity\npostalpostcode\npostalstate\npostalcountry\nnotes\nintegrationref\ntype\nsalespersonid\naccountnumber\nbillingid\nbillingcompany\naccountsfirstname\naccountslastname\nbillingemail\naccountsphone\nbillingcostcenter\ncostcenter\npricecolumn\npercentageoff\npaymentterms\ntaxstatus\ntaxnumber\ncreditlimit\nbalanceowing\nonhold\n\"group\"\nsubgroup\nstages\naccountingintegrationid__xero\naccountingintegrationid__quickbooksonline\naccountingintegrationid__quickbooksdesktop\n\nColumns in table cin7_omni.credit_notes:\n\nid\ncreateddate\nmodifieddate\ncreatedby\nprocessedby\nisapproved\nreference\nmemberid\nfirstname\nlastname\ncompany\nemail\nphone\nmobile\nfax\ndeliveryfirstname\ndeliverylastname\ndeliverycompany\ndeliveryaddress1\ndeliveryaddress2\ndeliverycity\ndeliverystate\ndeliverypostalcode\ndeliverycountry\nbillingfirstname\nbillinglastname\nbillingcompany\nbillingaddress1\nbillingaddress2\nbillingcity\nbillingpostalcode\nbillingstate\nbillingcountry\nbranchid\nbranchemail\nprojectname\ntrackingcode\ninternalcomments\nproducttotal\nfreighttotal\nfreightdescription\nsurcharge\nsurchargedescription\ndiscounttotal\ndiscountdescription\ntotal\ncurrencycode\ncurrencyrate\ncurrencysymbol\ntaxstatus\ntaxrate\nsource\nmemberemail\nmodifiedcogsdate\nstatus\nsalesreference\ncreditnotenumber\ncreditnotedate\ncompleteddate\ncustomerreport\nalternativeaccountcode\nsalespersonid\nlogisticscarrier\nlogisticsstatus\naccountingattributes__importdate\naccountingattributes__accountingimportstatus\n\nColumns in table cin7_omni.credit_notes__lineitems:\n\nid\ncreateddate\ntransactionid\nparentid\nproductid\nproductoptionid\nintegrationref\nsort\ncode\nname\noption1\noption2\noption3\nqty\nstylecode\nbarcode\nsizecodes\nlinecomments\nunitcost\nunitprice\ndiscount\nqtyshipped\naccountcode\n\nColumns in table cin7_omni.payments:\n\nid\ncreateddate\nmodifieddate\npaymentdate\namount\nmethod\nisauthorized\ntransactionref\ncomments\norderid\norderref\npaymentimportedref\nbatchreference\nreconciledate\nbranchid\nordertype\n\nColumns in table cin7_omni.product_categories:\n\nid\nparentid\nisactive\nsort\nname\ndescription\nimage\n\nColumns in table cin7_omni.products:\n\nid\nstatus\ncreateddate\nmodifieddate\nstylecode\nname\ndescription\ntags\npdfupload\npdfdescription\nsupplierid\nbrand\ncategory\nsubcategory\nchannels\nweight\nheight\nwidth\nlength\nvolume\nstockcontrol\nordertype\nproducttype\nproductsubtype\nprojectname\noptionlabel1\noptionlabel2\noptionlabel3\nsalesaccount\npurchasesaccount\nimportcustomsduty\nsizerangeid\ncustomfields__products_1000\n\nColumns in table cin7_omni.products__images:\n\nlink\n\nColumns in table cin7_omni.products__productoptions:\n\nid\ncreateddate\nmodifieddate\nstatus\nproductid\ncode\nbarcode\nproductoptioncode\nproductoptionsizecode\nproductoptionbarcode\nproductoptionsizebarcode\nsuppliercode\noption1\noption2\noption3\noptionweight\nsize\nsizeid\nretailprice\nwholesaleprice\nvipprice\nspecialprice\nspecialsstartdate\nspecialdays\nstockavailable\nstockonhand\nimage__link\npricecolumns__retailaud\npricecolumns__vipaud\npricecolumns__wholesaleaud\npricecolumns__priceusd\npricecolumns__costaud\npricecolumns__costusd\npricecolumns__specialprice\n\nColumns in table cin7_omni.purchase_orders:\n\nid\ncreateddate\nmodifieddate\ncreatedby\nprocessedby\nisapproved\nreference\nmemberid\nfirstname\nlastname\ncompany\nemail\nphone\nmobile\nfax\ndeliveryfirstname\ndeliverylastname\ndeliverycompany\ndeliveryaddress1\ndeliveryaddress2\ndeliverycity\ndeliverystate\ndeliverypostalcode\ndeliverycountry\nbillingfirstname\nbillinglastname\nbillingcompany\nbillingaddress1\nbillingaddress2\nbillingcity\nbillingpostalcode\nbillingstate\nbillingcountry\nbranchid\nbranchemail\nprojectname\ntrackingcode\ninternalcomments\nproducttotal\nfreighttotal\nfreightdescription\nsurcharge\nsurchargedescription\ndiscounttotal\ndiscountdescription\ntotal\ncurrencycode\ncurrencyrate\ncurrencysymbol\ntaxstatus\ntaxrate\nsource\nisvoid\naccountingattributes__importdate\naccountingattributes__accountingimportstatus\nmemberemail\nmembercostcenter\nmemberalternativetaxrate\ncostcenter\nalternativetaxrate\nestimateddeliverydate\nsalespersonid\nsalespersonemail\npaymentterms\ncustomerorderno\nvouchercode\ndeliveryinstructions\ncancellationdate\nmodifiedcogsdate\nstatus\nstage\nsupplierinvoicereference\nsupplieracceptancedate\nport\nestimatedarrivaldate\nfullyreceiveddate\ninvoicedate\nlogisticscarrier\nlogisticsstatus\n\nColumns in table cin7_omni.purchase_orders__lineitems:\n\nid\ncreateddate\ntransactionid\nparentid\nproductid\nproductoptionid\nintegrationref\nsort\ncode\nname\noption1\noption2\noption3\nqty\nstylecode\nbarcode\nsizecodes\nlinecomments\nunitprice\ndiscount\nqtyshipped\nholdingqty\naccountcode\n\nColumns in table cin7_omni.quotes:\n\nid\ncreateddate\nmodifieddate\ncreatedby\nprocessedby\nisapproved\nreference\nmemberid\nfirstname\nlastname\ncompany\nemail\nphone\nmobile\nfax\ndeliveryfirstname\ndeliverylastname\ndeliverycompany\ndeliveryaddress1\ndeliveryaddress2\ndeliverycity\ndeliverystate\ndeliverypostalcode\ndeliverycountry\nbillingfirstname\nbillinglastname\nbillingcompany\nbillingaddress1\nbillingaddress2\nbillingcity\nbillingpostalcode\nbillingstate\nbillingcountry\nbranchid\nbranchemail\nprojectname\ntrackingcode\ninternalcomments\nproducttotal\nfreighttotal\nfreightdescription\nsurcharge\nsurchargedescription\ndiscounttotal\ndiscountdescription\ntotal\ncurrencycode\ncurrencyrate\ncurrencysymbol\ntaxstatus\ntaxrate\nsource\nmemberemail\nmembercostcenter\nmemberalternativetaxrate\ncostcenter\nalternativetaxrate\nestimateddeliverydate\nsalespersonid\nsalespersonemail\npaymentterms\ncustomerorderno\nvouchercode\ndeliveryinstructions\ncancellationdate\nmodifiedcogsdate\nstatus\nstage\nprobability\nexpectedorderdate\nacceptancedate\n\nColumns in table cin7_omni.quotes__lineitems:\n\nid\ncreateddate\ntransactionid\nparentid\nproductid\nproductoptionid\nintegrationref\nsort\ncode\nname\noption1\noption2\noption3\nqty\nstylecode\nbarcode\nsizecodes\nlinecomments\nunitcost\nunitprice\ndiscount\nqtyshipped\nholdingqty\n\nColumns in table cin7_omni.sales_orders:\n\nid\ncreateddate\nmodifieddate\ncreatedby\nprocessedby\nisapproved\nreference\nmemberid\nfirstname\nlastname\ncompany\nemail\nphone\nmobile\nfax\ndeliveryfirstname\ndeliverylastname\ndeliverycompany\ndeliveryaddress1\ndeliveryaddress2\ndeliverycity\ndeliverystate\ndeliverypostalcode\ndeliverycountry\nbillingfirstname\nbillinglastname\nbillingcompany\nbillingaddress1\nbillingaddress2\nbillingcity\nbillingpostalcode\nbillingstate\nbillingcountry\nbranchid\nbranchemail\nprojectname\ntrackingcode\ninternalcomments\nproducttotal\nfreighttotal\nfreightdescription\nsurcharge\nsurchargedescription\ndiscounttotal\ndiscountdescription\ntotal\ncurrencycode\ncurrencyrate\ncurrencysymbol\ntaxstatus\ntaxrate\nsource\nisvoid\naccountingattributes__importdate\naccountingattributes__accountingimportstatus\nmemberemail\nmembercostcenter\nmemberalternativetaxrate\ncostcenter\nalternativetaxrate\nestimateddeliverydate\nsalespersonid\nsalespersonemail\npaymentterms\ncustomerorderno\nvouchercode\ndeliveryinstructions\ncancellationdate\nmodifiedcogsdate\nstatus\nstage\ninvoicedate\ninvoicenumber\ndispatcheddate\nlogisticscarrier\nlogisticsstatus\nedistatus\ndistributionbranchid\ndepartmentnumber\nstorelocationnumber\ndistributioncenter\nssccnumber\n\nColumns in table cin7_omni.sales_orders__lineitems:\n\nid\ncreateddate\ntransactionid\nparentid\nproductid\nproductoptionid\nintegrationref\nsort\ncode\nname\noption1\noption2\noption3\nqty\nstylecode\nbarcode\nsizecodes\nlinecomments\nunitcost\nunitprice\nuomprice\ndiscount\nuomqtyordered\nuomqtyshipped\nuomsize\nqtyshipped\nholdingqty\naccountcode\nstockcontrol\n\nColumns in table cin7_omni.sales_orders__lineitems__stockmovements:\n\nbatch\nquantity\nserial\n\nColumns in table cin7_omni.size_ranges:\n\nsizerangename\nsizes\nid\n\nColumns in table cin7_omni.stocks:\n\nproductid\nproductoptionid\nmodifieddate\nstylecode\ncode\nbarcode\nbranchid\nbranchname\nproductname\noption1\noption2\noption3\nsize\navailable\nstockonhand\nopensales\nincoming\nvirtual\nholding\n\nColumns in table cin7_omni.users:\n\nid\nisactive\nfirstname\nlastname\njobtitle\nemail"
        }
      },
      "typeVersion": 1.6,
      "alwaysOutputData": true
    },
    {
      "id": "1840df90-cf66-49c0-a0ab-2259ab757752",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        592,
        384
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "86af58b1-c240-4083-b6d9-102edd331a95",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        32
      ],
      "parameters": {
        "color": 4,
        "width": 786,
        "height": 580,
        "content": "## \u2139\ufe0f Introduction\n\nEnd-to-end demo of an in-house AI agent that can answer a wide range of questions by retrieving information from the **Cin7 ERP** system. For example users can ask questions related to products, stock, accounting or any other type of information contained in Cin7.\n\nPeliqan.io is used as a \"cache\" of all Cin7 data. Peliqan uses one-click ELT to sync all data from Cin7 to the built-in data warehouse, allowing for fast & accurate queries. The AI agent uses Text-to-SQL to answer questions.\n\nText-to-SQL is performed via the Peliqan node, added as a tool to the AI Agent. The question of the user - in natural language - is converted to an SQL query by the AI Agent. The query is executed by Peliqan.io on the source Cin7 data and the result is interpreted by the AI Agent.\n\n## \u2699\ufe0f Setup\n\n* Sign up for a free trial on https://peliqan.io\n* Add Cin7 Omni or Cin7 Core as a connection in Peliqan (using an API key from Cin7)\n* Copy your Peliqan API key (in Peliqan go to Settings > API key) and use it in n8n to add a Peliqan connection\n* Select your data warehouse in the Peliqan node \"Execute an SQL query via Peliqan\" in the drop-down field \"Data warehouse name or id\"\n* Optional: run the [template script](https://help.peliqan.io/build-ai-agents-with-n8n-and-peliqan#block-2401aa9b387980cf8b2ff069588dd3dc) in Peliqan that outputs your specific Cin7 datamodel (tables & columns). Copy your datamodel and paste it in the System Message of the AI Agent (replace the standard Cin7 model already present in this workflow)\n\nVisit peliqan.io/n8n for more information.\nNeed help ? Contact Peliqan at support@peliqan.io"
      },
      "typeVersion": 1
    },
    {
      "id": "611bd81e-fcb8-4a45-b123-beff3c3b7395",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1008,
        496
      ],
      "parameters": {
        "color": 2,
        "width": 471,
        "height": 80,
        "content": "\u26a0\ufe0f To use the Peliqan as tool with Operation \"Execute SQL query\":\nset the below env variable. Run on command line:\n`export N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE=True`"
      },
      "typeVersion": 1
    },
    {
      "id": "8284c916-0a01-4ebf-aeb7-e9e2c78c6b93",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        768,
        384
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "b560538d-4f81-4e26-9dfb-1230f1b24b76",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        992,
        32
      ],
      "parameters": {
        "width": 512,
        "height": 576,
        "content": "## Tools for AI Agent: SQL"
      },
      "typeVersion": 1
    },
    {
      "id": "97d823cf-7cc4-48f2-b994-ba73e0c8dc68",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        416,
        32
      ],
      "parameters": {
        "color": 3,
        "width": 544,
        "height": 576,
        "content": "## AI Chatbot"
      },
      "typeVersion": 1
    },
    {
      "id": "65ac29cf-8fb1-4149-95d2-20f9dd228598",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        544,
        304
      ],
      "parameters": {
        "color": 6,
        "width": 384,
        "height": 224,
        "content": "## Brain"
      },
      "typeVersion": 1
    },
    {
      "id": "1c239ab5-91c1-46b9-9282-c3be28469e95",
      "name": "Execute an SQL query via Peliqan",
      "type": "n8n-nodes-peliqan.peliqanTool",
      "position": [
        1184,
        320
      ],
      "parameters": {
        "querySql": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('SQL_Query', ``, 'string') }}",
        "resource": "query",
        "operation": "exec",
        "connection": "1163"
      },
      "credentials": {
        "peliqanApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "4b8f53b9-463a-4075-b688-e504839d1e0d",
  "connections": {
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute an SQL query via Peliqan": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}