1 · What is an LLM?
An LLM (Large Language Model) is a program that does one thing extremely well: guess the next word. Give it the start of a sentence, it predicts what word probably comes next, picks one, and repeats. That's the entire trick.
The "large" part is scale — billions of parameters trained on billions of pages. The "model" part is a math function. Together: a function that has read so much text that its guesses for "what comes next" sound like a human wrote them.
It cannot truly think, plan, or remember anything beyond the words you put in front of it right now. Once you understand that, every other behavior makes sense.
LLM (Large Language Model — โมเดลภาษาขนาดใหญ่) คือโปรแกรมที่ทำสิ่งเดียวเก่งมาก คือ เดาคำถัดไป ให้จุดเริ่มของประโยคไป มันจะเดาว่าคำต่อไปน่าจะเป็นอะไร เลือกหนึ่งคำ แล้วทำซ้ำ แค่นั้นเอง
คำว่า "ใหญ่" คือเรื่องสเกล — พารามิเตอร์เป็นพันล้าน ฝึกจากเอกสารพันล้านหน้า "โมเดล" คือฟังก์ชันคณิตศาสตร์ รวมกันคือฟังก์ชันที่อ่านข้อความมาเยอะจนคำเดาเหมือนคนเขียน
มันคิดเองไม่ได้จริง ๆ จำอะไรนอกหน้าจอตอนนี้ไม่ได้ พอเข้าใจจุดนี้ พฤติกรรมทุกอย่างของมันก็จะดูสมเหตุสมผลขึ้นเอง
大语言模型 (LLM) 其实就做一件事,做得特别好:猜下一个词。给它半句话,它预测下一个词最可能是什么,选一个,然后重复。整个魔术就这么简单。
"大" 指规模 — 几十亿参数,训练于几十亿页文本。"模型" 是数学函数。合起来就是一个读了海量文本、猜词像人类写的函数。
它不会真正思考、规划,或记住屏幕之外的任何事。理解了这一点,它后面所有的行为都合理了。
🎬 Watch it generate
Each step the model produces a probability for every possible next token. We pick (often the top one), append it, and repeat. That's "generation".
2 · Words Become Tokens
The model doesn't read letters or words — it reads tokens. A token is roughly a chunk of 3-5 characters, sometimes a whole short word, sometimes a fragment. "Hello, friend!" might be 4 tokens; "internationalization" might be 5.
Why care? Two reasons:
- Cost. APIs charge per token in and out. A long Thai or Chinese document tokenizes differently than English — usually more tokens for the same idea, because non-Latin scripts are split finer.
- Limits. Every model has a context window measured in tokens (4k, 32k, 128k, 1M). When you "give it your file", you're spending tokens.
โมเดลไม่ได้อ่านตัวอักษรหรือคำ — มันอ่าน โทเคน (tokens) โทเคนคือชิ้นข้อความประมาณ 3-5 ตัวอักษร บางทีเป็นคำสั้น ๆ บางทีเป็นเศษคำ "Hello, friend!" อาจเป็น 4 โทเคน "internationalization" อาจเป็น 5
ทำไมต้องสนใจ?
- ค่าใช้จ่าย API คิดเงินตามจำนวนโทเคนเข้า-ออก ภาษาไทยหรือจีนแบ่งโทเคนละเอียดกว่า ภาษาอังกฤษ เนื้อหาเดียวกันใช้โทเคนมากกว่า
- ขีดจำกัด ทุกโมเดลมี context window นับเป็นโทเคน (4k, 32k, 128k, 1M) เมื่อ "ส่งไฟล์ให้มัน" คุณกำลังใช้โทเคน
模型不读字母或单词 — 它读 token。一个 token 大概 3-5 个字符,有时是个短词,有时是词的一部分。"Hello, friend!" 可能是 4 个 token,"internationalization" 可能是 5 个。
为什么要关心?两个原因:
- 成本:API 按输入输出 token 计费。长泰文或中文文档切分方式跟英文不同,相同内容通常用 更多 token,因为非拉丁文字切得更细。
- 上限:每个模型都有 上下文窗口,按 token 计算 (4k, 32k, 128k, 1M)。当你 "给它文件" 时,你就在花 token。
✂️ Try the tokenizer
A simplified tokenizer (real ones use byte-pair encoding). Notice how Thai and Chinese characters split smaller — every character tends to be its own token.
3 · The Context Window — Three Layers
Every time you send a message to a model, the model sees a stack of three things, in this order:
- System prompt — the rules, persona, and instructions. Set once at startup.
- Conversation history — all previous user/AI turns this session.
- Your new message — what you just typed.
The model has no memory between sessions. Everything it knows about who it is and what it's doing comes from this stack — re-sent on every turn. When the stack exceeds the context window, oldest history gets dropped or summarized.
ทุกครั้งที่ส่งข้อความให้โมเดล มันจะเห็น กอง 3 ชั้น ตามลำดับนี้:
- System prompt — กฎ บุคลิก คำสั่ง โหลดครั้งเดียวตอนเริ่ม
- ประวัติการสนทนา — รอบ user/AI ที่ผ่านมาในเซสชันนี้
- ข้อความใหม่ของคุณ — ที่เพิ่งพิมพ์
โมเดลไม่มีความจำข้ามเซสชัน ทุกอย่างที่มันรู้ว่าตัวเองเป็นใคร ทำอะไร มาจากกองนี้ ส่งซ้ำทุกครั้งที่คุยรอบใหม่ พอกองล้น context window จะถูกตัดหรือสรุปจากของเก่าสุด
每次给模型发消息,它看到的是 三层堆叠,按这个顺序:
- 系统提示词 — 规则、人设、指令。启动时设一次。
- 对话历史 — 这次会话里所有的对话轮次。
- 你的新消息 — 你刚打的那一句。
模型没有跨会话的记忆。它知道自己是谁、在干什么的所有信息,都来自这个堆 — 每轮都会重新发送。堆超出上下文窗口时,最老的历史会被丢弃或总结。
📚 The stack, every turn
↑ loaded from
system_prompts/main.mdAI: Yes — a quiet room facing the garden, 1,200 baht…
↑ from
logs/conversations/ — rolling buffer↑ live from LINE / web chat / SMS
Out of 8,192 tokens (a typical small-model window).
4 · Running a Model Locally
Why local? Three reasons that matter for a small business:
- Privacy. Customer chats, bookings, prices, receipts never leave your laptop. No third party has the data.
- Cost. One-time hardware spend. No per-token bills. A model that handles 200 customer messages a day costs ฿0 in API fees.
- Offline. Works during the 4G outage at the night market.
The trade-off is quality and speed — a 7B-parameter local model is roughly as smart as GPT-3.5, not GPT-4. Plenty for a guesthouse FAQ, a vendor's product descriptions, or a coffee shop menu helper. Not enough for legal contracts.
The fastest path: install Ollama, pull a model, run it.
# Mac / Linux / Windows: install once, then: ollama pull qwen2.5:7b ollama run qwen2.5:7b # Or via API on localhost:11434 curl http://localhost:11434/api/chat -d '{ "model": "qwen2.5:7b", "messages": [{"role":"user","content":"สวัสดี"}] }'
ทำไมต้องในเครื่อง? 3 เหตุผลสำคัญสำหรับธุรกิจขนาดเล็ก:
- ความเป็นส่วนตัว ข้อความลูกค้า การจอง ราคา ใบเสร็จ ไม่ออกจากเครื่องคุณเลย ไม่มีบุคคลที่สามได้ข้อมูล
- ต้นทุน จ่ายครั้งเดียวที่ฮาร์ดแวร์ ไม่มีค่าโทเคน โมเดลที่ตอบลูกค้าวันละ 200 ครั้งเสีย ฿0 ค่า API
- ออฟไลน์ ใช้ได้ตอน 4G หลุดที่ตลาดกลางคืน
ข้อเสียคือคุณภาพและความเร็ว — โมเดลในเครื่อง 7B พารามิเตอร์ ฉลาดประมาณ GPT-3.5 ไม่ใช่ GPT-4 พอใช้กับ FAQ เกสต์เฮาส์ คำอธิบายสินค้า เมนูร้านกาแฟ ยังไม่พอสำหรับสัญญากฎหมาย
ทางที่ง่ายที่สุด: ติดตั้ง Ollama ดาวน์โหลดโมเดล แล้วรัน
# Mac / Linux / Windows: ติดตั้งครั้งเดียว แล้ว: ollama pull qwen2.5:7b ollama run qwen2.5:7b # หรือผ่าน API ที่ localhost:11434 curl http://localhost:11434/api/chat -d '{ "model": "qwen2.5:7b", "messages": [{"role":"user","content":"สวัสดี"}] }'
为什么要本地?对小生意来说,三个理由:
- 隐私:客户聊天、预订、价格、收据,永远不离开你的电脑。第三方拿不到数据。
- 成本:一次性硬件支出,没有 token 账单。一个每天处理 200 条客户消息的模型,API 费用 ¥0。
- 离线:夜市 4G 断网时也能用。
代价是质量和速度 — 7B 参数的本地模型大约相当于 GPT-3.5,而不是 GPT-4。够用于民宿 FAQ、商品描述、咖啡店菜单助手,不够用于法律合同。
最快路径:安装 Ollama,拉模型,运行。
# Mac / Linux / Windows:安装一次,然后: ollama pull qwen2.5:7b ollama run qwen2.5:7b # 或者通过 localhost:11434 的 API: curl http://localhost:11434/api/chat -d '{ "model": "qwen2.5:7b", "messages": [{"role":"user","content":"你好"}] }'
📊 Pick a model size
RAM needed (4-bit quantized) vs how clever it feels:
Rule of thumb: if your laptop has 16 GB RAM, run a 7B-8B model. 32 GB unlocks 13B-14B. Most small businesses don't need anything bigger.
5 · The Startup Prompt — Consistency by Default
A model with no system prompt is a brilliant new hire on day one with no training. It knows English, it can write — but it doesn't know your prices, your tone, your cancellation policy, or which language to reply in. Every customer gets a slightly different answer.
The fix is the startup prompt: one document the agent loads before any conversation and silently re-sends with every turn. It bakes in:
- Identity — "You are Khun Mali, host at Krueng Guesthouse."
- Knowledge — prices, hours, addresses, policies, FAQ.
- Tone — warm, brief, never pushy.
- Language rule — always reply in the guest's language.
- Boundaries — what to refuse, what to escalate to a human.
Toggle the switch below to feel the difference:
โมเดลที่ไม่มี system prompt เหมือนพนักงานใหม่วันแรกที่ ยังไม่ได้รับการอบรม เลย พูดอังกฤษได้ เขียนได้ แต่ไม่รู้ราคาคุณ โทนคุณ นโยบายยกเลิก หรือควรตอบภาษาอะไร ลูกค้าแต่ละคนเลยได้คำตอบไม่เหมือนกัน
วิธีแก้คือ startup prompt: เอกสารหนึ่งฉบับที่ agent โหลดก่อนเริ่มคุย และส่งซ้ำเงียบ ๆ ทุกรอบ บรรจุ:
- ตัวตน — "คุณคือพี่มะลิ เจ้าของเกสต์เฮาส์ครุงค์"
- ความรู้ — ราคา เวลาทำการ ที่อยู่ นโยบาย FAQ
- โทน — อบอุ่น สั้น ไม่ตื๊อ
- กฎภาษา — ตอบตามภาษาแขกเสมอ
- ขอบเขต — เรื่องไหนปฏิเสธ เรื่องไหนส่งต่อให้คน
กดสวิตช์ด้านล่างดูความต่าง:
没有系统提示词的模型,像入职第一天的新员工 — 没受过任何培训。它会英文、会写字,但不知道你的价格、你的语气、你的退订政策,也不知道该用哪种语言回复。每位客户拿到的答案都略不一样。
解法是 启动提示词:agent 在开始对话之前加载的一份文档,每一轮都悄悄重发。里面写明:
- 身份 — "你是马丽姐,清迈 Krueng 民宿的主人。"
- 知识 — 价格、营业时间、地址、政策、常见问题。
- 语气 — 温暖、简短、不催促。
- 语言规则 — 始终用客人的语言回复。
- 边界 — 哪些要拒绝、哪些要转人工。
切换下面的开关感受一下区别:
Where does this file live?
In a folder next to your agent — typically system_prompts/main.md. The agent reads it on startup, holds it in memory, and prepends it to every model call. Changing the file and restarting the agent is how you "retrain" it — no machine learning required. See section 8 for the full folder layout.
ไฟล์นี้อยู่ที่ไหน?
ในโฟลเดอร์ข้าง ๆ agent ของคุณ — มักจะเป็น system_prompts/main.md agent อ่านไฟล์นี้ตอนเริ่ม เก็บไว้ในหน่วยความจำ แล้วใส่ไว้หน้าทุกการเรียกโมเดล แก้ไฟล์แล้วรีสตาร์ท agent = "ฝึก" มันใหม่ โดยไม่ต้อง ML เลย ดูโครงโฟลเดอร์เต็มในหัวข้อ 8
这个文件放哪?
放在你的 agent 同级文件夹里 — 通常是 system_prompts/main.md。agent 启动时读取,载入内存,然后在每次模型调用前拼接。改文件、重启 agent,就是 "重新培训" — 不需要任何机器学习。完整目录布局见第 8 节。
6 · Workflows — Telling the Agent What to Do
A system prompt sets who the agent is. Workflows define what it does. A workflow is a named sequence of steps the agent follows when a specific kind of request comes in. You write each workflow as its own short markdown file the agent can look up.
Click a workflow below to see the steps:
System prompt บอกว่า agent เป็นใคร Workflow บอกว่า มันทำอะไร Workflow คือลำดับขั้นที่ agent ทำเมื่อเจอคำถามประเภทหนึ่ง เขียนเป็นไฟล์ markdown สั้น ๆ ให้ agent เปิดดูได้
กดที่ workflow ด้านล่างเพื่อดูขั้นตอน:
系统提示词决定 agent 是谁。工作流决定它 做什么。工作流就是 agent 遇到某类请求时走的一串带名字的步骤。每个工作流写成一个简短的 markdown 文件,让 agent 查阅。
点击下面的工作流看步骤:
How the agent picks a workflow
The system prompt usually contains a small router: "If the guest asks about availability or price → use workflows/booking.md. If they ask for food or sights → workflows/recommend.md." The model reads the right file and follows it. Adding a new workflow is just a new markdown file plus one new line in the router.
agent เลือก workflow ยังไง
ใน system prompt จะมีตัว router เล็ก ๆ: "ถ้าแขกถามเรื่องห้องว่างหรือราคา → ใช้ workflows/booking.md ถ้าถามเรื่องอาหารหรือสถานที่ → workflows/recommend.md" โมเดลอ่านไฟล์ที่เกี่ยวข้องแล้วทำตาม เพิ่ม workflow ใหม่ = ไฟล์ใหม่ + 1 บรรทัดใน router
agent 怎么挑工作流
系统提示词通常有一个小 router:"客户问空房或价格 → 用 workflows/booking.md。问吃喝或景点 → workflows/recommend.md。" 模型读相应文件,照着做。增加新工作流 = 加一个 markdown 文件 + router 加一行。
7 · Tools & APIs — Giving the Model Hands
By itself, an LLM only outputs text. It can't read your calendar, send a LINE message, look up the weather, or charge a credit card. Tools (also called functions or APIs) fix this. You describe a function in JSON; the model decides when to call it; your code runs the function and sends the result back; the model uses the result to write its reply.
This is the agent loop:
ตัว LLM เองออกได้แค่ข้อความ อ่านปฏิทินคุณไม่ได้ ส่ง LINE ไม่ได้ เช็คอากาศไม่ได้ รูดบัตรเครดิตไม่ได้ tools (เรียกอีกชื่อว่า function หรือ API) เข้ามาแก้ตรงนี้ คุณอธิบาย function ด้วย JSON โมเดลตัดสินใจว่าจะเรียกเมื่อไหร่ โค้ดของคุณรัน function แล้วส่งผลกลับ โมเดลใช้ผลนั้นเขียนคำตอบ
นี่คือ agent loop:
LLM 本身只输出文字 — 读不了你的日历、发不了 LINE、查不了天气、也刷不了信用卡。工具(也叫 函数 或 API)就是为了解决这个。你用 JSON 描述一个函数;模型决定何时调用;你的代码运行函数,把结果传回;模型用结果写回复。
这就是 agent loop:
Example tool definition
A guesthouse agent might have these three:
check_availability
{ "name": "check_availability", "description": "Returns rooms free for a date range.", "parameters": { "check_in": "YYYY-MM-DD", "check_out": "YYYY-MM-DD", "guests": "integer" } }
create_booking
{ "name": "create_booking", "parameters": { "room_id", "guest_name", "check_in", "check_out" } }
send_line_message
{ "name": "send_line_message", "parameters": { "to", "text" } }
What this unlocks
Three guesthouse tools and a system prompt are enough to handle 80% of incoming messages: check the calendar, hold a room, send the booking confirmation on LINE. Add get_weather, currency_convert, find_taxi and you've covered most of the rest. Tools turn a chatbot into an employee.
เปิดอะไรเพิ่ม?
tools 3 ตัว + system prompt หนึ่งฉบับ พอจัดการข้อความเข้า 80% — เช็คปฏิทิน จองห้อง ส่งคอนเฟิร์มทาง LINE เพิ่ม get_weather currency_convert find_taxi ก็ครอบคลุมที่เหลือเกือบหมด tools เปลี่ยน chatbot ให้กลายเป็นพนักงาน
这能解锁什么?
三个民宿工具 + 一份系统提示词,足够应对 80% 的来信 — 查日历、留房、用 LINE 发确认。加上 get_weather、currency_convert、find_taxi,剩下的也基本都能搞定。工具让 chatbot 变成员工。
8 · Folders, Names & Evolution
Everything we've covered — system prompts, workflows, tools — lives as files on disk. The shape of those files is itself instruction. An AI scans your folder before it scans your contents; a clear tree tells it what you have before it has read a single line.
Why naming is documentation
A file called cs_FINAL_v3_REAL_2.md tells a future reader (human or AI) absolutely nothing about what's inside. A file called workflows/booking.md says it all in two words: it lives under workflows, and it handles bookings. The model can guess what's inside without opening it — and more importantly, it can guess where to look when a new request comes in.
Think like REST
The cleanest mental model I know for naming AI files is to borrow from REST URLs. Good REST paths read top-down, general to specific: /customers/123/orders/456. Same idea for your folders:
- Plural for collections, singular for instances.
workflows/holds many;workflows/booking.mdis one. - Nouns, not verbs.
prompts/greeting.md, notdo_greeting.md. The verb is what the agent does with the file. - Predictable hierarchy. If
prompts/sales/objection_handling.mdexists, the AI can guess thatprompts/sales/closing.mdprobably does too. Symmetry is a discoverability tool. - Lowercase, underscores or hyphens, no spaces. URL-safe and shell-safe.
shipping_policy.mdworks everywhere;Shipping Policy (final).mdbreaks half your tooling. - The path is the documentation. Reading
tools/payments/refund.jsontells you the file is a tool definition, lives in the payments domain, and handles refunds. You haven't opened it yet, but you already know what's inside.
How files evolve
Don't pre-build the perfect tree. Start with one file. Split when it stops fitting in your head.
ทุกอย่างที่เราพูดมา — system prompt, workflow, tool — อยู่เป็นไฟล์ในเครื่อง รูปร่างของไฟล์เหล่านั้นเป็นคำสั่งในตัวมันเอง AI สแกนโฟลเดอร์ก่อนสแกนเนื้อหา ต้นไม้ที่ชัดเจนบอก AI ว่าคุณมีอะไรก่อนที่มันจะอ่านบรรทัดแรกด้วยซ้ำ
ทำไมการตั้งชื่อ = เอกสาร
ไฟล์ชื่อ cs_FINAL_v3_REAL_2.md ไม่บอกอะไรเลยว่าข้างในคืออะไร ไฟล์ชื่อ workflows/booking.md บอกหมดในสองคำ — อยู่ใต้ workflows จัดการการจอง โมเดลเดาเนื้อในได้โดยไม่ต้องเปิด และที่สำคัญกว่าคือเดา ว่าควรไปดูที่ไหน เมื่อมีคำขอใหม่
คิดแบบ REST
วิธีคิดเรื่องการตั้งชื่อไฟล์ AI ที่สะอาดที่สุดคือยืมจาก REST URL path ของ REST ที่ดีอ่านจากบนลงล่าง จากกว้างไปแคบ: /customers/123/orders/456 ใช้ความคิดเดียวกันกับโฟลเดอร์:
- พหูพจน์สำหรับกลุ่ม เอกพจน์สำหรับชิ้น
workflows/มีหลายอันworkflows/booking.mdมีอันเดียว - คำนาม ไม่ใช่กริยา
prompts/greeting.mdไม่ใช่do_greeting.mdกริยาคือสิ่งที่ agent ทำ กับ ไฟล์ - ลำดับชั้นที่เดาได้ ถ้ามี
prompts/sales/objection_handling.mdAI เดาได้ว่าprompts/sales/closing.mdน่าจะมีด้วย ความสมมาตรช่วยให้ค้นพบง่าย - ตัวพิมพ์เล็ก, underscore หรือ hyphen, ห้ามเว้นวรรค ปลอดภัยกับ URL และ shell
shipping_policy.mdใช้ได้ทุกที่Shipping Policy (final).mdพังเครื่องมือคุณครึ่งหนึ่ง - path คือเอกสาร อ่าน
tools/payments/refund.jsonก็รู้ว่าเป็น tool อยู่ในโดเมน payments จัดการคืนเงิน ยังไม่ได้เปิดเลยก็รู้แล้วว่าข้างในคืออะไร
ไฟล์วิวัฒน์ยังไง
อย่าออกแบบต้นไม้สมบูรณ์ตั้งแต่แรก เริ่มจากไฟล์เดียว แตกออกเมื่อมันใหญ่เกินจะคิดในหัว
到目前为止讲的一切 — 系统提示词、工作流、工具 — 都以文件形式存在硬盘上。这些文件的结构本身就是指令。AI 在扫描内容之前先扫描你的文件夹;一棵清楚的树,让它在读第一行之前就已经知道你有什么。
命名就是文档
叫 cs_FINAL_v3_REAL_2.md 的文件,对未来的读者(人或 AI)来说什么都没说。叫 workflows/booking.md 的文件,两个词全说明白了 — 在 workflows 下面,处理预订。模型不打开都能猜到内容,更重要的是 — 来了新请求时,它能猜到 该去哪里找。
像 REST 一样思考
给 AI 文件命名最干净的思维模型,就是借用 REST URL。好的 REST 路径从上到下、从一般到具体:/customers/123/orders/456。文件夹同理:
- 集合用复数,实例用单数。
workflows/装很多个;workflows/booking.md是一个。 - 用名词,不用动词。
prompts/greeting.md,不是do_greeting.md。动词是 agent 对文件 做 的事。 - 层级要可预测。 如果存在
prompts/sales/objection_handling.md,AI 就能猜到prompts/sales/closing.md大概也存在。对称性是发现性的工具。 - 小写、下划线或连字符、不要空格。 URL 安全,shell 安全。
shipping_policy.md哪都能用;Shipping Policy (final).md会让一半工具崩。 - 路径就是文档。 读
tools/payments/refund.json你就知道:是个工具定义,在 payments 域,处理退款。还没打开就已经知道里面是什么。
文件怎么演化
不要一开始就搭完美的树。从一个文件开始。装不下脑子时再拆。
✗ Bad — opaque to AI & humans
- cs_FINAL_v3_REAL_2.md
- Doc1.txt
- Booking System (NEW).md
- misc/stuff.md
- prompt-final-finalfinal.md
✓ Good — self-describing path
- system_prompts/main.md
- workflows/booking.md
- workflows/booking_cancellation.md
- tools/payments/refund.json
- data/menu/coffee.json
How an agent uses this tree
On startup, the agent reads system_prompts/main.md. That file ends with a small map: "For bookings, read workflows/booking.md. For menu questions, read data/menu/. For refunds, use tools/payments/refund.json." When a customer message arrives, the agent matches it to a row in that map and reads the linked file before responding. The folder structure isn't decoration — it's the program's table of contents.
Add a CHANGELOG.md at the root. When you change a workflow, add a one-line entry. The agent (and you, six months from now) will thank you.
agent ใช้ต้นไม้นี้ยังไง
ตอนเริ่ม agent อ่าน system_prompts/main.md ไฟล์นี้จบด้วยแผนที่เล็ก ๆ: "เรื่องจอง อ่าน workflows/booking.md เรื่องเมนู อ่าน data/menu/ เรื่องคืนเงิน ใช้ tools/payments/refund.json" พอข้อความลูกค้าเข้า agent จับคู่กับแถวในแผนที่ แล้วอ่านไฟล์ที่เชื่อมก่อนตอบ โครงสร้างโฟลเดอร์ไม่ใช่ของประดับ — มันคือสารบัญของโปรแกรม
เพิ่ม CHANGELOG.md ที่ root ด้วย แก้ workflow ทีไรก็เพิ่ม 1 บรรทัด agent (และตัวคุณในอีก 6 เดือน) จะขอบคุณ
agent 怎么用这棵树
启动时,agent 读 system_prompts/main.md。这个文件结尾会有一份小地图:"预订相关读 workflows/booking.md。菜单相关读 data/menu/。退款用 tools/payments/refund.json。" 客户消息进来时,agent 把它跟地图里的某一行匹配,读对应文件再回复。文件夹结构不是装饰 — 是程序的目录页。
根目录加一个 CHANGELOG.md。改了工作流就加一行。agent(还有六个月后的你)会感谢你的。
9 · The Assembly Line — Timers, Triggers & The Big Picture
An agent that only replies when a human messages it is half a business. The other half runs without anyone watching — daily reports, weekly summaries, scheduled price checks, overnight inventory pulls. Same model, same tools, same workflows — but kicked off by a clock instead of a chat message.
Think of it as a factory assembly line. Triggers are the bells that start a shift. The router is the foreman who hands incoming work to the right station. Each workflow is a sequence of stations. The tool shelf sits underneath, available to every station. Outputs come off the end of the line — a LINE message, an email, a database row.
The two trigger types
- Event triggers — fire when something happens. New chat message, payment received, webhook from booking.com.
- Time triggers — fire on the clock. Cron-style schedules: every 5 minutes, every morning at 7, every Friday at 5 PM, the 1st of every month.
You write each schedule as a tiny config file. The agent's startup loads them all and registers each one with a timer. From that point on, the agent runs itself.
agent ที่ตอบเฉพาะตอนคนส่งข้อความเข้ามาคือธุรกิจครึ่งเดียว อีกครึ่งทำงาน โดยไม่มีใครดู — รายงานรายวัน สรุปรายสัปดาห์ เช็คราคาตามนัด ดึงสต็อกตอนกลางคืน โมเดลเดียวกัน tools เดียวกัน workflow เดียวกัน — แต่จุดประกายจากนาฬิกาแทนข้อความ
คิดเป็น สายพานการประกอบในโรงงาน — ตัว trigger คือกระดิ่งเริ่มกะ router คือหัวหน้างานที่ส่งงานเข้าไปยังสถานีที่ใช่ workflow แต่ละอันคือสถานีหลายสถานีต่อกัน ชั้นเก็บ tools อยู่ด้านล่างให้ทุกสถานีหยิบใช้ ผลลัพธ์ออกจากปลายสายพาน — ข้อความ LINE, อีเมล, แถวในฐานข้อมูล
trigger สองประเภท
- Event trigger — ทำงาน เมื่อมีอะไรเกิดขึ้น ข้อความใหม่ ยอดเงินเข้า webhook จาก booking.com
- Time trigger — ทำงาน ตามนาฬิกา cron เช่น ทุก 5 นาที ทุกเช้า 7 โมง ทุกศุกร์ 5 โมงเย็น ทุกวันที่ 1 ของเดือน
เขียน schedule เป็นไฟล์ config เล็ก ๆ agent ตอนเริ่มทำงานจะโหลดทั้งหมดและลงทะเบียนกับ timer หลังจากนั้น agent ทำงานเองได้
只在人发消息时才回复的 agent,只完成了生意的一半。另一半在没人看的时候跑 — 每日报告、每周汇总、定时查价、深夜盘点。同样的模型,同样的工具,同样的工作流 — 但启动的不是聊天消息,而是时钟。
把它想成工厂流水线:trigger 是上班铃,router 是把进来的活分到正确工位的工长,每个 workflow 都是一串工位,工具架在下方供所有工位取用。成品从流水线尾部出来 — LINE 消息、邮件、数据库一行记录。
两种 trigger
- 事件触发 — 有事发生 才跑:新聊天消息、收到付款、booking.com 的 webhook。
- 时间触发 — 看时钟 跑:cron 风格的调度,每 5 分钟、每天早 7 点、每周五 5 点、每月 1 号。
每个调度写成一个小 config 文件。agent 启动时加载所有调度,给每个注册一个 timer。从那以后,agent 自己跑自己。
The full assembly line
Click any station to see what it does. Triggers on the left fire workflows in the middle. Workflows pull from the tool shelf below. Outputs leave on the right.
Four real schedules for a Chiang Mai guesthouse
Triage incoming chats */5 * * * *
Morning briefing 0 7 * * *
Weekly report 0 17 * * 5
Monthly price review 0 9 1 * *
A 24-hour view
Hover the markers to see what fires when. The line shows what a typical Tuesday looks like for the agent.
The schedule file
Schedules live as plain JSON in schedules/. The agent reads them on startup, registers a timer for each, and from then on calls the named workflow at the configured times. Adding a new schedule = drop in one file, restart the agent.
schedule อยู่เป็น JSON ธรรมดาใน schedules/ agent อ่านตอนเริ่ม ลงทะเบียน timer ของแต่ละไฟล์ จากนั้นจะเรียก workflow ที่กำหนดตามเวลาที่ตั้งไว้ เพิ่ม schedule ใหม่ = วางไฟล์ใหม่ รีสตาร์ท agent
调度文件以普通 JSON 存放在 schedules/。agent 启动时读取,给每个注册一个 timer,之后按设定时间调用对应的 workflow。加新调度 = 放一个文件,重启 agent。
// schedules/morning_briefing.json { "name": "morning_briefing", "cron": "0 7 * * *", // every day at 7:00 "timezone": "Asia/Bangkok", "workflow": "workflows/scheduled/briefing.md", "context": { "recipient": "owner_line_id", "language": "th", "window": "yesterday" }, "on_failure": "retry_in_15min" }
Why this matters
Once schedules are in place, the agent stops being a chatbot and starts being infrastructure. The owner can take Sunday off — the agent still answers booking inquiries, still files the morning brief, still flags the weekly anomaly. The hardest part is no longer "can the AI write a reply?" — it's "do I trust the AI to fire 100 times a day without supervision?" The answer comes from logs, scenario tests, and the discipline of the file structure we covered in section 8. Clean folders, named workflows, deterministic schedules — together they make autonomy boring, which is exactly what you want.
เมื่อตั้ง schedule แล้ว agent จะเลิกเป็น chatbot และกลายเป็น โครงสร้างพื้นฐาน เจ้าของหยุดวันอาทิตย์ได้ — agent ยังตอบคำถามจอง ยังส่งสรุปเช้า ยังจับสิ่งผิดปกติรายสัปดาห์ คำถามยากไม่ใช่ "AI เขียนตอบได้ไหม" อีกต่อไป — มันคือ "เชื่อใจให้ AI ทำงาน 100 ครั้งต่อวันโดยไม่ดูได้ไหม" คำตอบมาจาก log, การทดสอบสถานการณ์ และวินัยในโครงสร้างไฟล์ที่พูดถึงในหัวข้อ 8 โฟลเดอร์สะอาด workflow มีชื่อ schedule แน่นอน — รวมกันทำให้ความอัตโนมัติน่าเบื่อ ซึ่งคือสิ่งที่ต้องการพอดี
调度一旦到位,agent 就不再是 chatbot,变成 基础设施。老板可以周日休息 — agent 照样回答预订咨询、照样发早报、照样标记每周异常。难题不再是 "AI 能不能写回复" — 是 "我信任这个 AI 一天没人盯着跑 100 次吗"。答案来自日志、场景测试、以及第 8 节讲的文件结构纪律。干净的文件夹、命名清楚的工作流、确定性的调度 — 加在一起让自动化变得无聊,而无聊正是你想要的。
📖 Prompt Lab — interactive prompt builder (3 languages) · 10 Prompt Patterns reference
Built in Chiang Mai by Krueng AI · 💙