ลดต้นทุน Context ด้วย Stable Prefix และ Cache
เรียนรู้ ลดต้นทุน Context ด้วย Stable Prefix และ Cache เพื่อสร้าง AI Harness สำหรับงานในประเทศไทย
เป้าหมาย: ออกแบบ contract, runtime และ evaluation ที่เปลี่ยนโมเดลให้เป็นระบบดูแลได้ · ใช้เวลาประมาณ 18 นาที
Contract → Runtime → Evidence → Improvement
Harness เปลี่ยนโมเดลทั่วไปให้ทำงานเฉพาะอย่างควบคุมได้
Contract
แยก stable system/tool/schema จาก dynamic user/time/data เพื่อใช้ prompt cache เมื่อผู้ให้บริการรองรับ; KV cache เร่ง token ภายใน generation ส่วน explicit cache reuse input ข้าม request ต้องวัด hit rate, invalidation และ privacy
Runtime
จัด message/context/tool/state/retry/timeout โดยไม่ซ่อน side effect
Evidence
เก็บ trace ที่ลดข้อมูลและ eval แยก failure layer
Improvement
แก้ prompt/retrieval/tool/code ตามสาเหตุและรัน regression ก่อน release
Artifact ของ Harness
KV cache
ระบุ KV cache ด้วย owner, version, boundary, observable evidence และ failure handling
ทุก contract ต้องอ่านได้ทั้งคนและระบบและมีวิธีทดสอบ
prompt cache
ระบุ prompt cache ด้วย owner, version, boundary, observable evidence และ failure handling
ทุก contract ต้องอ่านได้ทั้งคนและระบบและมีวิธีทดสอบ
stable prefix
ระบุ stable prefix ด้วย owner, version, boundary, observable evidence และ failure handling
ทุก contract ต้องอ่านได้ทั้งคนและระบบและมีวิธีทดสอบ
invalidation
ระบุ invalidation ด้วย owner, version, boundary, observable evidence และ failure handling
ทุก contract ต้องอ่านได้ทั้งคนและระบบและมีวิธีทดสอบ
Harness ที่ดูฉลาดแต่เปราะ
รวม policy, data และ output ใน string เดียว
debug/provenance/cache ยาก
แยก role และ structured contract
stream หรือ tool call แล้วถือว่าสำเร็จ
ข้อมูลอาจไม่ครบหรือ side effect ผิด
validate final state และ business outcome
วัดเฉพาะคำตอบสวย
ไม่เห็น retrieval/tool/cost/safety failure
layered evaluation และ trace
ทำ Harness Specification
system prompt ใส่ timestamp ทุกครั้งทำให้ stable prefix เปลี่ยนและ cache miss
ระบุ messages, Markdown/schema, context/cache, tool/MCP, skill, state/stream และ evaluation
ดูคำตอบตัวอย่าง
แยก system policy ที่เสถียรจาก user/data dynamic ใช้ Markdown ให้คนอ่านและ JSON Schema สำหรับเครื่อง ระบุ untrusted provenance กับ permission ให้ MCP/tool ใช้ least privilege และ approval ห่อ workflow ซ้ำเป็น Skill ที่มี version/test แยก partial streaming จาก committed result จัด stable prefix เพื่อ cache โดยไม่ใส่ timestamp และสร้าง evaluation set ภาษาไทยวัด answer/retrieval/tool argument/side effect/latency/cost/escalation
- message/provenance
- human + machine format
- tool/permission contract
- skill/version
- stream/cache states
- layered Thai eval
บันทึกช่วยจำ
- ตรวจ API และ MCP specification ตาม version ที่ใช้จริง
- trace และ cache ต้องไม่เก็บ secret หรือข้อมูลส่วนบุคคลเกินวัตถุประสงค์
สรุปบทเรียนนี้
- contracts before orchestration
- validate committed result
- evaluate every layer