{
  "id": "L7gGUWkvL3u0OG4p",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Peliqan AI Agent Uniconta ERP",
  "tags": [],
  "nodes": [
    {
      "id": "8f2f7a9d-2382-450c-a3b0-6d2a0625c5ca",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        464,
        96
      ],
      "parameters": {
        "public": true,
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "a5a630da-b374-4135-a3b4-cd6f11e27256",
      "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 Uniconta ERP system.\n\nYou can query Uniconta by running SQL queries on the Uniconta 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 Uniconta data model of tables & columns that can be used in SQL queries:\n\n\nColumns in table uniconta.creditorclient:\n\ngroup\naccount\nname\naddress1\nzipcode\ncity\ncountry\ncountryname\ncurrency\nallowmergepayment\ncompanyregno\npayment\nvatzone\nenddiscountpct\nuserlanguage\npaymentmethod\nblocked\ncurbalance\noverdue\ncurbalancecur\noverduecur\nlastinvoice\npaymentfee\nusernote\nuserattachment\neeisnotvatdeclorg\nuserlangaugeid\nbalancemethod\ncreated\nlinediscountpct\ndeliverytime\ncompanystate\nupdatedat\nhasnotes\nhasdocs\nispeppolsupported\ncompanyid\nrowid\nvat\npostingaccount\npaymentid\nvatnumber\n\nColumns in table uniconta.creditortransclient:\n\ndate\naccount\nprimarykeyid\nvoucher\nopen\ninvoice\nposttype\njournalpostedid\namount\nnumberserie\nissettled\nexchangeregulated\ndocumentref\ntext\nisdcinvoice\ncompanyid\nrowid\ninvoicean\ncurrency\namountcur\n\nColumns in table uniconta.creditortransopenclient:\n\naccount\nname\npaymentmethod\nusedcashdiscount\nfromdebtor\namountopen\namountopencur\noverdue\noverduecur\ncashdiscount\ncashdiscountdate\nduedate\npaid\nonhold\nsendtocollection\npayment\ntext\nprimarykeyid\ndate\nvoucher\nvoucherx\nopen\ninvoice\ninvoicean\nposttype\njournalpostedid\namount\ncredit\ncurrency\namountcur\ncreditcur\nnumberserie\nissettled\nhasvoucher\ndocumentref\npaymentdate\npaymentrefid\npaymentendtoendid\npartialpaymentamount\nvatofcashdiscount\nvatamount\nordernumber\nisdcinvoice\ngracedate\ncompanyid\nvat\ndebit\n\nColumns in table uniconta.debtorclient:\n\ngroup\naccount\nname\naddress1\ncity\nzipcode\ncountry\ncountryname\ncompanyregno\ncurrency\npayment\nenddiscountpct\ncreditmax\nvatzone\nvat\npricegroup\nlayoutgroup\npostingaccount\nblocked\ndirectdebitactive\nuserlanguage\ninvoiceemail\ncurbalance\noverdue\ncurbalancecur\noverduecur\npricesinclvat\ninvoiceinxml\nbankaccounttype\nbankaccount\nlastinvoice\nvatnumber\npaymentfee\nusernote\nuserattachment\neeisnotvatdeclorg\nuserlangaugeid\nswift\nemaildocuments\nbalancemethod\ncreated\nlinediscountpct\npackagingconsumer\ncompanystate\nupdatedat\nhasnotes\nhasdocs\nispeppolsupported\ncompanyid\nrowid\ncontactemail\ncontactperson\n\nColumns in table uniconta.debtorinvoiceclient:\n\nprimarykeyid\naccount\nname\npricesinclvat\ncostvalue\nmargin\nmarginratio\nsalesvalue\nisonetimedebtor\nlayoutgroup\nstockupdate\npacknote\noffer\ngracedate\ndate\nordernumber\ninvoicenumber\nvoucher\ndeleted\ncostrestated\njournalpostedid\nenddiscountpct\nenddiscount\nvatamount\nlineamount\nnetamount\nwithholding\ntotalamount\npayment\nduedate\nsendtime\nsendtimeoio\nsendtimedirectdebit\nvattotal\nvattotal2\nvattotal3\nvatpct\nvatpct2\nvatpct3\nvat\ncurrency\npaymenttext\nvoidinvoice\nnumberserie\ncashdiscount\ncontactref\nordercreated\nfikcode\ncartons\nweight\nnetweight\nvolume\nsimulation\ndeliveryisinvoiceaddress\nerroremail\nerroroio\ncashpayment\namountlocalcur\nexchangerate\nvatzoneenum\ncompanyid\nrowid\n\nColumns in table uniconta.debtorinvoicelines:\n\ncartons\nweight\nnetweight\nvolume\nunitstr\ninvoiceqty\nvatpct\ninvoiceprice\ninvoicetotal\ninvoicenetamount\nvatamount\nformattedinvoiceqty\nlinenumber\ndate\nitem\nitemname\ndcaccount\naccountname\nmovementtype\nqty\nnetamount\ngrossamount\ntotal\nmargin\nmarginratio\ncostprice\ncostvalue\nsalesprice\ncurrency\nsalespricecur\ntotalcur\nnetdiscount\nordernumber\ninvoicenumber\nvat\ntext\nunit\nsubtotal\ncostrestated\nstockupdate\nimported\ncostposted\njournalpostedid\ninvjournalpostedid\npartofbom\nweek\nhasseriabatch\ncompanyid\nid\ndiscountpct\n\nColumns in table uniconta.debtororderclient:\n\nkeyname\nprimarykeyid\naccount\nname\npricesinclvat\nconfirmprinted\ncurbalance\noverdue\ncreditmax\nsalesvalue\nmargin\nmarginratio\ninvoiceemail\ninvoiceinterval\nnextinvoice\nsubscriptionended\ncountry\ncountryname\nordernumber\nlastpacknote\npicklistprinted\nproducedqty\nprojecttotal\nprojectcost\noffer\npostingaccount\npackagingconsumer\nhasnotes\nhasdocs\nordertype\nkeystr\npropertyofkeystr\nupdatedat\ncompanyid\nrowid\nenddiscountpct\npayment\ncurrency\nordertotal\ncostvalue\ndeleteorder\ndeletelines\ncreated\ncreatedtime\nlastinvoice\ndocumentref\npacknoteprinted\napproved\ncontactref\ninvoicedate\nupdatedon\nnolines\ntotalqty\ndeliveryisinvoiceaddress\ndiscount\ntotalbeforevat\napproveddate\ndeliverydateconfirmed\nweight\nnetweight\nvolume\ncartons\nduedate\nlayoutgroup\n\nColumns in table uniconta.debtororderlineclient:\n\nordernumber\ndeleteline\nordernumberorg\nsalesvalue\ncostvalue\nmargin\nmarginratio\nqtynow\nstorage\nqtydelivered\nname\naccount\nprimarykey1id\nprimarykey2id\nlinenumber\nweek\ntext\ndiscountpct\nqty\nprice\ndiscount\ncostprice\ntotal\ndoinvoice\ncurrency\nsubtotal\nhasnote\nignoreblocked\nqtyinvoiced\nremaining\norderrefline\ncostreftrans\nismarked\nseriebatchmarked\nupdatedat\ncartons\nweight\nvolume\nmarked\nordertype\ncompanyid\nrowid\norderrowid\nitem\n\nColumns in table uniconta.debtortransclient:\n\naccount\nprimarykeyid\ndate\nvoucher\nopen\ninvoice\ninvoicean\nposttype\njournalpostedid\namount\nnumberserie\nissettled\nexchangeregulated\ndocumentref\ntext\nisdcinvoice\ncompanyid\nrowid\n\nColumns in table uniconta.debtortransopenclient:\n\naccount\nname\nsendtime\npaymentstatus\nvat\ncollectionsletters\nlastinterest\nlastcollectionletter\nviewinvoicelink\nfromcreditor\nfeeamount\npaymentcharge\namountopen\noverdue\ncashdiscount\ncashdiscountdate\nduedate\npaid\nonhold\nsendtocollection\npayment\ntext\nprimarykeyid\ndate\nvoucher\nvoucherx\nopen\ninvoice\ninvoicean\nposttype\njournalpostedid\namount\ndebit\nnumberserie\nissettled\nhasvoucher\ndocumentref\npaymentdate\npaymentrefid\npaymentendtoendid\npartialpaymentamount\nvatofcashdiscount\nvatamount\nordernumber\nisdcinvoice\ngracedate\ncompanyid\n\nColumns in table uniconta.glaccountclient:\n\naccount\nname\naccounttype\ndefaultoffsetaccounttype\nblockedinjournal\nblocked\nsystemaccount\nmandatorytax\npagebreak\npercentage\nsavetotal\nbalance\nthisyear\nthisyeardebit\nthisyearcredit\nprevyear\nprevyeardebit\nprevyearcredit\nmandatorycategory\ncurrency\nreconciled\nexternalno\nexternalname\ndebetcredit\nstandardaccount\nhideinbalance\ndatevauto\ndim1parmdisplay\ndim2parmdisplay\ndim3parmdisplay\ndim4parmdisplay\ndim5parmdisplay\nusernote\nuserattachment\ndim1parm\ndim2parm\ndim3parm\ndim4parm\ndim5parm\ncategoryparm\ncurbalance\nprevbalance\nupdatedat\nhasnotes\nhasdocs\naccounttypeenum\nsystemaccountenum\ncompanyid\nrowid\nsavetotalinindex\nvat\nvatoperation\nsum\ncalculationexpression\nsuminfo\n\nColumns in table uniconta.gltransclient:\n\ndate\ndocumentdate\naccount\nvoucher\nvoucherline\ninvoice\njournalpostedid\namount\ntext\norigin\nnumberserie\namountcur\namountvat\namountbase\nhasvoucher\ndocumentref\nqty\ncompanyid\nid\ndctype\ndcaccount\ncurrency\nvat\n\nColumns in table uniconta.glvatclient:\n\nvat\nname\naccount\noffsetaccount\nvattype\nmethod\ntypesales\nvatoperationname\nrate\nrate2\nrate2partofbrutto\nrateafterdate\nrate2afterdate\nfollowaccount\nfollowaccount2\nmodelboxid\nshowzerooninvoice\nratetype\nmosstype\nexempt\nusedsalesvat\nblocked\nrowid\nupdatedat\nhasnotes\nhasdocs\ncompanyid\ntypebuy\nrate1vat\noffsetvatoperation\noffsetvatoperationname\n\nColumns in table uniconta.invitemclient:\n\nitem\nname\nitemtype\ncostmodel\npurchaseprice\ncostprice\nsalesprice1\nsalesprice2\nsalesprice3\ncartons\nblocked\npurchasecurrency\ncurrency1\ncurrency2\ncurrency3\nunit\nqty\ncostvalue\naveragecost\nusestorage\nhideinsales\nhideinpurchase\ngroup\nphoto\nurl\ninvoiceattachment\nlastmovement\nusevariants\nmandatoryvariant\nserialorbatch\nmandatoryserialbatch\nmandatoryserialbatchmarking\nweight\nnetweight\nvolume\nminstocklevel\nmaxstocklevel\npurchaseqty\nsalesqty\nincludeindiscount\nbomcostoflines\nitemincludedinbom\nusealternative\nqtyonstock\nqtyreserved\nqtyordered\navailable\navailableforreservation\nsalesunit\npurchaseunit\nusernote\nuserattachment\npurchasemin\ndeliverytime\nintraunit\nunspsc\nupdatedat\nhasnotes\nhasdocs\ncompanyid\nrowid"
        }
      },
      "typeVersion": 1.6,
      "alwaysOutputData": true
    },
    {
      "id": "af09ddf1-9e35-4ad1-9926-a4db2992cf67",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        592,
        384
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "508ebe8b-dbc5-45ce-aaf7-d26142eeb237",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -480,
        32
      ],
      "parameters": {
        "color": 4,
        "width": 866,
        "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 **Uniconta ERP** system. For example users can ask questions related to products, stock, accounting or any other type of information contained in Uniconta.\n\nPeliqan.io is used as a \"cache\" of all Uniconta data. Peliqan uses one-click ELT to sync all data from Uniconta 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 Uniconta 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 Uniconta as a connection in Peliqan (using an API key from Uniconta)\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 Uniconta datamodel (tables & columns). Copy your datamodel and paste it in the System Message of the AI Agent (replace the standard Uniconta 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": "e01d826b-9631-4a9b-9efe-bf66163fbfca",
      "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": "ea4d8c9a-5eab-4699-985d-70efddbbf605",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        768,
        384
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "5a7dd691-cbe7-46a5-9f24-8f1b2a3074cb",
      "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": "e21bb8f2-e3f8-4010-b8c9-2912ee26d79f",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        416,
        32
      ],
      "parameters": {
        "color": 3,
        "width": 544,
        "height": 576,
        "content": "## AI Chatbot"
      },
      "typeVersion": 1
    },
    {
      "id": "be062018-3f81-4f98-8aac-f34672ee677f",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        544,
        304
      ],
      "parameters": {
        "color": 6,
        "width": 384,
        "height": 224,
        "content": "## Brain"
      },
      "typeVersion": 1
    },
    {
      "id": "7ff886d9-bb55-4a88-9ce7-b5624a3136bd",
      "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": "0e25f4c5-533a-4b44-a77f-29fb8e3637e3",
  "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
          }
        ]
      ]
    }
  }
}