What you need
The agent in this guide does one job: it answers questions about your documents. An AI agent here means a program that gets a question, searches your documents for the right passages by itself and writes an answer with a language model.
You need a computer with macOS, Windows or Linux, the Node.js runtime version 20.19 to 24.x (n8n runs in it), a Telegram account and, for step 4, a server with a domain and an HTTPS address.
Ollama runs the model: it is a program for open models on your own computer or server, under the MIT license. n8n is distributed under the Sustainable Use License (fair-code): you may install it yourself and change it, but you may not resell it as a cloud service.
We base the guide on n8n because it has ready nodes for Telegram. If you prefer the visual builder Flowise under the Apache 2.0 license, the first three steps work the same way in it; details are on the page on the Flowise agent.
We do not promise a time in hours: it depends on your computer and the model download speed. In difficulty, it is a task for one evening; you need no programming, and the terminal commands are given below word for word.
Step 1: installation
You install two programs: Ollama for the model and n8n for the agent. Both run on your computer, and your data goes nowhere.
1. Download Ollama from ollama.com/download and install it like any other program. On Linux, start the model server with the command ollama serve if it is not running yet.
2. Install Node.js version 20.19 to 24.x: the n8n documentation requires it.
3. Install Docker: the n8n documentation requires it even when you run n8n through npm. Then start n8n with the command npx n8n, or install it permanently with npm install n8n -g and then n8n start. From version 3.0, n8n will ship only in Docker; this path is described in the n8n guide.
4. Open this address in your browser: http://localhost:5678: it is the n8n interface on your computer.
The first three steps run on one computer. You need to move to a server only for Telegram. What else n8n can do is covered on the page about the n8n agent.
Step 2: the model
A model is a file with a trained neural network that writes the answers. Ollama downloads a model with one command and serves it to other programs at http://localhost:11434.
1. Download the answer model with the command ollama pull qwen3:8b. This is Qwen 3, an open model under the Apache 2.0 license; the file is 5.2 GB. On a weak computer, take qwen3:4b, which is 2.5 GB.
2. Download the model for document search: ollama pull nomic-embed-text. It turns text into vectors, sets of numbers that n8n uses to find passages close in meaning to the question.
3. Test the model in the terminal: run ollama run qwen3:8b and ask a question. To leave the chat, type /bye.
4. In n8n, create Ollama credentials. If n8n cannot see Ollama, the documentation advises writing 127.0.0.1 instead of localhost. In the “Base URL” field, leave http://localhost:11434.
Another open model, under the MIT license, is DeepSeek R1; its weights were published on 20 January 2025. Switch models if Qwen’s answers do not suit you on your questions.
Step 3: the documents
The agent answers from your documents through RAG: before it answers, it searches the base for matching passages and writes the answer from them. First you build a workflow, a chain of nodes in n8n, that loads documents into the base.
1. Create a workflow and add the n8n Form Trigger node. Add a field of the “File” type to the form.
2. Add the “Simple Vector Store” node with the “Insert Documents” operation.
3. Connect to the store an “Embeddings Ollama” node with the nomic-embed-text model and a “Default Data Loader” node with the “Binary” data type. The “Simple” mode splits the text into chunks by itself.
4. Press “Execute Workflow”: n8n opens the form, and you upload a document into it.
5. Create a second workflow with the Chat Trigger and AI Agent nodes. Connect an “Ollama Chat Model” with the qwen3:8b model to the agent, and as a tool the same “Simple Vector Store” in the “Retrieve Documents (As Tool for AI Agent)” mode with the same store key (“Memory Key”).
6. In the second workflow, connect the same nomic-embed-text model to the store: the n8n documentation requires one model for loading and for search.
7. In the agent’s parameters, open “System Message” and write the rules: answer only from the documents, and if they have no answer, say so.
Simple Vector Store keeps the chunks only in memory: after n8n restarts, you will have to load the documents again. For constant use, n8n recommends another vector store; for your first agent, this one is enough.
Step 4: Telegram
Telegram sends messages to n8n only at an HTTPS address. The bot will not work on a home computer: n8n must run on a server with a domain and a certificate, and the WEBHOOK_URL variable holds its HTTPS address.
1. In Telegram, send the /newbot command to @BotFather, set the bot’s name and a username that ends in bot. BotFather will send you a token: keep it like a password and never show it to anyone.
2. In n8n, create Telegram credentials and paste the token into the “Access Token” field.
3. In the second workflow, replace Chat Trigger with “Telegram Trigger” with the “Message” event.
4. In the AI Agent node, in the “Prompt (User Message)” field, choose “Define below” and insert the message text from Telegram Trigger.
5. After the agent, add a Telegram node: resource “Message”, operation “Send Message”. Pass the chat number from Telegram Trigger to “Chat ID”, and the agent’s answer to “Text”.
Telegram keeps one webhook per bot. For tests, create a second bot; otherwise a test run will override the working one. A bot for customers with booking and handover to a person is covered on the page about a Telegram agent.
If customers write to the bot, the chats will hold their personal data. Under 152-FZ, Russia’s personal data law, data of Russian citizens is stored in databases in Russia, and before a transfer abroad the operator files a notice with Roskomnadzor, the data regulator, so rent the server for such a bot in Russia. More details are on the page on data security.
Step 5: checking the answers
An agent that confidently gives false answers does more harm than no agent at all. Test it before you give people the link to the bot.
1. Write 10 questions whose answers are definitely in the documents, and 3 questions whose answers are not there.
2. Ask them in the n8n chat and compare the answers with the documents. For questions with no answer, the agent must say it does not know.
3. Turn on the “Return Intermediate Steps” parameter in the agent: the agent’s steps will appear in the answer, and you will see whether it searched the document base.
4. If the agent makes things up, add a ban to “System Message” and lower the model’s “Sampling Temperature”. According to the n8n documentation, a high temperature raises the risk of made-up answers.
5. Repeat the same set of questions after every edit and every document update.
How to build checks for an agent that works with customers is covered on the page on testing an agent.