By ยศกร จิรพงศานานุรักษ์, Founder · 27 min read · Smart factory

Factories that already have SCADA or MES often hit the same problem: the data is all there, but it is hard to get out and use. Every time you want to know something you have to ask IT for a report, wait two days for the file, and then find you want to ask one more question. An AI Agent solves exactly this: a person asks in ordinary language, and the system goes and fetches the figures and answers with a chart.
How does it work?
- A person types a question in Thai or English as normal.
- The system converts the question into a command that fetches data from the existing production database.
- It pulls the real figures out, rather than having the model guess them.
- It summarises the result as an answer with a chart, and also says which table and which time period the figures came from.
The key lies in steps three and four. A correctly designed system lets the language model do only the converting of the question and the composing of the answer. The figures must come from the real database every time, and the source must always be referenced so it can be traced and checked.
What can you ask?
- Which line had the lowest OEE yesterday, and what cause lost the most time?
- Which machine had the most repair requests this month, and how does that compare with last month?
- What percentage of this customer's order has been produced, and when is it expected to finish?
- Which shift had abnormally high scrap last week?
- How has energy use per unit produced this month changed from before?
The most important precautions
Never connect a language model to the production database with write permission. What must be set from day one is: use a read-only account; limit visibility to only the tables that are needed; set ceilings on result size and query time so that a single question cannot slow down the production system; and separate permissions by user role in the same way as in the existing system. A shift supervisor should not see cost data just because they asked through a chat box.
A common misunderstanding: thinking you must feed all of the factory's data to the model to learn from first. In fact you do not. A system like this does not keep your data inside the model. It pulls from the live database every time a question is asked, so the data stays where it is and updates automatically.
How to start without wasting time
- Pick the 10 to 20 questions that really are asked most often.
- Check that the data needed to answer those questions already exists and is clean enough.
- Get the first 10 answered accurately before widening the scope.
- Have real users confirm whether each answer is right or wrong, to use for continuous improvement.
The step people overlook most often is the second one. If machine stoppage causes are still recorded as free text that each shift writes differently, no AI can summarise them reliably. Standardising the cause codes is therefore often the work to do first, and it pays off well even before any AI is used.
Frequently asked questions
Will factory data leak outside?
It depends on the design. If you use a model that runs inside your organisation, the data never has to leave the factory. If you choose an external service for higher capability, you should send only the structure of the question and filtered results, not the whole database. This should be agreed clearly in writing before the project starts.
How will we know if the AI answers wrongly?
A good system must show the source of the figures every time, including the table name, the time period and the filter conditions, so a person can trace it back within a few clicks. If the system gives a bare figure without saying where it came from, it should not be used for decisions.
Do you need an MES before you can do this?
Not necessarily. You can start from the data you have, such as tags from SCADA or even production logs already kept in tables, as long as the data has a consistent structure and clear timestamps.
References
- Node.js v24 documentation: SQLite (node:sqlite) (accessed 2026-11-21)
- Node.js v24 documentation: TypeScript (type stripping) (accessed 2026-11-21)
- OWASP GenAI: LLM06:2025 Excessive Agency (accessed 2026-11-21)
- Model Context Protocol specification 2025-06-18: Tools (accessed 2026-11-21)
- Claude API documentation: Tool use overview (accessed 2026-11-21)
- OWASP Community: SQL Injection (accessed 2026-11-21)
- SQLite: Date and Time Functions (accessed 2026-11-21)




