AutomationFlowsAI & RAG › AI Legal Assistant: Legal Q&A with Document Retrieval

AI Legal Assistant: Legal Q&A with Document Retrieval

Original n8n title: 🧑‍⚖️ AI Legal Assistant Agent — Ai-powered Legal Q&a with Document Retrieval

ByAutomate With Marc @marconi on n8n.io

🧑‍⚖️ AI Legal Assistant Agent — AI-Powered Legal Q&A with Document Retrieval

Event trigger★★★☆☆ complexityAI-powered11 nodesAgentOpenAI ChatOpenAI EmbeddingsPinecone Vector StoreTelegramTelegram TriggerMemory Buffer Window
AI & RAG Trigger: Event Nodes: 11 Complexity: ★★★☆☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #5294 — we link there as the canonical source.

This workflow follows the Agent → OpenAI Embeddings recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "rPicfavvntizpQkM",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Legal Assistant Agent",
  "tags": [],
  "nodes": [
    {
      "id": "81b14e7a-0dde-4dd3-aa1b-943c1857903d",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        220,
        0
      ],
      "parameters": {
        "text": "={{ $json.message.text }}",
        "options": {
          "systemMessage": "You are a helpful legal assistant. Your task is to answer legal questions of the users by referring to the Pinecone Vector Database \"Legal Contract Library\" to get an accurate answer. \n#Rule\nDo not make up facts, if you do not have the right information, you may say so."
        },
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "53d344e5-773b-432a-8940-00a9b6814ee8",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        80,
        240
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "38b9de84-bfee-4d66-b22a-f95bcd78b9a6",
      "name": "Embeddings OpenAI",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        520,
        360
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "be801891-2ac9-4871-b54b-72491eb9b962",
      "name": "Legal Contract Library",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        360,
        240
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "options": {},
        "toolName": "Redacted",
        "pineconeIndex": {
          "__rl": true,
          "mode": "id",
          "value": "Redacted"
        },
        "toolDescription": "Extract, contracts, legal policies and relevant regulatory documents here."
      },
      "credentials": {
        "pineconeApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "8cbbb27e-5c31-4c8e-93a1-7515b28649b6",
      "name": "Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        820,
        0
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "c664b9b0-cf1b-454c-b943-adcc3f0a8de5",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -200,
        0
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f4fa00fd-5e18-4a81-8263-b3bf2d52cb9e",
      "name": "Simple Memory1",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        240,
        240
      ],
      "parameters": {
        "sessionKey": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 10
      },
      "typeVersion": 1.3
    },
    {
      "id": "f2aff94c-ad46-4759-90f0-368d420219e2",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -340,
        -160
      ],
      "parameters": {
        "width": 340,
        "height": 700,
        "content": "Telegram Message Trigger"
      },
      "typeVersion": 1
    },
    {
      "id": "4eb385e9-5caf-46f3-97a3-bac95c210c78",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        20,
        -160
      ],
      "parameters": {
        "color": 3,
        "width": 720,
        "height": 700,
        "content": "Legal Asssistant AI Agent"
      },
      "typeVersion": 1
    },
    {
      "id": "252a59c6-90aa-4ca4-9a4e-2905b69cc984",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        760,
        -160
      ],
      "parameters": {
        "color": 4,
        "width": 280,
        "height": 700,
        "content": "Telegram Output"
      },
      "typeVersion": 1
    },
    {
      "id": "beaef1c7-48cb-4f35-a0d7-b5819a0e99fe",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1180,
        -160
      ],
      "parameters": {
        "color": 6,
        "width": 820,
        "height": 1180,
        "content": "\ud83e\uddd1\u200d\u2696\ufe0f Legal Assistant Agent \u2014 AI-Powered Legal Q&A with Document Retrieval\nCategory: LegalTech / AI Agent / RAG / Chatbot\n\nDescription:\nThis no-code AI agent acts as a legal assistant chatbot that can answer user queries by retrieving information from a pre-indexed legal document library. It\u2019s powered by OpenAI + Pinecone + Telegram and designed for law firms, compliance teams, or anyone who needs instant answers from contracts, policies, or regulatory documents.\n\nFor more of such builds and step-by-step video tutorial, check out:\nhttps://www.youtube.com/@Automatewithmarc\n\n\ud83d\udd0d How it Works:\n\nTelegram Trigger \u2013 Starts when a user sends a message via Telegram.\n\nAI Agent (GPT-4o) \u2013 Uses a retrieval-augmented generation (RAG) setup to understand the question and pull relevant context.\n\nPinecone Vector Store \u2013 Searches across a vectorized legal contract library for relevant clauses or documents.\n\nOpenAI Embeddings \u2013 Converts uploaded documents into vector embeddings for efficient search.\n\nMemory Buffer \u2013 Maintains conversation flow and context for follow-up questions.\n\nTelegram Response \u2013 Sends the final AI-generated answer directly to the user.\n\n\ud83c\udfaf Use Cases:\n\nIn-house legal teams automating internal policy Q&A\n\nLaw firms building client-facing legal bots\n\nStartups offering legal tech services with document-based queries\n\nCompliance teams monitoring contract terms and obligations\n\n\u2705 Key Features:\n\nReal-time legal Q&A via Telegram\n\nPinecone + OpenAI-powered vector search\n\nRetrieval-Augmented Generation (RAG) setup\n\nFactual, memory-aware assistant with fallback if info is unavailable\n\nFully customizable and extendable\n\n\u2699\ufe0f Setup Instructions:\n\nConnect OpenAI, Pinecone, and Telegram credentials\n\nUpload your contracts or policy docs into Pinecone\n\nCustomize the system prompt or expand document sources as needed\n\nActivate and test via Telegram\n\nThis workflow is a solid foundation for any AI-powered legal assistant or chatbot solution\u2014highly relevant for modern LegalOps and knowledge management teams."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "0cec767c-2903-4bfb-999a-5668fcadd39d",
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory1": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Legal Contract Library",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Legal Contract Library": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

🧑‍⚖️ AI Legal Assistant Agent — AI-Powered Legal Q&A with Document Retrieval

Source: https://n8n.io/workflows/5294/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

Parents smart bot. Uses telegramTrigger, agent, toolWorkflow, toolHttpRequest. Event-driven trigger; 27 nodes.

Telegram Trigger, Agent, Tool Workflow +11
AI & RAG

AI. Uses lmChatOpenAi, toolWorkflow, telegram, telegramTrigger. Event-driven trigger; 27 nodes.

OpenAI Chat, Tool Workflow, Telegram +7
AI & RAG

Chatbot. Uses googleDrive, vectorStoreSupabase, googleDriveTrigger, documentDefaultDataLoader. Event-driven trigger; 23 nodes.

Google Drive, Supabase Vector Store, Google Drive Trigger +12
AI & RAG

This workflow is built for e-commerce businesses, retail store owners, and entrepreneurs who want to provide intelligent customer support and seamless order taking through Telegram. If you're tired of

Telegram Trigger, Telegram, OpenAI +7
AI & RAG

Transform your email workflow with this intelligent automation that drafts professional emails through Telegram commands using AI and contact retrieval. Key Features

Pinecone Vector Store, OpenAI Embeddings, Document Default Data Loader +6