ARTICLE 09 · AI AGENT · 2026-10-21

How AI apps work: LLM, RAG and AI agents, explained through a real app

LLM, RAG and AI agent are much easier to grasp inside an app that is actually running. We open the chat assistant on our own website and follow one question stop by stop: where each word lives, and how each stop can fail.

How AI apps work: LLM, RAG and AI agents, explained through a real app
The short version
  • An LLM writes answers from the language patterns it has learned. It does not know your company's data.
  • RAG searches your documents first and hands only the relevant parts to the model, so the answers are only as good as the documents.
  • An app becomes an AI agent when the model chooses a tool and the system's code carries it out.
  • Thai text and Thailand's PDPA affect both how search works and where the model is allowed to run.

Stop 1: your message, and the instructions you never see

Open the chat page on dnamaker.com and pick "Company knowledge gets lost" in the left-hand list. The message that goes to Dream, our AI assistant, ends with "I want an AI that answers from our own documents." We will follow that message until the answer comes back to your screen.

The message travels with the recent conversation history and a system prompt: instructions the team wrote, which you never see. Dream's prompt says who Dream is, that the conversation runs in four stages from understanding the brief to a proposal, and that Dream must not invent client names or figures.

Before the message reaches the model there is a front gate. The system limits how many messages one network can send, caps model use per day, and answers attempts to extract the system instructions with a refusal that never reaches the model.

What goes wrong at this stop: a system prompt so broad that the AI promises things the company does not do, and an app with no front gate, which meets both runaway costs and prompt injection, text written to make the system drop its instructions.

Stop 2: the LLM writes the answer

An LLM, or large language model, is a program that has learned language patterns from an enormous amount of text. It writes its answer piece by piece, each time picking the piece most likely to come next. Most chat assistants you use every day have an LLM inside.

An LLM is good at language work such as summarizing, translating and asking follow-up questions. It does not have your company's data, does not know what happened after its training ended, and does not know what it does not know. Wrong answers sound as confident as right ones. This is called hallucination.

In Dream, one large language model writes the reply. If you attach an image, a second model first describes it in text. The model also writes a hidden status line, which the system cuts out and uses to fill the four-stage bar at the top and the "Project brief" panel.

What goes wrong at this stop: letting the model answer from memory. It will guess numbers, dates and names. That is why Dream never lets the model write a price.

Stop 3: RAG looks things up before answering

RAG, short for retrieval-augmented generation, means searching for relevant information first and handing it to the model together with the question. The model answers from the document in front of it, like an open-book exam.

Dream's knowledge is a small set the team wrote. Company facts sit in the system prompt, and if you arrive from a solution page, the system attaches that page's content. Dream's voice mode gets a map of the whole site, built from the same files the pages are built from.

A company's documents are too large to attach to every question, so RAG over documents works in three steps. Preparation: split the documents into short passages and turn each one into a set of numbers that stands for its meaning, called an embedding, kept in a vector database. Search: turn the question into numbers the same way and find the passages closest in meaning, so someone who asks about "maternity leave" finds the section titled "leave for childbirth". Answer: hand those passages to the model with an instruction to answer from them and cite the source. A chatbot that works this way is what people call a RAG chatbot.

The search box on our site matches words, which is precise for names and codes. Search by meaning does better with questions written as sentences. Company systems usually combine the two, which is called hybrid search.

What goes wrong at this stop: retrieving the wrong document, such as an old version still in the store or a passage cut mid-table so the header is lost. The answer is then wrong too.

Stop 4: the answer, and the checks before it reaches you

Before the answer appears, a good system has one more checkpoint, called a guardrail. Dream's removes anything that looks like a secret key, and if a reply shows traces of the system instructions, the system throws it away and sends a fallback reply. The chat page also says plainly that Dream is an AI and can make mistakes.

Saying "I don't know" has to be designed. A good RAG system tells the model to say the answer is not in the documents when search finds nothing, and to attach a citation every time. Dream asks follow-up questions when the brief is thin, and writes down its assumptions instead of guessing silently.

What goes wrong at this stop: a guardrail so strict that it refuses ordinary questions, or so loose that it lets through invented answers or data the person asking has no right to see.

Three questions for every AI answer

  1. Where from? Which document and section does it rely on? If the system cannot say, treat the answer as the model's opinion.
  2. How fresh? When was that document last changed, and is it still the version in use?
  3. Who checks? Who owns the content, and does someone have to approve it before it is used?

Stop 5: when the app can call tools, it becomes an AI agent

An app becomes an AI agent when the model decides which tool to call and the system's code carries it out. The mechanism is called tool calling. How an AI agent differs from agentic AI is covered in chapter 5.

Dream has three steps of this kind. For an estimate, the model picks the modules and leaves a marker; code works out the range from a table the team maintains and puts it where the marker was. For the button at the end of a reply, the model can only pick a page key; the address and the page title come from our own copy, so a reply cannot send you off the site. In voice mode, Dream can call tools that open a page or scroll to a section in your browser.

Dream's tools only calculate or take you to a page, so the risk is low. An agent that records leave requests or changes data in an ERP needs a human approval point before it acts.

