{
  "name": "moss",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "id": "node-telegram-trigger",
      "name": "telegram trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.1,
      "position": [
        0,
        300
      ],
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const msg = $input.first().json;\nconst chatId = String(msg.message.chat.id);\nconst text = msg.message.text || '';\nconst firstName = msg.message.from.first_name || '';\nconst username = msg.message.from.username || '';\nreturn [{ json: { chatId, text, firstName, username } }];"
      },
      "id": "node-extract",
      "name": "extract message",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "operation": "getAll",
        "tableId": "user_profiles",
        "filters": {
          "conditions": [
            {
              "keyName": "chat_id",
              "keyValue": "={{ $json.chatId }}"
            }
          ]
        },
        "options": {
          "limit": 1
        }
      },
      "id": "node-read-profile",
      "name": "read profile",
      "type": "n8n-nodes-base.n8nTrainingCustom",
      "typeVersion": 1,
      "position": [
        440,
        300
      ],
      "continueOnFail": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "leftValue": "={{ $json.profile || '' }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "node-check-profile",
      "name": "has profile?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        660,
        300
      ]
    },
    {
      "parameters": {
        "agent": "conversationalAgent",
        "promptType": "define",
        "text": "={{ $('extract message').item.json.text }}",
        "options": {
          "systemMessage": "you are moss, a personal AI assistant.\n\nthis user is new. your job right now is onboarding \u2014 help them set up their profile.\n\nstart with a warm, brief greeting. then ask them to tell you about themselves: who they are, what they do, what they care about, how they like to communicate. keep it open-ended \u2014 don't use a rigid questionnaire. let them share what they want.\n\nonce they've shared enough (at least name + some context about their life/work), confirm what you've understood and tell them you're ready to help.\n\nkeep your tone direct and natural. no corporate filler phrases."
        }
      },
      "id": "node-onboarding-agent",
      "name": "onboarding agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        880,
        480
      ]
    },
    {
      "parameters": {
        "agent": "conversationalAgent",
        "promptType": "define",
        "text": "={{ $('extract message').item.json.text }}",
        "options": {
          "systemMessage": "=you are moss, a personal AI assistant.\n\n## what you know about this user\n{{ $('read profile').item.json.profile || 'no profile yet' }}\n\n## how to behave\n- direct and efficient. skip filler phrases like \"of course!\" or \"great question!\"\n- have opinions. you can disagree and push back\n- reply in the same language the user writes in\n- use structured output (bullets, tables) for complex answers\n- remember what the user tells you during this conversation\n- be precise with numbers and claims \u2014 especially anything finance-related\n\n## your purpose\nhelp this user think better, work faster, and get things done. you have access to their calendar, tasks, and preferences. use that context proactively."
        }
      },
      "id": "node-main-agent",
      "name": "main agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        880,
        160
      ]
    },
    {
      "parameters": {
        "model": "deepseek-chat",
        "options": {
          "temperature": 0.7,
          "maxTokens": 1500
        }
      },
      "id": "node-llm-main",
      "name": "llm for main",
      "type": "@n8n/n8n-nodes-langchain.lmChatDeepSeek",
      "typeVersion": 1,
      "position": [
        780,
        0
      ],
      "credentials": {
        "deepSeekApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "model": "deepseek-chat",
        "options": {
          "temperature": 0.7,
          "maxTokens": 1500
        }
      },
      "id": "node-llm-onboarding",
      "name": "llm for onboarding",
      "type": "@n8n/n8n-nodes-langchain.lmChatDeepSeek",
      "typeVersion": 1,
      "position": [
        780,
        620
      ],
      "credentials": {
        "deepSeekApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('extract message').item.json.chatId }}"
      },
      "id": "node-memory-main",
      "name": "memory main",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        980,
        0
      ]
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "=onboarding_{{ $('extract message').item.json.chatId }}"
      },
      "id": "node-memory-onboarding",
      "name": "memory onboarding",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        980,
        620
      ]
    },
    {
      "parameters": {
        "jsCode": "const mainOutput = $('main agent').item?.json?.output || '';\nconst onboardingOutput = $('onboarding agent').item?.json?.output || '';\nconst reply = mainOutput || onboardingOutput;\nconst chatId = $('extract message').item.json.chatId;\nreturn [{ json: { reply, chatId } }];"
      },
      "id": "node-merge-reply",
      "name": "merge reply",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1100,
        300
      ]
    },
    {
      "parameters": {
        "chatId": "={{ $json.chatId }}",
        "text": "={{ $json.reply }}",
        "additionalFields": {}
      },
      "id": "node-send-reply",
      "name": "send reply",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1320,
        300
      ],
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "telegram trigger": {
      "main": [
        [
          {
            "node": "extract message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "extract message": {
      "main": [
        [
          {
            "node": "read profile",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "read profile": {
      "main": [
        [
          {
            "node": "has profile?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "has profile?": {
      "main": [
        [
          {
            "node": "main agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "onboarding agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "main agent": {
      "main": [
        [
          {
            "node": "merge reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "onboarding agent": {
      "main": [
        [
          {
            "node": "merge reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "merge reply": {
      "main": [
        [
          {
            "node": "send reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "llm for main": {
      "ai_languageModel": [
        [
          {
            "node": "main agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "llm for onboarding": {
      "ai_languageModel": [
        [
          {
            "node": "onboarding agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "memory main": {
      "ai_memory": [
        [
          {
            "node": "main agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "memory onboarding": {
      "ai_memory": [
        [
          {
            "node": "onboarding agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  }
}