✨ คู่มือฉบับสมบูรณ์ · Loop Engineering

Loop Engineering

"หยุดเขียน Prompt เอง — ออกแบบ Loop ที่สั่งงาน AI Agent แทนคุณ"

Loop Engineering คือการออกแบบระบบควบคุมที่ค้นหางาน มอบหมายให้ Agent ตรวจสอบผลลัพธ์ และจดจำสถานะ — แทนที่จะนั่งพิมพ์ Prompt ทีละครั้ง

"I don't prompt Claude anymore. I have loops running that prompt Claude and figuring out what to do. My job is to write loops."

— Boris Cherny, Head of Claude Code @ Anthropic

🎯 ทำไมต้อง Loop Engineering?

จุดที่ให้พลังเปลี่ยนไปแล้ว — จาก "เขียน Prompt ให้ดี" เป็น "ออกแบบระบบที่ควบคุม Agent ตลอดเวลา"

📉

ปัญหาของการ Prompt ทีละครั้ง

ทุกครั้งที่เปิด Session ใหม่ AI เริ่มจากศูนย์ ไม่รู้บริบทโปรเจกต์ ไม่รู้ว่าเมื่อวานทำอะไร คุณเสียเวลา "สอน AI" ซ้ำแล้วซ้ำเล่า — เรียกว่า Intent Debt (หนี้เจตนา)

🚀

พลังของ Loop

Loop คือระบบอัตโนมัติที่ทำงานตามตาราง ค้นหาปัญหา → มอบหมายให้ Sub-agent → ตรวจสอบผล → จดจำสถานะ คุณเป็น วิศวกรที่ออกแบบ Loop ไม่ใช่คนพิมพ์ Prompt

💡
แนวคิดหลัก Loop คือ recursive goal — กำหนดวัตถุประสงค์ แล้วให้ Agent ทำซ้ำ (พร้อม Sub-agent + Memory) จนสำเร็จ หรือจนกว่าจะส่งต่อให้มนุษย์

🧩 ส่วนประกอบพื้นฐาน 5 + 1

Loop หนึ่งวงประกอบด้วยส่วนต่างๆ เหล่านี้ นำไปประกอบเหมือน LEGO — เริ่มจากน้อยแล้วเพิ่มทีละอย่างเมื่อพิสูจน์ค่าแล้ว

1

⏰ Automations / Scheduling

หัวใจของ Loop — กำหนดจังหวะที่ Loop ทำงาน: ทุก 5 นาที ทุกวัน เมื่อ CI พัง หรือจนกว่าจะสำเร็จ

ตัวอย่าง: /loop 1d (Grok) · cron (Claude Code) · hermes cron create "0 8 * * *"
2

🌿 Worktrees — การทำงานขนานปลอดภัย

เมื่อ Agent แก้โค้ด จะทำใน Git Worktree แยกต่างหาก ไม่กระทบโค้ดหลัก ป้องกัน Merge Conflict ระหว่างการพยายามแก้ไขหลายครั้ง

ตัวอย่าง: git worktree add fix-123 → Agent ทำงานในโฟลเดอร์แยก → ลบเมื่อเสร็จ
3

📚 Skills — ความจำถาวร

เก็บ conventions, คำสั่ง build/test, "ห้ามทำแบบนี้เพราะเคยเกิดบั๊ก X" ทำให้ Loop ไม่ต้องเริ่มต้นจากศูนย์ทุกครั้ง — ลด Intent Debt

ตัวอย่าง: SKILL.md ที่บอก "ใช้ pnpm ไม่ใช่ npm" หรือ "ห้ามแก้ไฟล์ใน auth/"
4

🔌 Plugins & Connectors (MCP)

MCP (Model Context Protocol) ช่วยให้ Loop เชื่อมต่อเครื่องมือจริง: อ่าน/เขียน GitHub PRs, Linear tickets, Slack, Database

