{
  "name": "n8n-2-3: Airtable Workflow",
  "nodes": [
    {
      "parameters": {
        "model": "gpt-4o",
        "options": {}
      },
      "id": "8b509a5f-f142-42f4-9535-dd31b83ed08e",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -260,
        440
      ],
      "typeVersion": 1,
      "credentials": {
        "openAiApi": {
          "id": "qKk5wVYPDLRt63R9",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "agent": "openAiFunctionsAgent",
        "promptType": "define",
        "text": "={{ $('When chat message received').item.json.chatInput }}",
        "options": {
          "systemMessage": "You are Airtable assistant. \nYou need to process user's requests and run relevant tools for that. \n\nPlan and execute in right order runs of tools to get data for user's request.\n\nFeel free to ask questions before do actions - especially if you noticed some inconcistency in user requests that might be error/misspelling. \n\nIMPORTANT Always check right table and base ids before doing queries.\n\nIMPORTANT Use Code function to do aggregation functions that requires math like - count, sum, average and etc. Aggegation function could be recognized by words like \"how many\",\"count\",\"what number\" and etc.\nUse Code function to generate graph and images.\n\nIMPORTANT If search with filter failed - try to fetch records without filter\n\nIMPORTANT Ask yourself before answering - am I did everything is possible? Is the answer is right? Is the answer related to user request?\n\nIMPORTANT Always return in response name of Base and Table where records from. ",
          "maxIterations": 10
        }
      },
      "id": "d34d01ca-afc3-45c6-86c0-4bc7fa699484",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -20,
        160
      ],
      "typeVersion": 1.6
    },
    {
      "parameters": {
        "content": "### Replace Mapbox public key - <your_public_key> in code",
        "height": 80
      },
      "id": "e253da5d-fc70-4d42-936b-33dcf17e2b7c",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        580
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('When chat message received').item.json.sessionId }}"
      },
      "id": "dca155ce-d5a4-4ad7-b300-9cd5de6f2f1c",
      "name": "Window Buffer Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -100,
        440
      ],
      "typeVersion": 1.3
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "3d908f10-d6a0-4b6a-93c3-abdb3ce769e6",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -240,
        160
      ],
      "webhookId": "abf9ab75-eaca-4b91-b3ba-c0f83d3daba4",
      "typeVersion": 1.1
    },
    {
      "parameters": {
        "name": "search",
        "description": "Search records in specific base and table.\n\n- Use Filter (optional) rules for filtering - describe what logic you want to see in filter including field names. \nIMPORTANT - specify all related fields with types for Filter query with right names based on schema. Tool doesn't know schema and type of fields.\n\n- Use Limit (optional) to get more/less records - default = All records. IMPORTANT use default value only when user ask to get all records for analysis.\n\n- Always try to limit list of fields based on user request or in case of number of fields > 30. IMPORTANT Use fields names only.\n \n- Sort by one/multiple fields if needed - order in array is order of level for sorting.\n\nInput example:\nbase_id - appHwXgLVrBujox4J\ntable_id - tblrGzFneREP5Dktl\nlimit - 100\nsort (optional) - [{\"field\":\"Name\",\"direction\":\"asc\"}]\nfilter_desc (optional) - field Name (string) should be equal/contains Mark\nfields (optional) - [\"Name\",\"Email\"]\n\nOutput example:\nRecord 1 - value 1, value 2",
        "workflowId": {
          "__rl": true,
          "value": "brmfwJoKcZIQQUfu",
          "mode": "list",
          "cachedResultName": "n8n-2-3: Airtable Workflow"
        },
        "fields": {
          "values": [
            {
              "name": "command",
              "stringValue": "search"
            }
          ]
        },
        "specifyInputSchema": true,
        "schemaType": "manual",
        "inputSchema": "{\n \"type\": \"object\",\n \"properties\": {\n \"base_id\": {\n \"type\": \"string\",\n \"description\": \"ID of the base to search in\"\n },\n \"table_id\": {\n \"type\": \"string\",\n \"description\": \"ID of the table to search in\"\n },\n \"limit\": {\n \"type\": \"number\",\n \"description\": \"Number of records to retrieve (default is all records)\"\n },\n \"filter_desc\": {\n \"type\": \"string\",\n \"description\": \"Text description of the filter logic\"\n },\n \"sort\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"field\": { \"type\": \"string\" },\n \"direction\": { \"type\": \"string\", \"enum\": [\"asc\", \"desc\"] }\n },\n \"required\": [\"field\", \"direction\"]\n },\n \"description\": \"Array of sorting rules for the query\"\n },\n \"fields\": {\n \"type\": \"array\",\n \"items\": { \"type\": \"string\" },\n \"description\": \"List of fields to retrieve\"\n }\n },\n \"required\": [\"base_id\", \"table_id\"]\n}"
      },
      "id": "3ceec7a1-94bd-44b7-90b1-6515ec5a42a6",
      "name": "Search records",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        320,
        440
      ],
      "typeVersion": 1.2
    },
    {
      "parameters": {
        "name": "code",
        "description": "Process data with code. Use for math functions and image (graphs) generation. \nIMPORTANT Provide raw data only, don't preprocess or use math functions by yourself\n\nInput example:\nrequest - Count average\ndata - 1,2,3\n\nOutput example:\nAverage is 2\nImage file",
        "workflowId": {
          "__rl": true,
          "value": "brmfwJoKcZIQQUfu",
          "mode": "list",
          "cachedResultName": "n8n-2-3: Airtable Workflow"
        },
        "fields": {
          "values": [
            {
              "name": "command",
              "stringValue": "code"
            }
          ]
        },
        "specifyInputSchema": true,
        "schemaType": "manual",
        "inputSchema": "{\n \"type\": \"object\",\n \"properties\": {\n \"request\": {\n \"type\": \"string\",\n \"description\": \"Description of the operation to perform.\"\n },\n \"data\": {\n \"type\": \"string\",\n \"description\": \"Stringified data - JSON, strings, arrays and etc.\"\n }\n },\n \"required\": [\"request\", \"data\"]\n}"
      },
      "id": "9837ffdd-6f8f-4855-b3f1-57aae7ca0dab",
      "name": "Process data with code",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        460,
        440
      ],
      "typeVersion": 1.2
    },
    {
      "parameters": {
        "name": "create_map",
        "description": "Create link with image for map graph.\nUse addresses' longitude and latitude to create input data.\n\nInput Example:\npin-s+555555(-74.006,40.7128),pin-s+555555(-118.2437,34.0522)\n\nOutput Example:\nImage link.",
        "jsCode": "// Example: convert the incoming query to uppercase and return it\n\nreturn `https://api.mapbox.com/styles/v1/mapbox/streets-v12/static/${query.markers}/-96.9749,41.8219,3.31,0/800x500?before_layer=admin-0-boundary&access_token=<your_public_key>`;",
        "specifyInputSchema": true,
        "schemaType": "manual",
        "inputSchema": "{\n\"type\": \"object\",\n\"properties\": {\n\t\"markers\": {\n\t\t\"type\": \"string\",\n\t\t\"description\": \"List of markers with longitude and latitude data separated by comma. Keep the same color 555555|Example: pin-s+555555(-74.006,40.7128),pin-s+555555(-118.2437,34.0522)\"\n\t\t}\n\t}\n}"
      },
      "id": "57731430-f31d-405d-b2b3-6165fe04fbe5",
      "name": "Create map image",
      "type": "@n8n/n8n-nodes-langchain.toolCode",
      "position": [
        620,
        440
      ],
      "typeVersion": 1.1
    },
    {
      "parameters": {
        "name": "get_bases",
        "description": "Fetches the list of available bases.\n\nOutput:\n- List of bases with their IDs and names.",
        "workflowId": {
          "__rl": true,
          "value": "brmfwJoKcZIQQUfu",
          "mode": "list",
          "cachedResultName": "n8n-2-3: Airtable Workflow"
        },
        "fields": {
          "values": [
            {
              "name": "command",
              "stringValue": "get_bases"
            }
          ]
        }
      },
      "id": "e31fde19-7fb1-4487-a1a8-750c5c65c8fa",
      "name": "Get list of bases",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        40,
        440
      ],
      "typeVersion": 1.2
    },
    {
      "parameters": {
        "name": "get_base_tables_schema",
        "description": "Fetches the schema of tables in a specific base by id.\n\nInput:\nbase_id: appHwXgLVrBujox4J\n\nOutput:\ntable 1: field 1 - type string, fields 2 - type number",
        "workflowId": {
          "__rl": true,
          "value": "brmfwJoKcZIQQUfu",
          "mode": "list",
          "cachedResultName": "n8n-2-3: Airtable Workflow"
        },
        "fields": {
          "values": [
            {
              "name": "command",
              "stringValue": "get_base_tables_schema"
            }
          ]
        },
        "specifyInputSchema": true,
        "schemaType": "manual",
        "inputSchema": "{\n \"type\": \"object\",\n \"properties\": {\n \"base_id\": {\n \"type\": \"string\",\n \"description\": \"ID of the base to retrieve the schema for. Format - appHwXgLVrBujox4J\"\n }\n },\n \"required\": [\"base_id\"]\n}"
      },
      "id": "98130bc7-df47-4a30-a4cd-c953b40cce8f",
      "name": "Get base schema",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        180,
        440
      ],
      "typeVersion": 1.2
    },
    {
      "parameters": {},
      "id": "88a6fc2e-1cf0-4772-af94-34ad075c3d42",
      "name": "Execute Workflow Trigger",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        -780,
        1120
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "cfdbe2f5-921e-496d-87bd-9c57fdc22a7a",
              "name": "response",
              "type": "object",
              "value": "={{$json}}"
            }
          ]
        },
        "options": {}
      },
      "id": "008f017c-6a5c-416c-90ed-06d2c8a18bb3",
      "name": "Response",
      "type": "n8n-nodes-base.set",
      "position": [
        1200,
        1140
      ],
      "typeVersion": 3.4
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Execute Workflow Trigger').item.json.command }}",
                    "rightValue": "get_bases"
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "get_bases"
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "26a3ffe8-c8a6-4564-8d18-5494a8059372",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Execute Workflow Trigger').item.json.command }}",
                    "rightValue": "get_base_tables_schema"
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "get_base_tables_schema"
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "0f51cc26-2e42-42e1-a5c2-cb1d2e384962",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Execute Workflow Trigger').item.json.command }}",
                    "rightValue": "search"
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "search"
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "51031140-5ceb-48aa-9f33-d314131a9653",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Execute Workflow Trigger').item.json.command }}",
                    "rightValue": "code"
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "code"
            }
          ]
        },
        "options": {}
      },
      "id": "fbf47edb-c12f-4c4b-a252-85fe91a4a0bf",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        -560,
        1100
      ],
      "typeVersion": 3.2
    },
    {
      "parameters": {
        "aggregate": "aggregateAllItemData",
        "options": {}
      },
      "id": "0bb2b677-e56d-43d9-8c1b-1c1a3303e9bb",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        240,
        760
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "aggregate": "aggregateAllItemData",
        "options": {}
      },
      "id": "8c69caa1-83f7-48a9-97fc-476613988785",
      "name": "Aggregate1",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        240,
        920
      ],
      "typeVersion": 1
    },
    {
      "parameters": {},
      "id": "ef6695c3-56db-45fb-9a2c-be234e78a408",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        420,
        1140
      ],
      "typeVersion": 3
    },
    {
      "parameters": {
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "records"
            }
          ]
        },
        "options": {
          "mergeLists": true
        }
      },
      "id": "a65c3738-77ed-4af4-9793-38e6e0dd2f7b",
      "name": "Aggregate2",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        740,
        1140
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "fcb24127-53f9-4498-b0fd-463bd4966ac9",
              "operator": {
                "type": "string",
                "operation": "notExists",
                "singleValue": true
              },
              "leftValue": "={{ $json.data[0].attachments[0].file_id }}",
              "rightValue": ""
            },
            {
              "id": "016ecba7-f6af-4881-a7d6-780dcb43223c",
              "operator": {
                "type": "string",
                "operation": "notExists",
                "singleValue": true
              },
              "leftValue": "={{ $json.data[0].content.find(x=>x.type==\"image_file\").image_file.file_id }}",
              "rightValue": ""
            }
          ]
        },
        "options": {}
      },
      "id": "6c4b314d-966a-4a54-a1ed-e67e8ee1223f",
      "name": "If1",
      "type": "n8n-nodes-base.if",
      "position": [
        580,
        1500
      ],
      "typeVersion": 2.2
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "cfdbe2f5-921e-496d-87bd-9c57fdc22a7a",
              "name": "response",
              "type": "string",
              "value": "={{ $json.data.url.replace('org/','org/dl/') }}"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "b82c593b-a5a5-44ec-92d0-7bc59396e1ec",
      "name": "Response1",
      "type": "n8n-nodes-base.set",
      "position": [
        1220,
        1500
      ],
      "typeVersion": 3.4
    },
    {
      "parameters": {
        "resource": "base",
        "options": {}
      },
      "id": "6829fab7-2ac8-4101-ac66-53cb4d151262",
      "name": "Get Bases",
      "type": "n8n-nodes-base.airtable",
      "position": [
        40,
        760
      ],
      "typeVersion": 2.1,
      "credentials": {
        "airtableTokenApi": {
          "id": "lKrmtLc3Va7YXnXJ",
          "name": "Sales CRM Airtable"
        }
      }
    },
    {
      "parameters": {
        "resource": "base",
        "operation": "getSchema",
        "base": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Execute Workflow Trigger').item.json.query.base_id }}"
        }
      },
      "id": "61c2a67b-4f11-4500-a846-b9c4151e2069",
      "name": "Get Base/Tables schema",
      "type": "n8n-nodes-base.airtable",
      "position": [
        40,
        920
      ],
      "typeVersion": 2.1,
      "credentials": {
        "airtableTokenApi": {
          "id": "lKrmtLc3Va7YXnXJ",
          "name": "Sales CRM Airtable"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "fcb24127-53f9-4498-b0fd-463bd4966ac9",
              "operator": {
                "type": "string",
                "operation": "notExists",
                "singleValue": true
              },
              "leftValue": "={{ $('Execute Workflow Trigger').item.json.query.filter_desc }}",
              "rightValue": ""
            }
          ]
        },
        "options": {}
      },
      "id": "a631a9e3-b09e-4dbd-9318-af5e239a6c9b",
      "name": "If filter description exists",
      "type": "n8n-nodes-base.if",
      "position": [
        -200,
        1140
      ],
      "typeVersion": 2.2
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.airtable.com/v0/{{ $('Execute Workflow Trigger').item.json.query.base_id }}/{{ $('Execute Workflow Trigger').item.json.query.table_id }}/listRecords",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "airtableTokenApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ \n Object.fromEntries(\n Object.entries({\n sort: $('Execute Workflow Trigger').item.json.query.sort,\n limit: $('Execute Workflow Trigger').item.json.query.limit,\nfields: $('Execute Workflow Trigger').item.json.query.fields,\nfilterByFormula: $('Merge').item.json.choices == undefined ? undefined : JSON.parse($json.choices[0].message.content).filter\n }).filter(([key, value]) => value !== undefined)\n )\n}}",
        "options": {
          "pagination": {
            "pagination": {
              "parameters": {
                "parameters": [
                  {
                    "type": "body",
                    "name": "offset",
                    "value": "={{ $response.body.offset}}"
                  }
                ]
              },
              "paginationCompleteWhen": "other",
              "completeExpression": "={{ $response.body.offset==undefined}}"
            }
          }
        }
      },
      "id": "f516c677-3bc3-4195-92cb-49ced352412b",
      "name": "Airtable - Search records",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        560,
        1140
      ],
      "typeVersion": 4.2,
      "credentials": {
        "airtableTokenApi": {
          "id": "lKrmtLc3Va7YXnXJ",
          "name": "Sales CRM Airtable"
        }
      },
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.openai.com/v1/chat/completions",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "openAiApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n \"model\": \"gpt-4o-mini\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": {{ JSON.stringify($('Set schema and prompt').item.json.prompt) }}\n },\n {\n \"role\": \"user\",\n \"content\": \"{{ $('Execute Workflow Trigger').item.json.query.filter_desc }}\"\n }],\n \"response_format\":{ \"type\": \"json_schema\", \"json_schema\": {{ $('Set schema and prompt').item.json.schema }}\n\n }\n }",
        "options": {}
      },
      "id": "713e8955-131d-4ad0-95f5-f13675092097",
      "name": "OpenAI - Generate search filter",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        220,
        1200
      ],
      "typeVersion": 4.2,
      "credentials": {
        "openAiApi": {
          "id": "qKk5wVYPDLRt63R9",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "dc09a5b4-ff6a-4cee-b87e-35de7336ac05",
              "name": "prompt",
              "type": "string",
              "value": "=Analyse user request for Airtable filtration. User filter rules to build right formula. Think smart about filter (e.g. instead of search where Name equal to value - search where name contains lowercase value)\nIMPORTANT Check examples and best practices before building formula. \n\nIMPORTANT best practices:\n\nSEARCH(LOWER('example'), LOWER({Field})) ensures both the search term and field are compared in lowercase for consistent case-insensitive matching\n\nIMPORTANT Examples:\n\n- AND(SEARCH('urgent', {Notes}), {Priority} > 3) fetch records where “Notes” contain “urgent” and “Priority” is greater than 3\n- AND({Status} = 'Pending', IS_BEFORE({Due Date}, TODAY())) fetch records where “Status” is “Pending” and “Due Date” is before today\n- OR(SEARCH('error', {Logs}), SEARCH('warning', {Logs})) fetch records where “Logs” contain “error” or “warning”\n- AND(LEN({Description}) > 10, {Price} > 50) fetch records where “Description” is longer than 10 characters and “Price” is greater than 50\n- RECORD_ID() = 'rec12345' fetch a specific record by its ID\n- SEARCH('rec67890', ARRAYJOIN({Linked Records}, ',')) fetch records linked to a specific record ID rec67890\n- AND(SEARCH('rec12345', ARRAYJOIN({Linked Records}, ',')), {Status} = 'Active') fetch records where “Linked Records” contain rec12345 and “Status” is “Active”\n\nFormula rules:\nOperators - =,!=,>,<,>=,<= \n- AND(condition1, condition2, ...) logical AND\n- OR(condition1, condition2, ...) logical OR\n- NOT(condition) logical NOT\n- SEARCH('substring', {Field}) finds position of substring, case-insensitive\n- FIND('substring', {Field}) finds position of substring, case-sensitive\n- IS_BEFORE({Date}, 'YYYY-MM-DD') checks if date is before\n- IS_AFTER({Date}, 'YYYY-MM-DD') checks if date is after\n- IS_SAME({Date1}, {Date2}, 'unit') checks if dates are the same by unit\n- RECORD_ID() = 'recXXXXXX' filters by record ID\n- {Field} = '' field is blank\n- {Field} != '' field is not blank\n- ARRAYJOIN({Linked Field}, ',') joins linked records into a string\n- LOWER({Field}) converts to lowercase for case-insensitive comparison\n- UPPER({Field}) converts to uppercase for case-insensitive comparison\n- VALUE({Text}) converts text to number for numeric comparisons\n- LEN({Field}) gets text length\n- ROUND(number, precision) rounds number\n- TODAY() current date\n- NOW() current timestamp\n- IF(condition, true_value, false_value) conditional logic\n- DATETIME_FORMAT({Date}, 'format') formats date as text\n- DATETIME_DIFF(date1, date2, 'unit') difference between dates\n- DATEADD({Date}, number, 'unit') adds time to date\n- LEFT({Text}, number) extracts leftmost characters\n- RIGHT({Text}, number) extracts rightmost characters\n- AND({Field1} = 'Value1', {Field2} > 50) multiple conditions\n- SEARCH('Value', {Field}) substring match\n- ROUND({Field1} / {Field2}, 2) numeric calculation\n- AND(IS_BEFORE({Date}, TODAY()), {Status} = 'Active') filter by date and status\n- ISERROR(expression) checks if an expression has an error\n- ABS(number) absolute value\n- MIN(value1, value2) minimum value\n- MAX(value1, value2) maximum value\n\n"
            },
            {
              "id": "4e0f9af6-517f-42af-9ced-df0e8a7118b0",
              "name": "schema",
              "type": "string",
              "value": "={\n \"name\": \"filter\",\n \"schema\": {\n \"type\": \"object\",\n \"properties\": {\n \"filter\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"filter\"\n ],\n \"additionalProperties\": false\n },\n \"strict\": true\n}"
            }
          ]
        },
        "options": {}
      },
      "id": "dd024ea1-1210-49f8-8304-e514d536f1f5",
      "name": "Set schema and prompt",
      "type": "n8n-nodes-base.set",
      "position": [
        20,
        1200
      ],
      "typeVersion": 3.4
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://tmpfiles.org/api/v1/upload",
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "data"
            }
          ]
        },
        "options": {}
      },
      "id": "86f3c631-30b6-47e2-b5e9-69151d176f01",
      "name": "Upload file to get link",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1040,
        1500
      ],
      "typeVersion": 4.2,
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "url": "=https://api.openai.com/v1/files/{{ $json.data[0].attachments[0]?.file_id ?? $json.data[0].content.find(x=>x.type==\"image_file\")?.image_file.file_id }}/content",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "openAiApi",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "OpenAI-Beta",
              "value": "assistants=v2"
            }
          ]
        },
        "options": {}
      },
      "id": "18c4ef20-3b70-4fcf-a5b5-aa44e31af74e",
      "name": "OpenAI - Download File",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        820,
        1500
      ],
      "typeVersion": 4.2,
      "credentials": {
        "openAiApi": {
          "id": "qKk5wVYPDLRt63R9",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "url": "=https://api.openai.com/v1/threads/{{ $('OpenAI - Create thread').item.json.id }}/messages",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "openAiApi",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "OpenAI-Beta",
              "value": "assistants=v2"
            }
          ]
        },
        "options": {}
      },
      "id": "f25a0cfd-5948-4e9f-8bc6-62b052b017a4",
      "name": "OpenAI - Get messages",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        420,
        1500
      ],
      "typeVersion": 4.2,
      "credentials": {
        "openAiApi": {
          "id": "qKk5wVYPDLRt63R9",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.openai.com/v1/threads/{{ $('OpenAI - Create thread').item.json.id }}/runs",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "openAiApi",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "OpenAI-Beta",
              "value": "assistants=v2"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "assistant_id",
              "value": "asst_4LUcd7gQY6abM9g5ZpVCNrgT"
            },
            {
              "name": "stream",
              "value": "={{true}}"
            },
            {
              "name": "tool_choice",
              "value": "={{ {\"type\": \"code_interpreter\"} }}"
            },
            {
              "name": "tools",
              "value": "={{ [{\"type\": \"code_interpreter\"}] }}"
            }
          ]
        },
        "options": {}
      },
      "id": "6add2d9d-5b1c-44d4-a9b7-5eed6b22d563",
      "name": "OpenAI - Run assistant",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        220,
        1500
      ],
      "typeVersion": 4.2,
      "credentials": {
        "openAiApi": {
          "id": "qKk5wVYPDLRt63R9",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.openai.com/v1/threads/{{ $('OpenAI - Create thread').item.json.id }}/messages ",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "openAiApi",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "OpenAI-Beta",
              "value": "assistants=v2"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "role",
              "value": "user"
            },
            {
              "name": "content",
              "value": "=Request:\n{{ $('Execute Workflow Trigger').item.json.query.request }}\n\nData:\n{{ $('Execute Workflow Trigger').item.json.query.data }}"
            }
          ]
        },
        "options": {}
      },
      "id": "9a460c7e-4713-4d8c-b8f0-3f2d026559f6",
      "name": "OpenAI - Send message",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        20,
        1500
      ],
      "typeVersion": 4.2,
      "credentials": {
        "openAiApi": {
          "id": "qKk5wVYPDLRt63R9",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/threads",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "openAiApi",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "OpenAI-Beta",
              "value": "assistants=v2"
            }
          ]
        },
        "options": {}
      },
      "id": "0a62826e-4759-4caf-8917-991f403502cf",
      "name": "OpenAI - Create thread",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -180,
        1500
      ],
      "typeVersion": 4.2,
      "credentials": {
        "openAiApi": {
          "id": "qKk5wVYPDLRt63R9",
          "name": "OpenAi account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Window Buffer Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search records": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Process data with code": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Create map image": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get list of bases": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get base schema": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Execute Workflow Trigger": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Get Bases",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Base/Tables schema",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "If filter description exists",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "OpenAI - Create thread",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate1": {
      "main": [
        [
          {
            "node": "Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Airtable - Search records",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate2": {
      "main": [
        [
          {
            "node": "Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "OpenAI - Download File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Bases": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Base/Tables schema": {
      "main": [
        [
          {
            "node": "Aggregate1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If filter description exists": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set schema and prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Airtable - Search records": {
      "main": [
        [
          {
            "node": "Aggregate2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI - Generate search filter": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Set schema and prompt": {
      "main": [
        [
          {
            "node": "OpenAI - Generate search filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload file to get link": {
      "main": [
        [
          {
            "node": "Response1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI - Download File": {
      "main": [
        [
          {
            "node": "Upload file to get link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI - Get messages": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI - Run assistant": {
      "main": [
        [
          {
            "node": "OpenAI - Get messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI - Send message": {
      "main": [
        [
          {
            "node": "OpenAI - Run assistant",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI - Create thread": {
      "main": [
        [
          {
            "node": "OpenAI - Send message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "2d4526d7e2b7123bfb0e1996caa47744a7651d73096bbc7220a5e9657d119dfc"
  },
  "tags": [],
  "id": "UsSrH0SIBNITVzla"
}