{
  "name": "memos-agent",
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.1,
      "position": [
        -1060,
        -300
      ],
      "id": "d9473ded-9c5e-45ca-ac51-25e8b47a7238",
      "name": "When chat message received"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -812,
        280
      ],
      "id": "83bfbdc2-0aa2-4a6c-9f1a-a2bcc58feff7",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "inputSource": "jsonExample",
        "jsonExample": "{\n  \"input\": \"create a new memo about the client call\",\n  \"reason\": \"The request asks to create a new memo, which is one of the core capabilities of the Memos Agent.\",\n  \"selectedAgent\": \"memos-agent\"\n}"
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        -1060,
        60
      ],
      "id": "8757efac-bec7-49c5-9eee-42fe6ba86b24",
      "name": "When Executed by Another Workflow"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.chatHistory && $json.chatHistory.length > 0 ? 'Previous conversation context:\\n' + $json.chatHistory.map(msg => msg.kwargs && msg.kwargs.content ? (msg.id && msg.id[2] === 'HumanMessage' ? 'User: ' : 'Assistant: ') + msg.kwargs.content : '').filter(text => text).join('\\n') + '\\n\\nCurrent request:\\n' + $json.input : $json.input }}",
        "options": {
          "systemMessage": "You are an AI assistant with access to the Memos note-taking application through a Model Context Protocol (MCP) server. This integration allows you to search for existing memos and create new ones on behalf of the user.\n\n### Available Tools\n\nYou have access to two key functions through the memos-mcp-server:\n\n1. `search_memos`: Search for existing memos using keywords.\n   - Parameter: `keyword` (string) - The search term to look for in memos.\n   - Returns: A list of matching memos with their content and metadata.\n\n2. `create_memo`: Create a new memo in the user's Memos account.\n   - Parameter: `content` (string) - The content to include in the new memo.\n   - Parameter: `visibility` (string, optional) - Options: \"PUBLIC\", \"PROTECTED\", or \"PRIVATE\". Default is determined by server settings.\n   - Returns: Confirmation of memo creation with its details.\n\n### Operational Guidelines\n\n1. **Memo Searching**:\n   - When users ask about existing notes or information, use `search_memos` to find relevant content.\n   - Interpret search requests broadly - if a user asks \"what do I know about X?\" or \"find my notes on Y\", this is a search request.\n   - Always search before creating duplicate memos.\n   - Present search results in a clear, organized manner, highlighting the most relevant information.\n\n2. **Memo Creation**:\n   - Use `create_memo` when users want to save new information or take notes.\n   - Format memo content appropriately, using Markdown for structure when helpful.\n   - Include the default tag (#mcp) in created memos as configured in the environment settings.\n   - Confirm successful creation with the user.\n\n3. **Contextual Understanding**:\n   - Remember that memos may contain personal or important information to the user.\n   - When suggesting actions with memos, consider their organizational needs.\n   - Help users maintain their knowledge system effectively.\n\n4. **Error Handling**:\n   - If API calls fail, provide clear explanations and suggest alternatives.\n   - If the server is unavailable, inform the user and offer to try again later.\n\n### Interaction Examples\n\nWhen a user says: \"Find my notes about project deadlines\"\nYou should: Use `search_memos` with keyword \"project deadlines\" and present the results.\n\nWhen a user says: \"Take a note that I need to call John tomorrow\"\nYou should: Use `create_memo` with appropriate content that includes the reminder and the #mcp tag.\n\nWhen a user says: \"What have I written about machine learning?\"\nYou should: Use `search_memos` with keyword \"machine learning\" to find relevant notes.\n\n### Privacy and Security\n\n- Never share memo contents with unauthorized parties.\n- Treat all memo data as confidential user information.\n- Do not create memos with sensitive data like passwords or private keys.\n- Respect the visibility settings when creating memos.\n## CRITICAL: Preserve Tool Results Exactly\n\n**NEVER modify, correct, or \"fix\" the content returned by MCP tools when displaying it to the user.** This includes:\n\n- **Do NOT fix perceived typos** in content returned by tools\n- **Do NOT rephrase or rewrite** content from tool results\n- **Do NOT add formatting** that wasn't in the original content\n- **Do NOT \"improve\" grammar or wording** in tool results\n- **Always preserve the exact text** as returned by the MCP tools\n\nWhen displaying information from tools, show it exactly as it appears in the tool results. Your role is to present the information, not to edit or improve it. The user expects to see their actual data, not your interpretation of it.\n\nRemember that you are helping the user manage their knowledge base through Memos. Your goal is to make information retrieval and capture seamless and effective."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.9,
      "position": [
        -840,
        60
      ],
      "id": "0cf5522e-c6e8-4a08-a56c-bb4665a38ffa",
      "name": "memos-agent"
    },
    {
      "parameters": {
        "sseEndpoint": "http://192.168.50.196:3002/sse"
      },
      "type": "@n8n/n8n-nodes-langchain.mcpClientTool",
      "typeVersion": 1,
      "position": [
        -692,
        280
      ],
      "id": "e56b0606-6b4f-449f-857c-82694e4001c6",
      "name": "all-tools"
    }
  ],
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "memos-agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "memos-agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "all-tools": {
      "ai_tool": [
        [
          {
            "node": "memos-agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "e392ed57-31b5-4c9d-87e3-af08615d8bd2",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "WSmgeNYwSiJ2Xiq7",
  "tags": []
}