ตัวอย่าง: Loop เปิด PR อัตโนมัติ · แสดงความเห็นใน Linear · ส่งแจ้งเตือน Slack
5

🔀 Sub-agents — Maker / Checker

สำคัญที่สุด! Agent ที่เขียนโค้ดห้ามตรวจสอบงานตัวเอง — ใช้คนละ Agent (อาจเป็นโมเดลที่แข็งแกร่งกว่า) เป็น Verifier

ตัวอย่าง: Implementer เขียน Fix → Verifier รัน Tests แยก → ผ่านค่อยเปิด PR
+1

🧠 Memory / State

เสาหลักเชื่อมทุกอย่างSTATE.md เก็บ: กำลังทำอะไร · ทำอะไรไปแล้ว · รออะไุจากมนุษย์ ทำให้ Loop จดจำข้าม Session

ตัวอย่าง: "กำลังแก้ #1241, รอ human review PR #1250, พบ flaky test"

📋 วงจรการทำงาน (Anatomy of a Loop)

⏰ Scheduler เริ่มทำงาน
🔍 Triage Skill อ่านสถานการณ์
🧠 อ่าน + เขียน STATE.md
🌿 สร้าง Worktree แยก
✏️ Implementer Sub-agent
✅ Verifier Sub-agent (Tests + Gates)
🔌 MCP / Git / Tickets
🚦 Human Gate — ปลอดภัย → Commit/PR | เสี่ยง → ส่งให้มนุษย์
⏰ วนกลับรอรอบถัดไป

🔄 รูปแบบ Loop ทั้ง 7 แบบ

แต่ละ Pattern แก้ปัญหาเฉพาะ — คลิกเพื่อดูรายละเอียดเต็ม

📊 1. Daily Triage — รายงานสรุปประจำวัน

⏰ 1d–2hความเสี่ยง: ต่ำ💰 Token: ต่ำ

เป้าหมาย: เริ่มวันด้วยภาพรวมที่จัดลำดับความสำคัญแล้ว โดยไม่ต้องไปตรวจ CI, Issues, PRs เอง

วงจรการทำงาน

Scheduler ทำงาน

เช้า หรือทุก 2 ชม. ระหว่าง Sprint

Triage Skill วิเคราะห์

อ่าน CI failures (24h), Issues, Commits, STATE.md

จัดลำดับ + เขียน State

เพิ่ม High Priority ลง STATE.md พร้อม action

(Phase 2) แก้บั๊กเล็ก

Worktree → Implementer → Verifier

ทำความสะอาด

ลบรายการที่ resolved/merged

ตัวอย่างคำสั่ง

# Grok
/loop 1d Run loop-triage. Update STATE.md. No auto-fix in week one.

# Claude Code
/loop 1d Run $loop-triage. Read STATE.md. Merge findings into
High Priority and Watch List. Do not edit code.

# Hermes
hermes cron create "0 8 * * *" --name "Daily triage" \
  --deliver local --skill loop-triage --workdir "$PWD" \
  "Run loop-triage. Read STATE.md first."

ตัวอย่าง STATE.md

# Loop State — Project X
Last run: 2026-07-13 08:15 UTC

## High Priority
- [ ] #1241 — flaky test in auth flow (CI red)
  Loop action: Opened worktree. Fix proposed. Waiting for review.

## Watch List
- PR #1238 open 4 days with no activity.

## Recent Noise (ignored)
- Dependabot PRs (separate automation)

ค่าใช้จ่าย Token

สถานการณ์Token/รอบหมายเหตุ
ไม่มีอะไรทำ~5kState ว่าง
Triage เต็มรูปแบบ (L1)~50kสแกน CI+Issues+Commits
แก้ไขด้วย (L2)~200kWorktree+Implementer+Verifier
แนะนำ: เริ่มจาก Pattern นี้ก่อน! สอน State discipline โดยไม่มีความเสี่ยง

