{
  "name": "LangMem Memory Consolidation",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 2 * * *"
            }
          ]
        }
      },
      "id": "langmem-cron-trigger",
      "name": "Nightly at 2 AM",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "http://backend:8000/memory/health",
        "options": {
          "timeout": 10000
        }
      },
      "id": "langmem-health-check",
      "name": "Check Memory Health",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "condition-enabled",
              "leftValue": "={{ $json.enabled }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "langmem-if-enabled",
      "name": "Is Memory Enabled?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://backend:8000/memory/consolidate",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{}",
        "options": {
          "timeout": 300000
        }
      },
      "id": "langmem-consolidate",
      "name": "Run Consolidation",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        900,
        240
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "result",
              "value": "=Consolidation completed: reviewed={{ $json.facts_reviewed }}, merged={{ $json.facts_merged }}, superseded={{ $json.facts_superseded }}, expired={{ $json.facts_expired }}"
            }
          ]
        },
        "options": {}
      },
      "id": "langmem-log-result",
      "name": "Log Result",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1120,
        240
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "result",
              "value": "Memory service is disabled, skipping consolidation"
            }
          ]
        },
        "options": {}
      },
      "id": "langmem-skip",
      "name": "Skip (Disabled)",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        900,
        400
      ]
    }
  ],
  "connections": {
    "Nightly at 2 AM": {
      "main": [
        [
          {
            "node": "Check Memory Health",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Memory Health": {
      "main": [
        [
          {
            "node": "Is Memory Enabled?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Memory Enabled?": {
      "main": [
        [
          {
            "node": "Run Consolidation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Skip (Disabled)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Consolidation": {
      "main": [
        [
          {
            "node": "Log Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "tags": [
    {
      "name": "memory"
    },
    {
      "name": "langmem"
    }
  ]
}