Streaming Output โดยรักษาโครงสร้างและสถานะ
เรียนรู้ Streaming Output โดยรักษาโครงสร้างและสถานะ เพื่อสร้าง AI Harness สำหรับงานในประเทศไทย
เป้าหมาย: ออกแบบ contract, runtime และ evaluation ที่เปลี่ยนโมเดลให้เป็นระบบดูแลได้ · ใช้เวลาประมาณ 18 นาที
Contract → Runtime → Evidence → Improvement
Harness เปลี่ยนโมเดลทั่วไปให้ทำงานเฉพาะอย่างควบคุมได้
Contract
streaming ลด perceived latency แต่ JSON/Markdown อาจยังไม่ครบ ต้องแยก partial text จาก committed result ใช้ incremental parser, cancel, timeout และ final validation ก่อนส่งต่อหรือ execute
Runtime
จัด message/context/tool/state/retry/timeout โดยไม่ซ่อน side effect
Evidence
เก็บ trace ที่ลดข้อมูลและ eval แยก failure layer
Improvement
แก้ prompt/retrieval/tool/code ตามสาเหตุและรัน regression ก่อน release
Artifact ของ Harness
streaming
ระบุ streaming ด้วย owner, version, boundary, observable evidence และ failure handling
ทุก contract ต้องอ่านได้ทั้งคนและระบบและมีวิธีทดสอบ
incremental parser
ระบุ incremental parser ด้วย owner, version, boundary, observable evidence และ failure handling
ทุก contract ต้องอ่านได้ทั้งคนและระบบและมีวิธีทดสอบ
partial state
ระบุ partial state ด้วย owner, version, boundary, observable evidence และ failure handling
ทุก contract ต้องอ่านได้ทั้งคนและระบบและมีวิธีทดสอบ
final validation
ระบุ final validation ด้วย 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
หน้าใบเสนอราคา render JSON ที่ยังมาไม่ครบแล้วผู้ใช้กดส่ง
ระบุ 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