👶 2. PR Babysitter — ดูแล Pull Requests

⏰ 5–15 นาทีความเสี่ยง: ปานกลาง💰 Token: สูง

เป้าหมาย: ลดเวลาที่มนุษย์ต้องเฝ้า PR ผ่าน Review, CI, Rebase และ Merge

วงจรการทำงาน

ค้นหา PR เปิดอยู่

ทั้งหมดที่ทีมสนใจ

วิเคราะห์แต่ละ PR

CI แดง? → แก้. มี Comments? → เสนอ Patch. พร้อม? → แจ้งมนุษย์

เขียนผลกลับ

อัปเดต PR comment + State

PR ค้างนาน?

เสนอปิดหรือส่งต่อ

ตัวอย่างคำสั่ง

# Grok
/loop 5m /pr-babysit check

# ความคิดเห็นต้องชัดเจน:
# "🤖 Loop Engineering — PR Babysitter"

ค่าใช้จ่าย Token

สถานการณ์Token/รอบหมายเหตุ
ไม่มีอะไรทำ~3kเป้าหมาย — exit early
Triage pass~80kสแกน PR + CI status
Fix attempt (L2)~250kWorktree+minimal-fix+verifier
⚠️
Early Exit บังคับ: หากไม่มี PR ใน watchlist ต้องออกทันที (~3k tokens) ไม่งั้น burn token ที่ 288 รอบ/วัน

🔧 3. CI Sweeper — กวาดล้าง CI Failures

⏰ 5–15 นาทีความเสี่ยง: ปานกลาง💰 Token: สูงมาก

เป้าหมาย: ตอบสนอง CI พังบน main อย่างรวดเร็ว — วินิจฉัย เสนอ Fix ขั้นต่ำ และส่งต่อเมื่อแก้ไม่ได้

วงจรการทำงาน

ค้นหา CI failures