What goes wrong at this stop: calling a tool with the wrong values, calling it twice, or following instructions hidden in a document.

LLM aloneLLM + RAGAI agent
Knowsgeneral knowledge up to its training dateplus your documentsplus live data from your systems
Can dodraft, summarize, translateanswer from documents with sourcescalculate, look up records, create documents
Fails byinventing factsretrieving an old version, answering beyond the asker's rightscalling the wrong tool, following hidden instructions
Needsa person to check before usedocuments with owners, access rightsnarrow permissions, approval points, a log of every call

Stop 6: Thai language and your data

Thai has no spaces between words, and many models split Thai text into more pieces, or tokens, than English text with the same meaning, so model calls in Thai often cost more. Real work also mixes the two languages, as in "ขอ OT วันเสาร์" (a request for Saturday overtime) or "PO เลขนี้ส่งของยัง" (has this PO shipped yet?), and search by meaning often misses lines like these.

Dream picks its reply language from the characters you type. If you have been chatting in Thai and then type only "Excel", Dream still answers in Thai. For voice, the team pins the language to the visitor's, because when the system was left to guess, short Thai replies were sometimes transcribed as Japanese or Portuguese.

Our chat page tells visitors that conversations are stored, and Dream's model is a cloud service, which suits content already public on the website. HR documents or customer data call for a different decision. Under Thailand's Personal Data Protection Act (PDPA), you need to know at which point personal data leaves the company. If it must not leave, the option is a private LLM running on your own servers. More in private AI options for companies whose data can't leave the building.

What goes wrong at this stop: a system tested only in English, and personal data that travels out with a question without anyone meaning it to.

An auto-parts factory in Chonburi (name and details invented) builds an AI assistant that answers HR questions over LINE OA (LINE Official Account, the business messaging channel many Thai companies use), searching documents on a shared drive. An employee asks: "Can I carry this year's unused annual leave into next year?" The assistant can fail in two ways.

First, the drive holds two versions of the leave policy, and search finds the old one, which says yes. HR has to correct people one by one. The fix: every document set has an owner, the retired version leaves the store on the day the new one is announced, and every answer shows the document name and its last-edited date.

Second, the team loads the whole drive to finish sooner, including management's salary table. A production-line supervisor asks about pay-rise criteria, and the assistant quotes figures from a file he has no right to open. The fix: filter documents by the asker's permissions before the model sees them. An example of this kind of work is on the HR and IT helpdesk agent page.

What to prepare before building a RAG assistant

A company can do these six things on its own, before talking to any developer.

  • The document sources, and which version is the one in use
  • An owner for each document set, who confirms the content is right
  • An update rhythm, and how old versions leave the store
  • Access rights: who can open which document
  • Real questions people ask often, with answers the document owner signs off
  • The personal data in the documents, and whether it may leave the company under the PDPA
For the development team · Chunking, Thai embeddings, hybrid search and testing

Chunking: split by headings and tables instead of character count, because Thai has no spaces between words. Attach document name, edit date and permissions as metadata. Thai embeddings: test multilingual models on the company's real text, including mixed Thai-English and product codes. Hybrid search: combine BM25 over a Thai-segmented index with vector search, then rerank; filter by permission and date at retrieval time. Testing: test the system with real examples from the company's own work before it goes live, agree with the document owners what counts as passing, and test again whenever the model, the prompt or the chunking changes; measure retrieval and answer faithfulness separately. Check retrieved documents for prompt injection too.

DNA MAKER · AI AGENT

How we build RAG assistants and AI agents for Thai companies

DNA Maker starts with the documents before choosing a model. We go through with your team which documents answer the questions people ask most, who owns them and who can see what, and we tell you plainly which parts are not ready yet. Before go-live we test with your real documents and real questions, and during the build you see a demo every week.

We put an approval point before every step where the AI changes data in a system. When data cannot leave the company, we deploy a private LLM on your servers and tie access to your Active Directory. The team you work with is DNA Maker's own; we do not subcontract. Scope and price are fixed before work starts. We have delivered more than 500 projects, for clients that include banks, hospitals and large Thai groups. See AI Agent & Chatbot and Private LLM, or describe your project to Dream.

Software engineering glossary

TermWhat it isA simple exampleWhat executives should ask the development team
LLMA large language model that writes answers piece by pieceDream uses an LLM to write replies on the chat pageDoes this answer come from our documents or from the model's memory?
RAGSearching for relevant information first, then giving it to the model with the questionAn HR assistant looks up the leave policy before answeringWhat does the system say when search finds nothing?
EmbeddingTurning text into a set of numbers that stands for its meaningA question about "maternity leave" finds the "leave for childbirth" sectionHas it been tested on mixed Thai-English text?
Tool callingThe model chooses a tool and the code carries it outDream leaves a marker and code fills in the price rangeWhich tools can change data?
Private LLMA language model running on servers the company controlsAn HR assistant running on the company's own machinesAt which point does personal data leave the company?
Try this tomorrow: pick the one question employees ask HR or IT most often, find the document that answers it, and write three lines: who owns it, when it was last changed and who can open it. If you cannot fill in all three, your first job is to sort out that document set.