บน main, release/*, PRs

จำแนกประเภท

Flake? Regression? Infra? Config?

Flake → เฝ้าดู ไม่แก้

เคยเห็นแล้วและเป็น intermittent

Actionable → แก้

Worktree → Implementer → Verifier (รัน tests ใน worktree)

Circuit Breaker

ครั้งที่ 3 ที่ล้มเหลว → หยุด ส่งให้มนุษย์

ตัวอย่างคำสั่ง

# Grok
/loop 15m Check CI on main and open PRs. For new failures:
classify, and if actionable draft minimal fix in worktree with
verifier. Update ci-sweeper-state.md. Escalate after 3 attempts.

# Claude Code
/goal All tests on main pass and lint is clean

Circuit Breaker (สำคัญมาก)

# ตรวจสอบก่อน retry:
npx @cobusgreyling/loop-context --check --ledger loop-ledger.json
# Exit 0 = ทำต่อ · Exit 2 = ส่งให้มนุษย์
🚨
อันตราย: ที่ 15m cadence โดยไม่มี early-exit = >5M tokens/วัน! ต้องมี early-exit เมื่อ CI เขียว

📦 4. Dependency Sweeper — อัปเดต Dependencies

⏰ 6h–1dความเสี่ยง: ปานกลาง💰 Token: ปานกลาง

เป้าหมาย: ค้นหา dependencies เก่า/มีช่องโหว่ อัปเดตเฉพาะที่ปลอดภัย (patch) ส่งต่อสิ่งที่เสี่ยง (major/CVE) ให้มนุษย์

วงจรการทำงาน

สแกน lockfiles + advisories

npm audit, Dependabot, OSV

จำแนกความเสี่ยง

Safe (patch ไม่มี CVE) / Cautious (minor) / High-risk (major หรือ CVE สูง)

Safe → อัปเดตอัตโนมัติ

Worktree → version bump → verifier (tests+build)

High-risk → มนุษย์

Flag พร้อม changelog diff + CVE link

ตัวอย่างคำสั่ง

# Grok
/loop 6h Run dependency-triage. For safe patches create
minimal PRs in worktrees. Never auto-merge majors or CVEs above medium.
⚠️
กฎเหล็ก: Major version bumps และ CVEs สูง = มนุษย์ตัดสินใจเสมอ

📝 5. Changelog Drafter — ร่าง Release Notes

⏰ 1d หรือเมื่อ tagความเสี่ยง: ต่ำ💰 Token: ต่ำ

เป้าหมาย: สแกน PRs/commits ที่ merge แล้ว ร่าง release notes คุณภาพสูงแบ่งหมวดหมู่ — มนุษย์ review ก่อน publish

วงจรการทำงาน

หา "since" window

tag ล่าสุด หรือวันที่จาก state

สแกน merged PRs + commits

ดึง titles, labels, linked issues

จัดหมวดหมู่

Features, Fixes, Breaking, Security, Docs

ร่าง + Verifier

ตรวจ accuracy, completeness, tone

ไม่ publish เด็ดขาด

เสนอ draft ให้มนุษย์ approve เท่านั้น

💡
ROI สูงสุด: Pattern ที่คุ้มที่สุด ปลอดภัยที่สุด เหมาะเป็น Loop ที่สองหรือสาม

🧹 6. Post-Merge Cleanup — ทำความสะอาดหลัง Merge

⏰ 1d–6hความเสี่ยง: ต่ำ💰 Token: ต่ำ

เป้าหมาย: หลัง merge ไป main กวาดหางานตามมา — deprecations, TODOs, tech debt, stale flags, doc gaps

วงจรการทำงาน

ดู merges ล่าสุด

24h หรือตั้งแต่รอบล่าสุด

สแกน diff ของ TODOs

"remove after", feature flags, broken links

เล็ก+ปลอดภัย → แก้

Worktree → minimal-fix → verifier

ใหญ่ → สร้าง ticket

ส่งให้มนุษย์พร้อม context

ตัวอย่างคำสั่ง

# Grok
/loop 1d Scan merges to main in the last 24h. Identify cleanup
items. For small low-risk items: worktree + minimal fix + verifier.
Update post-merge-state.md. Create tickets for larger items.

# ทำงาน off-peak เท่านั้น (กลางคืน)
# จำกัด auto-PRs: สูงสุด 2 PRs/วัน

🏷️ 7. Issue Triage — คัดกรอง Issues

⏰ 2h–1dความเสี่ยง: ต่ำ💰 Token: ต่ำ

เป้าหมาย: ค้นพบ หาซ้ำ จัดลำดับ และติด label ให้ Issues ใหม่ — ให้ทีมมี top-of-queue ที่สะอาดเสมอ

วงจรการทำงาน

ค้นหา issues/discussions ใหม่

ตั้งแต่รอบล่าสุด

วิเคราะห์แต่ละ issue

สรุป intent, หาซ้ำ, ดึงสัญญาณ (age, reactions, linked PRs)

จัด bucket

P0 (security/prod) / P1 / P2 / P3 / needs-info / duplicate

เขียน state + เสนอ labels

ห้าม auto-label หรือ close ใน L1

💡
เข้าคู่กับ Daily Triage: Issue Triage เป็น "feeder" ให้ Daily Triage — สองวงทำงานร่วมกันได้ดีมาก

🧭 เลือก Pattern แรก — Decision Tree

ไม่รู้จะเริ่มจากไหน? ใช้แผนผังนี้เลือก Pattern ที่เหมาะกับสถานการณ์

❓ อะไรเจ็บปวดที่สุดตอนนี้?
CI แดงบน main?
CI Sweeper (15m, L2)
↓ ไม่ใช่
PRs ค้างอยู่?
PR Babysitter (10-15m, L1→L2)
↓ ไม่ใช่
เช้ามาไม่รู้จะทำอะไร? Issues เยอะ?
Daily Triage + Issue Triage (L1 report-only)
↓ ไม่ใช่
Dependabot / CVE เยอะ?
Dependency Sweeper (L2 patch-only)
↓ ไม่ใช่
TODOs / Cleanup ค้างหลัง merge?
Post-Merge Cleanup (L1 off-peak)
↓ ไม่ใช่
Release notes / changelog เก่า?
Changelog Drafter (L1 draft-only)
↓ ยังไม่มั่นใจ
✅ เริ่มจาก Daily Triage (L1) — สอน discipline โดยไม่มีความเสี่ยง

⚡ เริ่มต้นใน 5 นาที

กฎสัปดาห์แรก: report only — ห้าม auto-fix ห้าม auto-merge อ่านทุกอย่างที่ Loop เขียนก่อน

1. เลือก Pattern (30 วินาที)

ไม่รู้เลือกอะไร? เริ่มจาก Daily Triage

2. Scaffold ในโปรเจกต์ (60 วินาที)

npx @cobusgreyling/loop-init . --pattern daily-triage --tool grok

# เปลี่ยน --tool ได้: grok | claude | codex | opencode

สร้าง: STATE.md, LOOP.md, loop-budget.md, loop-run-log.md + พิมพ์ Loop Ready score

3. เช็คค่าใช้จ่าย (30 วินาที)

npx @cobusgreyling/loop-cost --pattern daily-triage --level L1 --cadence 1d

4. Audit readiness (30 วินาที)

npx @cobusgreyling/loop-audit . --suggest

# ได้ badge สำหรับ README:
npx @cobusgreyling/loop-audit . --badge

5. รัน Loop แรก — report only (2 นาที)

# Grok
/loop 1d Run loop-triage. Update STATE.md. No auto-fix.

# Claude Code
/loop 1d Run $loop-triage. Read STATE.md. Do not edit code.

# Hermes
hermes cron create "0 8 * * *" --name "Daily triage" \
  --deliver local --skill loop-triage \
  --workdir "$PWD" "Run loop-triage"

6. อ่านผล + Commit state (1 นาที)

เปิด STATE.md แก้ไขสิ่งที่ผิด — คุณยังเป็นวิศวกร Commit เพื่อให้ audit เห็น activity

📋
Cheat Sheet แบบครบ
# Scaffold
npx @cobusgreyling/loop-init . --pattern daily-triage --tool grok

# Cost check
npx @cobusgreyling/loop-cost --pattern daily-triage --level L1

# Audit + suggestions
npx @cobusgreyling/loop-audit . --suggest

# Badge สำหรับ README
npx @cobusgreyling/loop-audit . --badge

# ตรวจ STATE.md ↔ LOOP.md drift
npx @cobusgreyling/loop-sync .

# L2: worktree สำหรับ fix attempts
npx @cobusgreyling/loop-worktree create --run-id fix-1 --pattern ci-sweeper
npx @cobusgreyling/loop-worktree mark --run-id fix-1 --status rejected
npx @cobusgreyling/loop-worktree cleanup --older-than 24h

📊 Readiness Levels — ขั้นพัฒนาการของ Loop

ห้ามข้ามขั้น! เริ่มจาก L1 เสมอ แล้วค่อย progress

📝

L0 — Draft

เอกสารความตั้งใจเท่านั้น ยังไม่รัน

Checklist: §1
📊

L1 — Report

Triage → State, ไม่มี auto-action (เริ่มที่นี่!)

Checklist: §1-3, §5
🔧

L2 — Assisted

Auto-fix ขนาดเล็ก พร้อม Verifier + Worktree

Checklist: §1-7
🤖

L3 — Unattended

รันโดยไม่มีมนุษย์เฝ้า — ต้องมี denylist, budget, metrics, human gates

Checklist: ทั้งหมด
🚨
Red Flags — หยุดและแก้ก่อนทำต่อ:
• PR เดียวมี >3 ครั้ง fix attempts โดยไม่ progress
• Verifier คือ session เดียวกับ Implementer
• ไม่มี State file — Loop ต้องเริ่มใหม่ทุกครั้ง
• แจ้งเตือนทุกรอบไม่ว่าจะมี findings หรือไม่
• Auto-merge เปิดโดยไม่มี path allowlist

🛡️ ความปลอดภัย — Guardrails

Loop ขยายพลังการตัดสินใจ — ทั้งที่ดีและที่แย่ Guardrails เหล่านี้คือมาตรฐานขั้นต่ำ

🚫 Path Denylist — ห้ามยุ่ง

Loop ห้ามแก้ไฟล์เหล่านี้โดยไม่ได้รับอนุญาตจากมนุษย์:

.env, .env.*
**/secrets/**
**/credentials/**
**/*_key*, **/*_secret*
.terraform/**
k8s/production/**
**/migrations/**
auth/**
payments/**
billing/**

🔀 Auto-Merge Policy

ค่าเริ่มต้น: ห้าม Auto-merge

อนุญาต (ถ้ามี allowlist)ห้ามเด็ดขาด
Typo ใน comment/docsBehavior changes
Lint auto-fix (test files)Dependency version bumps
Import orderingLockfile changes
Config ใน docs/ pathsDenylist paths ใดๆ

🔌 MCP Least Privilege

ConnectorReadWrite
GitHubissues, PRs, checkscomment, label (not merge)
Linearteam issuescomment, status (not delete)
Slackchannel historypost ไป #loop-escalations เท่านั้น
Databaseห้าม production write

🚦 Human Gates — ต้องมีมนุษย์เสมอ

  • Security, authentication, authorization
  • Payments, billing, PII
  • Infrastructure / Terraform / K8s production
  • Dependency upgrades (supply chain risk)
  • เปลี่ยนไฟล์ > N ไฟล์ (แนะนำ N=10)
  • ครั้งที่ 3 ที่ล้มเหลวบน item เดิม

❌ 10 Anti-Patterns — ห้ามทำ

ความผิดพลาดในการออกแบบที่ต้องหลีกเลี่ยงก่อนเปิด unattended loops

1. 🔁 Agent เดียวกัน Implement + Verify

ทำไมพัง: Confirmation bias, test อ่อนผ่านหมด
แก้: Verifier คนละ Agent/โมเดล ค่าเริ่มต้น = REJECT

2. ♾️ ไม่จำกัดจำนวนครั้ง

ทำไมพัง: Infinite fix loops, burn tokens
แก้: Hard cap 3 ครั้ง → escalate

3. 📝 Triage output กำกวม

ทำไมพัง: Loop ไม่ parse ได้, คนไม่อ่าน
แก้: Structured markdown + one-line items

4. 🚀 L3 ก่อน L1

ทำไมพัง: กระทำจากสัญญาณผิด
แก้: L1 report-only สัปดาห์แรกเสมอ

5. 📋 State ร่วมไม่มี schema

ทำไมพัง: State rot, ghost items
แก้: ไฟล์ State แยก per pattern

6. 🔌 MCP write-everything

ทำไมพัง: Blast radius ใหญ่เกินไป
แก้: L1 read-only ก่อน

7. 🔌 ไม่มี Kill Switch

ทำไมพัง: Alert fatigue, budget overrun
แก้: Document pause/kill ใน LOOP.md

8. 🐛 แก้ Flake ด้วย Code

ทำไมพัง: ปิดปัญหา infra ซะ
แก้: Classify → quarantine → escalate

9. 🔀 Auto-merge ไม่มี allowlist

ทำไมพัง: Security bugs ผ่าน verifier อ่อน
แก้: Explicit path allowlist

10. 📭 ไม่มี Run Log

ทำไมพัง: Debug ไม่ได้ "ทำไมทำแบบนั้นวันอังคาร?"
แก้: Append to loop-run-log.md ทุกรอบ

🔥 Failure Modes — วิธีที่ Loop พังจริง

เรียนรู้จากความล้มเหลวจริง — และวิธีป้องกัน

FailureSeverityสาเหตุการป้องกัน
Infinite Fix LoopS2Verifier อ่อน / root cause ผิดHard cap 3 → escalate
State RotS1→S2ไม่ prune, state เก่าPrune closed/merged ทุกรอบ
Verifier TheaterS2Verifier ไม่รัน testsVerifier ต้องรัน test/lint
Notification FatigueS1→S2แจ้งทุกรอบแจ้งเฉพาะตอนต้องมี decision
Token BurnS1Cadence เร็ว + sub-agent หนักEarly exit + budget cap
Over-ReachS2→S3Scope กว้างเกินDenylist + smallest diff
Comprehension DebtS2คนเลิกอ่าน outputWeekly digest review
Cognitive SurrenderS2"Loop จัดการเอง"Human gates ทุก pattern
Parallel CollisionS22 agents แก้ไฟล์เดียวกันWorktree isolation
Escalation FailureS2ไม่แจ้งมนุษย์Connector ping on escalation

🛠️ เครื่องมือชุด Loop Engineering

npm packages ทั้งหมด — ไม่ต้อง clone repo รันผ่าน npx ได้เลย

🏗️

loop-init

Scaffold skills, state, budget files + พิมพ์ Loop Ready score

npx @cobusgreyling/loop-init . --pattern daily-triage --tool grok
🔍

loop-audit

Loop Readiness Score (0-100) + suggestions + badge

npx @cobusgreyling/loop-audit . --suggest
💰

loop-cost

ประเมิน Token spend ตาม cadence

npx @cobusgreyling/loop-cost --pattern ci-sweeper --cadence 15m
🔄

loop-sync

ตรวจ drift ระหว่าง STATE.md ↔ LOOP.md

npx @cobusgreyling/loop-sync .

loop-context

Circuit breaker + stateful memory สำหรับ L2+

npx @cobusgreyling/loop-context --check --ledger run.json
🌿

loop-worktree

Manage isolated git worktrees สำหรับ fix attempts

npx @cobusgreyling/loop-worktree create --run-id fix1 --pattern ci-sweeper
🔌

loop-mcp-server

MCP runtime lookup — patterns, skills, state on demand

LOOP_PROJECT_ROOT=. npx @cobusgreyling/loop-mcp-server

🔀 เปรียบเทียบข้ามเครื่องมือ

Loop Engineering ไม่ผูกกับ tool ใด — สิ่งสำคัญคือ ความสามารถ ไม่ใช่ชื่อสินค้า

PrimitiveGrokClaude CodeCodexHermes
Scheduling/loop 1d/loop, cronAutomations tabhermes cron create
Worktreesisolation: "worktree"--worktreeBuilt-in per threadStandard git worktree + --workdir
Skills.grok/skills/.claude/skills/$skill-name~/.hermes/skills/
ConnectorsCallMcpToolMCP serversConnectors (MCP)hermes mcp add
Sub-agentsTask tool.claude/agents/TOML agentsdelegate_task
StateSTATE.mdAGENTS.mdMarkdown/LinearSTATE.md + hermes memory
Run-until-done/goal/goal/goalChained cron via context_from
💡
ย้ายข้ามเครื่องมือได้: 1) เขียน Skill (tool-agnostic SKILL.md) 2) นิยาม state schema 3) Document verification split 4) Map scheduling ไปยัง TUI/editor/Action ปัจจุบัน

⚙️ การดำเนินงาน — Operating Loops

รัน Loop คืองาน operations — ต้องดูเรื่อง cost, logging, และเมื่อไร่ะ pause/kill

💰 Token Budgeting

LoopCadenceRuns/วันToken/วัน (โดยประมาณ)
Daily Triage (report)1d1~50k
CI Sweeper (light)15m96~5M (หลีกเลี่ยง!)
PR Babysitter5m288สูง — ใช้ early exit

Best Practice: Triage pass ถูก — spawn sub-agents เฉพาะเมื่อ state บอกว่า actionable ว่าง → exit ใน <5k tokens

🛑 เมื่อไร่ะ Pause / Kill

⏸️ Pause ชั่วคราว

  • Token budget >80% กลางสัปดาห์
  • False positive >30%
  • Item เดียว escalated 2+ ครั้งใน 48h
  • Production incident กำลังเกิด
  • Breaking schema migration

💀 Kill ถาวร

  • S2 failures ต่อเนื่อง
  • Cost > value 2 สัปดาห์ติด
  • ทีม mute notifications ทั้งหมด
  • แทนที่ด้วย event-driven (เช่น CI Action)

📈 Logging แต่ละรอบ

{
  "run_id": "2026-07-13T08:15:00Z",
  "pattern": "daily-triage",
  "duration_s": 45,
  "items_found": 4,
  "actions_taken": 1,
  "escalations": 0,
  "tokens_estimate": 52000,
  "outcome": "success"
}

🔗 การทำงานหลาย Loop พร้อมกัน

รันหลาย Loop ปกติ — แต่ต้องมีขอบเขตชัดเจน ไม่งั้น Loop ตีกัน

📋 หลักการ

  • 1 owner ต่อ branch — สูงสุด 1 Loop ต่อ branch ต่อชั่วโมง
  • State แยก — STATE.md สำหรับ triage, ไฟล์เฉพาะสำหรับ action loops
  • Triage = report, Action = execute
  • Denylist ร่วม — copy path denylist เดียวกันในทุก LOOP.md
  • Budget รวม — aggregate token budget

🎯 Priority เมื่อขัดแย้ง

1. CI Sweeper

main แดง blocks ทุกอย่าง

2. PR Babysitter

PRs time-sensitive

3. Dependency Sweeper

Pause ถ้า CI แดง

4. Post-Merge

Off-peak, ด่วนน้อยสุด

5. Daily Triage

Report only L1

🧠 แนวคิดและคำศัพท์

🔁 Loop Engineering

แทนที่ตัวเองในฐานะ "คนพิมพ์ Prompt" — ออกแบบระบบที่ค้นหางาน มอบหมาย ตรวจสอบ และจดจำสถานะ

🏗️ Agent Harness Engineering

สภาพแวดล้อมที่ Agent ตัวเดียว ทำงาน: tools, context, permissions. Harness = sandbox; Loop = ที่ schedule + orchestrate

🏭 The Factory Model

ระบบที่ สร้าง software: pipelines, agents, checks, handoffs. Loop Engineering = วิธีดูแล factory floor

💸 Intent Debt

ทุก session AI เริ่มจากศูนย์ — intent ที่หายไปถูกแทนด้วย "การเดาที่มั่นใจ" Skills คือวิธีจ่ายหนี้นี้

📖 Comprehension Debt

ช่องว่างระหว่าง "โค้ดที่มี" กับ "สิ่งที่คุณเข้าใจจริงๆ" Loop เร็ว = ship โค้ดที่คุณไม่ได้เขียนเยอะขึ้น

😴 Cognitive Surrender

กับดักของการปล่อย Loop รันไป โดยคุณเลิกมีความคิดเห็น — ออกแบบ Loop ด้วย "วิจารณญาณ" คือทางรักษา

📊 Orchestration Tax

ต้นทุนมนุษย์ในการประสานงาน agents ขนาน: review bandwidth, merge conflicts, context switching

🎼 Code Agent Orchestra

Pattern: agents คนละบทบาท (explore, implement, verify) — Implementer ห้ามตรวจงานตัวเอง