ข้ามไปที่เนื้อหา

มากกว่า stack trace: observability และ verification ของ async AI agent ใน production

Agent trace สวยแค่ไหน ก็ช่วยคุณไม่ได้ตอนตีสอง ใน Langfuse คุณเห็นครบทุก LLM call ทุก token ทุก tool invocation แต่ก็ยังพิสูจน์ไม่ได้ว่า agent ตัดสินใจอะไร เพราะอะไร และมีสิทธิ์ทำแบบนั้นหรือเปล่า Observability บอกได้ว่าเกิดอะไรขึ้น แต่บอกไม่ได้ว่าเกิดขึ้นถูกอย่างที่ควรจะเป็น

ช่องว่างตรงนี้คือปัญหาใหม่ของ runtime และสัปดาห์นี้วงการก็เริ่มขยับ วันที่ 11 มิถุนายน Diagrid ปล่อย Verifiable Execution ใน Dapr 1.18 ส่วน The New Stack ก็ลงบทความว่า การ verify agent เป็นเรื่องของ runtime ไม่ใช่เรื่องตอน test12

โพสต์นี้เขียนให้ platform team ที่มี Kubernetes กับ OpenTelemetry อยู่แล้ว แล้วตอนนี้โดนขอให้รัน agent ที่แก้ของใน production ถ้ามีคนถามว่า "agent ทำอะไรไป" แล้วคุณตอบว่า "เรามี OTel trace" แปลว่าช่องว่างนี้ยังไม่ได้ปิด

ก่อนอื่นต้องดู scope ให้ชัด เพราะ agent ส่วนใหญ่ไม่ต้องทำถึงขนาดนี้ ถ้า agent เป็นแบบ read-only หรือแค่ให้คำแนะนำ คือสรุป ร่าง ดึงข้อมูล หรือแนะนำ แล้วคนเป็นคนลงมือเอง ทำแค่ Layer 1 ก็พอ OTel trace กับ Langfuse เอาอยู่ Layer ด้าน durability และ proof จำเป็นก็ต่อเมื่อ agent ลงมือทำ action ที่มี side effect เอง เช่น โอนเงิน แก้ record หรือเรียก tool ที่เปลี่ยน state ของ production ตัวแบ่งคือ agent ทำเรื่องที่ย้อนกลับไม่ได้เองหรือเปล่า ไม่ใช่ว่าดู "agentic" แค่ไหน เนื้อหาข้างล่างทั้งหมดเขียนสำหรับ agent กลุ่มที่ทำเองได้


Failure แบบที่ metric มองไม่เห็น

Microservice ทั่วไปเวลาพังจะพังแบบเสียงดัง ตอบ 500 โยน exception SLO หลุด แล้ว dashboard ก็แดงไปทั้งแผง แต่ agent พังแบบเงียบ คือตอบมาอย่างมั่นใจ format เรียบร้อย แต่ผิดทั้งหมด โดยที่ทุก metric ยังเขียวอยู่2

ลองดู incident แบบนี้ที่ทำเอาพังกันทั้งวัน:

Async support agent รันเป็น queue worker ลูกค้าขอคืนเงิน agent ดึง order ผิดตัวมาจาก vector DB (embedding ชนกัน) แล้วเรียก MCP tool issue_refund เป็นเงิน $4,200 ทั้งที่ควรเป็น $42 tool ทำงานสำเร็จ workflow จบ span เขียว trace ขึ้น 200 สวยงาม ผ่านไปหกชั่วโมง ฝ่ายการเงินถึงมาถามว่าเกิดอะไรขึ้น

On-call engineer เปิด trace ดู เห็นว่า span execute_tool ทำงาน เห็นว่า issue_refund ตอบ success แต่สิ่งที่ไม่เห็นเลยคือ agent ดึงเอกสารไหนมา model ใช้ข้อมูลอะไรคิดจริงๆ ตัวเลข $4,200 มาจากลูกค้าหรือ model มโนขึ้นมาเอง และที่สำคัญที่สุด agent ตัวนี้มีสิทธิ์คืนเงินเกิน $100 โดยไม่ต้องให้คนอนุมัติหรือเปล่า

Trace เก็บได้แค่ว่ามีการเรียก แต่ไม่ได้เก็บการตัดสินใจ ไม่ได้เก็บ state ที่ใช้ตัดสินใจ และไม่ได้เก็บว่า agent ทำในนามสิทธิ์ของใคร สามอย่างนี้คือสิ่งที่ต้องมีถ้าจะ reconstruct, replay หรืออธิบายพฤติกรรมของ agent ให้คนอื่นฟังได้ แต่ค่า default ไม่มีอย่างไหนอยู่ใน span เลย

Observability vs. verification

สองเรื่องนี้เป็นคนละปัญหา และใช้ tooling คนละชุด หลายทีมเอามาปนกัน เลยคิดว่าตัวเองครอบคลุมแล้วทั้งที่ยังไม่ใช่

Observability Verification
ตอบคำถาม "เกิดอะไรขึ้น?" "ทำถูกไหม และมีสิทธิ์ทำหรือเปล่า?"
เก็บอะไร Span, metric, log, จำนวน token Input, การตัดสินใจ, side-effect, identity, signature
จับ failure แบบไหน Latency, error, crash ตัดสินใจผิดแต่ทำสำเร็จ, action ที่ไม่มีสิทธิ์, การแก้ข้อมูลย้อนหลัง
เก็บได้นานแค่ไหน ดู live + retention ช่วงสั้นๆ Durable, audit ได้, replay ได้ไม่จำกัดเวลา
Tool ที่ใช้กัน OTel, Langfuse, Prometheus, Grafana Durable workflow, signed history, attestation, policy gate
Determinism Sampling แบบ best-effort ต้อง replay แบบ deterministic ได้

Observability จำเป็น แต่ยังไม่พอ ต้องมีทั้งสอง layer ที่เหลือของโพสต์นี้คือวิธีสร้าง layer ที่สองขึ้นมา โดยไม่ต้องทิ้ง layer แรก


Agent run ที่ verify ได้ ต้องมีอะไรบ้าง

ก่อนเลือก tool ต้องวาง data model ให้ถูกก่อน Run หนึ่งจะนับว่า "verify ได้" ก็ต่อเมื่อเอา record มา replay แล้วได้การตัดสินใจเดิมทุกจุด และพิสูจน์ได้ด้วยว่าไม่มีใครแก้ record ทีหลัง แบบนี้ต้องเก็บหกอย่าง ไม่ใช่อย่างเดียว

Element ต้องเก็บอะไร สำคัญยังไง
Inputs Prompt จริงที่ส่งไป, context ที่ดึงมา (พร้อม doc ID + score), tool schema, model + param ไม่เห็นหลักฐานที่ agent เห็น ก็ตัดสินไม่ได้ว่าตัดสินใจถูกไหม
Decisions LLM output ทุกตัวแบบคำต่อคำ รวมถึงเหตุผลที่เลือก tool และ finish_reason ได้ "ทำไม" ไม่ใช่แค่ "ทำอะไร"
Side-effects Tool call ทุกตัว, argument, ผลลัพธ์ และ idempotency key Blast radius: อะไรไปแตะ prod บ้าง
State checkpoints Durable workflow history หลังจบแต่ละ step Crash แล้วไม่หาย และเป็นฐานของ replay
Provenance Workload identity (ใครหรืออะไรเป็นคนรัน) ของแต่ละ step "Agent ตัวนี้มีสิทธิ์ทำแบบนั้นไหม?"
Integrity Signature ที่ครอบทั้ง history หลักฐานว่าไม่มีใครแก้ record ทีหลัง

สามข้อแรกเป็นเรื่อง observability ซึ่ง OTel กับ Langfuse ทำได้ดีอยู่แล้ว สามข้อหลังเป็นเรื่อง verification และ stack ส่วนใหญ่ยังไม่มีอะไรรองรับเลย ลำดับตรงนี้มีความหมาย แต่ละ layer ต้องพึ่ง layer ก่อนหน้า ถ้า history ยัง replay แบบ deterministic ไม่ได้ จะ sign ไปก็ไม่มีประโยชน์


ทุกอย่างขึ้นอยู่กับ determinism

Replay จะใช้ได้ก็ต่อเมื่อ run เป็น deterministic คือป้อน input ชุดเดิมที่บันทึกไว้กลับเข้าไป แล้วต้องได้การตัดสินใจเดิมออกมา ปัญหาคือ agent ปกติ non-deterministic สุดๆ ทั้ง model sampling, timestamp จากนาฬิกาจริง, retry แบบสุ่ม, now() ใน prompt และ tool fan-out ที่ลำดับไม่แน่นอน

ทางแก้คือ pattern ที่ durable-workflow engine ใช้กันมาเป็นสิบปีแล้ว: record-and-replay ตอน replay ไม่ต้องรันงานที่มี side effect ซ้ำ แค่เอาผลลัพธ์ที่บันทึกไว้มาเล่นใหม่ Model call, vector query, tool invocation แต่ละตัวบันทึกไว้ครั้งเดียว พอ replay ตัว engine ก็คืนผลที่เก็บไว้ให้ ไม่ได้เรียกออกไปจริงอีกรอบ Control flow ของ agent รันซ้ำ แต่ effect ไม่เกิดซ้ำ กลไกชุดเดียวกันนี้เลยทำได้ทั้งให้ agent ที่ crash ไป resume ต่อได้ และย้อนไป audit agent ที่รันไปแล้วได้


Stack ที่ใช้ได้จริง: สาม layer

ไม่ต้องรื้อ tracing ที่มีอยู่ แค่วาง verification ซ้อนขึ้นไปข้างบน มีสาม layer แต่ละ layer ทำงานที่ layer ข้างล่างทำไม่ได้

┌─────────────────────────────────────────────────────────┐
│  Layer 3 — PROOF      Dapr 1.18 Verifiable Execution     │
│  signs history, propagates lineage, attests authority    │
├─────────────────────────────────────────────────────────┤
│  Layer 2 — DURABLE    Dapr Workflow                      │
│  event-sourced history, deterministic replay, crash-safe │
├─────────────────────────────────────────────────────────┤
│  Layer 1 — TRACE      OpenTelemetry GenAI + Langfuse     │
│  spans for every agent step, tool call, and LLM call     │
└─────────────────────────────────────────────────────────┘

Layer 1: trace ด้วย OTel GenAI semantic conventions

ทุกวันนี้ OpenTelemetry GenAI semantic conventions กลายเป็นภาษากลางของ agent telemetry ไปแล้ว ใช้ชื่อ attribute ตาม convention นี้ดีกว่าตั้งเอง เพราะ backend ทุกเจ้า (Langfuse, Datadog, Honeycomb) จะอ่าน span ของคุณออก3 Convention นี้มอง agent run หนึ่งรอบเป็น span invoke_agent ตัวบนสุด ข้างใต้มี child span chat (LLM call ละหนึ่งตัว) และ execute_tool (tool ละหนึ่งตัว)

from opentelemetry import trace

tracer = trace.get_tracer("refund-agent")

with tracer.start_as_current_span("invoke_agent") as agent_span:
    agent_span.set_attribute("gen_ai.operation.name", "invoke_agent")
    agent_span.set_attribute("gen_ai.agent.name", "refund-agent")
    agent_span.set_attribute("gen_ai.conversation.id", conversation_id)

    # The LLM decision — capture the evidence AND the output
    with tracer.start_as_current_span("chat") as chat_span:
        chat_span.set_attribute("gen_ai.operation.name", "chat")
        chat_span.set_attribute("gen_ai.request.model", "claude-opus-4-8")
        chat_span.set_attribute("gen_ai.usage.input_tokens", usage.input_tokens)
        chat_span.set_attribute("gen_ai.usage.output_tokens", usage.output_tokens)
        chat_span.set_attribute("gen_ai.response.finish_reasons", ["tool_calls"])
        # The retrieved evidence the model reasoned over — the part traces usually drop
        chat_span.set_attribute("rag.document_ids", retrieved_doc_ids)
        chat_span.set_attribute("rag.scores", retrieved_scores)

    # The side-effect — capture args AND an idempotency key
    with tracer.start_as_current_span("execute_tool") as tool_span:
        tool_span.set_attribute("gen_ai.operation.name", "execute_tool")
        tool_span.set_attribute("gen_ai.tool.name", "issue_refund")
        tool_span.set_attribute("gen_ai.tool.call.id", tool_call_id)
        tool_span.set_attribute("app.refund.amount_usd", amount)
        tool_span.set_attribute("app.idempotency_key", idem_key)

Attribute สองตัวที่ทำให้ trace ใช้เป็นหลักฐานได้ คือ rag.document_ids/rag.scores (model เห็นอะไร) กับ app.idempotency_key (side-effect จะได้ replay ได้อย่างปลอดภัยและไม่เกิดซ้ำ) Auto-instrumentation มาตรฐานไม่เก็บให้ทั้งคู่ ต้องใส่เอง

ส่ง span พวกนี้เข้า Langfuse ไว้ให้คนดู Langfuse จะจัด span เป็น timeline ของแต่ละ session ให้เปิดดู prompt, context ที่ดึงมา และ tool arg เทียบกันได้ในหน้าเดียว นี่คือ observability แต่ยังไม่ใช่ proof เพราะข้อมูลใน Langfuse เป็นแบบ sample, แก้ไขได้ และมี retention จำกัด เอาไว้ debug ดีมาก แต่ถ้าอีกหกเดือนต้องโดน audit ก็ช่วยอะไรไม่ได้

Layer 2: ทำให้ run durable และ replay ได้ด้วย Dapr Workflow

เอา agent loop ไปครอบไว้ใน Dapr Workflow ตัว workflow function คือ orchestration logic ส่วน step ไหนมี side effect ก็แยกเป็น activity Dapr เก็บ history แบบ event-sourced ทุกครั้งที่ activity ทำเสร็จ ผลลัพธ์จะโดน checkpoint ไว้ ถ้า pod ตายกลางทาง workflow ก็ replay history ไปจนถึง checkpoint ล่าสุดแล้วทำต่อจากตรงนั้น ไม่มีคืนเงินซ้ำสองรอบ และ state ไม่หาย1

import dapr.ext.workflow as wf

wfr = wf.WorkflowRuntime()

@wfr.workflow(name="refund_agent")
def refund_agent(ctx: wf.DaprWorkflowContext, order_query: str):
    # Each call is recorded; on replay these return stored results, not re-runs
    context = yield ctx.call_activity(retrieve_context, input=order_query)
    decision = yield ctx.call_activity(llm_decide, input=context)

    # Verification gate BEFORE the side-effect
    if decision["amount_usd"] > 100:
        approval = yield ctx.wait_for_external_event("human_approval")
        if not approval["approved"]:
            return {"status": "rejected", "reason": "exceeded auto-approve limit"}

    result = yield ctx.call_activity(issue_refund, input=decision)
    return {"status": "completed", "result": result}

@wfr.activity(name="issue_refund")
def issue_refund(ctx, decision: dict):
    # Side-effecting MCP tool call — runs exactly once, recorded in history
    return mcp_client.call_tool("issue_refund", decision, idempotency_key=decision["idem_key"])

ได้สองอย่างที่ agent loop เปล่าๆ ให้ไม่ได้:

  • Gate wait_for_external_event เป็น verification checkpoint ตัวจริง ไม่ใช่ของเสริม Workflow จะหยุดรอแบบ durable จะเป็นนาทีหรือเป็นวันก็ได้ จนกว่าคนจะอนุมัติ ไม่ต้อง poll state ไม่หาย ไม่ต้องเขียน cron job มาแก้ขัด การคืนเงินเกิน $100 ไม่มีทางเกิดขึ้นจนกว่าจะมีคนอนุมัติ และช่วงที่หยุดรอก็บันทึกอยู่ใน record ถาวรด้วย
  • ได้ deterministic replay มาฟรีๆ เพราะทุก activity บันทึกไว้หมด จะหยิบ run ไหนในอดีตมา replay จาก history ก็ได้ แล้วดูการตัดสินใจไล่ไปทีละ step ตามที่เกิดขึ้นจริง กลไกเดียวได้ทั้งการ reconstruct เพื่อ audit และการกู้คืนตอน crash

หมายเหตุเรื่อง API: authoring model ของ Dapr Workflow (call_activity, wait_for_external_event, history แบบ event-sourced) stable และใช้ได้ปัจจุบัน แต่ก่อน copy ไปใช้ ให้ pin version ของ dapr runtime กับ SDK ไว้ และเช็ค Dapr Workflow docs อีกรอบ เพราะ SDK surface ยังเปลี่ยนไปมาระหว่าง release

Layer 3: พิสูจน์ด้วย Dapr 1.18 Verifiable Execution

Durable history ตอบได้ว่า "เกิดอะไรขึ้น" แต่ไม่ได้พิสูจน์ว่าไม่มีใครแก้ history และไม่ได้พิสูจน์ว่า agent มีสิทธิ์ลงมือ Dapr 1.18 ปิดช่องว่างนี้ด้วยความสามารถใหม่สามตัว ทั้งหมดสร้างอยู่บน SPIFFE workload identity1

ความสามารถ ทำอะไร ตอบคำถามไหน
Workflow History Signing ใส่ cryptographic signature ให้ history record ใครแก้ก็จับได้ "Audit record นี้โดนแก้หรือเปล่า?"
Workflow History Propagation ส่ง execution lineage ติดไปกับ request ข้าม workflow, service และ app "Request นี้เริ่มมาจากไหนจริงๆ?"
Workflow Attestation Activity ได้ execution context ที่ verify ด้วย cryptography ได้ "Call นี้มาจาก workflow ที่อนุมัติแล้ว หรือมีคนแอบข้ามขั้นตอนตรวจมา?"

Diagrid สรุปไว้ดีจนน่าหยิบมาใช้ต่อ: SPIFFE ตอบว่า "คุณเป็นใคร" ส่วน Verifiable Execution ตอบว่า "คุณมาถึงตรงนี้ได้ยังไง"1 สำหรับ agent ที่โอนเงินได้ คำถาม "มาถึงตรงนี้ได้ยังไง" คือคำถามด้าน compliance โดยตรง Attestation คือสิ่งที่กันไม่ให้ caller ยิงตรงเข้า activity issue_refund เพื่อข้าม approval gate > $100 เพราะ activity เรียกขอหลักฐานได้ว่าโดนเรียกมาจาก workflow path ที่ sign แล้วจริงๆ

ถึงตรงนี้ audit trail ไม่ได้แค่มีอยู่ แต่แก้ย้อนหลังแล้วจับได้ History ที่ sign, propagate และ attest แล้ว ยื่นให้ auditor หรือใช้ในศาลได้ ไม่ใช่แค่เอาไว้ให้ on-call engineer เปิดดู

ระวังเรื่องความ mature: Verifiable Execution เพิ่งออกเมื่อ 11 มิถุนายน 2026 และประกาศของ CNCF ยังเป็นแค่ระดับแนวคิด ไม่มีตัวอย่าง code1 ให้ถือว่า configuration surface ยังเปลี่ยนได้ ลองทำ prototype ตาม release notes ของ Dapr 1.18 กับ docs ของ Diagrid Catalyst ไปก่อน และอย่าเพิ่งเอาไปไว้บน critical path ของ launch จนกว่าจะรัน flow signing/attestation แบบ end-to-end ด้วยตัวเองแล้ว นอกจากนี้ Dapr 1.18 ยังขยับ Jobs API เป็น stable และ component hot-reloading เป็น GA ซึ่งได้ใช้แน่ถ้าคุณตั้ง schedule ให้ agent รันเป็นรอบ


Pattern: audit trail เป็นทรัพย์สิน ไม่ใช่ต้นทุน

ทีมส่วนใหญ่มอง audit logging เป็นต้นทุน เหมือนภาษี compliance ที่จ่ายแบบจำใจ ลองมองกลับกัน history ของ agent ที่ verify ได้เป็นของชิ้นเดียวที่หลายฝ่ายในองค์กรอยากได้ และเก็บแค่ครั้งเดียวก็พอ ถ้าออกแบบโดยคิดถึงคนใช้กลุ่มนี้ตั้งแต่ต้น record ชุดเดียวจะใช้ได้ทั้ง debug, compliance, security forensics และ cost attribution

Stakeholder จะถามอะไร ต้องเก็บอะไรไว้
On-call / SRE "ทำไม agent ทำแบบนั้น?" Input, เอกสารที่ดึงมา, การตัดสินใจ, tool arg, history ที่ replay ได้
Legal / Compliance "พิสูจน์มาว่า agent ตัดสินใจอะไร และทำตาม policy" Signed history, approval gate, identity ของแต่ละ step
Security "มีใครแก้หรือแอบข้าม agent ไปไหม?" Attestation, lineage propagation, การ verify signature
FinOps "การตัดสินใจนี้เสียเงินเท่าไร และใครเป็นคน trigger?" Token usage ของแต่ละ step, ค่า tool call, conversation/tenant ID

ประเด็นสำคัญคือ record ที่ออกแบบดีชุดเดียวตอบได้ครบทั้งสี่ฝ่าย เพราะ field ที่แต่ละฝ่ายต้องการแทบจะซ้ำกันหมด ทั้ง input, identity, การตัดสินใจ, ค่าใช้จ่าย และ signature ออกแบบ schema ให้ผ่านฝ่ายที่เข้มที่สุด (legal) ฝ่ายอื่นก็ได้คำตอบไปด้วยฟรีๆ

ในทางปฏิบัติ ให้ emit record แบบ signed และ append-only หนึ่งตัวต่อ agent step:

{
  "run_id": "wf-9f3a...",
  "step": 3,
  "agent": "refund-agent",
  "identity": "spiffe://corp/ns/payments/sa/refund-agent",
  "inputs": { "query": "...", "retrieved_doc_ids": ["doc_881"], "scores": [0.71] },
  "decision": { "tool": "issue_refund", "amount_usd": 42, "finish_reason": "tool_calls" },
  "side_effect": { "idempotency_key": "ref_2026...", "result": "ok" },
  "policy": { "gate": "auto_approve_under_100", "passed": true },
  "cost": { "input_tokens": 1840, "output_tokens": 96, "usd": 0.0021 },
  "prev_hash": "sha256:...",
  "signature": "..."
}

prev_hash ร้อย record ต่อกันเป็น log ที่แก้ย้อนหลังแล้วจับได้ (record แต่ละตัวผูกกับ record ก่อนหน้า) ส่วน signature คือสิ่งที่ history signing ของ Dapr ทำให้ในระดับ workflow นี่แหละคือความต่างระหว่าง "เรามี log" กับ "เราพิสูจน์ได้" วันที่เจอคืนเงินผิด $4,200 คุณไม่ต้องเถียงด้วย dashboard สีเขียว แค่ replay run wf-9f3a แล้วชี้ให้ดูพร้อม signature ว่า agent ดึงเอกสารไหนมา และควรไปติดที่ gate ไหน


เรื่องที่ต้องคิดฝั่ง Kubernetes

Agent ไม่ได้รันอยู่ใน notebook แต่รันเป็น async worker บน cluster ของคุณ verification stack เลยต้องคิดเรื่องการ deploy จริงจังด้วย

Runtime เป็น sidecar, tool ก็เป็น sidecar

Dapr รันเป็น sidecar อยู่แล้ว workflow engine, state store และ pub/sub เลยเข้าถึง agent ได้โดยไม่ต้องลาก SDK มาเต็มไปหมด MCP tool server ก็ควรใส่ไว้ใน pod เดียวกันเป็น sidecar ด้วย tool call จะได้วิ่งผ่าน localhost ที่ runtime มองเห็นและ attest ได้ ไม่ใช่ egress ออกไปหา service ข้างนอกที่ไม่มีใครเห็นข้างใน

apiVersion: apps/v1
kind: Deployment
metadata:
  name: refund-agent
spec:
  template:
    metadata:
      annotations:
        dapr.io/enabled: "true"
        dapr.io/app-id: "refund-agent"
        dapr.io/enable-api-logging: "true"   # surface Dapr API calls in logs
    spec:
      containers:
        - name: agent
          image: registry/refund-agent:1.4.0
          env:
            - name: OTEL_EXPORTER_OTLP_ENDPOINT
              value: "http://otel-collector:4317"
        # MCP tool server as a sidecar — localhost, observable, co-scheduled
        - name: mcp-tools
          image: registry/mcp-payments:2.1.0
          ports:
            - containerPort: 8808

การวาง MCP server ไว้ใน pod เดียวกันสำคัญกับ verification ตรงๆ tool call ที่วิ่งผ่าน localhost:8808 ยังอยู่ในขอบเขต identity ของ pod SPIFFE identity ที่ผูกกับ workflow จึงเป็นตัวเดียวกับที่เรียก tool ถ้า egress ออกไปหา tool API ข้างนอก สายนี้ก็ขาดทันที กลายเป็นว่าต้องไปเชื่อขอบเขตของ network แทนที่จะเชื่อ cryptography

ให้เห็น state ของ agent แบบเดียวกับที่เห็น pod

On-call ไม่ควรต้องมานั่ง grep JSON เพื่อดูว่า agent ที่รันอยู่กำลังทำอะไร Workflow management API ของ Dapr ให้ดู state ของ run ได้ตรงๆ query ได้เหมือน resource อื่นใน cluster:

# Inspect a live or completed run by instance ID
curl localhost:3500/v1.0/workflows/dapr/wf-9f3a/...

# Or from inside the cluster, through the sidecar
kubectl exec deploy/refund-agent -c daprd -- \
  curl -s localhost:3500/v1.0/workflows/dapr/<instance-id>

แล้วต่อเข้ากับหน้าจอที่ทีมใช้ดูอยู่แล้ว จะเป็น panel ใน Headlamp, plugin ใน Backstage หรือ datasource ใน Grafana ก็ได้ เป้าหมายคือ engineer ที่โดนปลุกตอนตีสองตอบได้ว่า "agent ตัวนี้กำลังทำอะไร และทำอะไรไปแล้วบ้าง" โดยไม่ต้องอ่าน raw log เลยสักบรรทัด Run ที่หยุดรอ human-approval gate แบบ durable อยู่ ต้องดูออกใน UI ว่ากำลังรออนุมัติ ไม่ใช่ดูเหมือนค้าง

Dead-letter queue คือ incident ของ agent ไม่ใช่ noise ของ infra

ถ้า async agent ทำ message พังจนตกไปอยู่ใน DLQ อย่ามองเป็นแค่สะดุดชั่วคราวแล้ว retry ไปเรื่อยๆ นั่นคือการตัดสินใจที่ล้มเหลว ตั้ง alert จริงจังกับความลึกของ DLQ ใน topic ของ agent และให้ทุก entry ใน DLQ มี run_id ติดมาด้วย จะได้ดึง signed history มาดูได้ทันที Agent ที่ retry เงียบๆ จนตกลง DLQ แล้วเลิกไปเฉยๆ คือ failure แบบเงียบที่ metric ไม่มีทางบอกคุณ


Verification ต้องจ่ายอะไรบ้าง

เรื่องนี้ไม่ฟรี และถ้าทำเป็นว่าฟรี สุดท้ายจะได้ verification stack ที่ไม่มีใครดูแล ดูบิลให้ชัดก่อนตัดสินใจทำ

ต้นทุน หน้าตาเป็นยังไง คุ้มเมื่อไหร่
Latency Signing กับ attestation เพิ่มงาน crypto ทุก step ส่วน durable checkpoint เพิ่ม round trip ไป state store ทุก activity คุ้มกับ action ที่ย้อนกลับไม่ได้ ส่วน agent แบบ read-only บน hot path ข้ามไปได้
Storage Signed history เต็มรูปแบบของแต่ละ run โตเร็ว ทุก input การตัดสินใจ และผลลัพธ์ต้องเก็บไว้ตลอดช่วง audit คุ้มถ้าจะมี auditor หรือ regulator มาถาม ตั้ง retention policy ไว้ ไม่ต้องเก็บทุกอย่างตลอดไป
Operational surface Durable-workflow engine, ระบบ signing/identity (SPIFFE) และ state store เข้ามาอยู่บน critical path คุ้มถ้ารัน Dapr อยู่แล้ว แต่ถ้าต้อง adopt ใหม่ทั้งชุดแค่เพื่อ agent ตัวเดียวถือว่าหนัก
ความเสี่ยงของของใหม่ Dapr 1.18 Verifiable Execution เพิ่งออกมาไม่กี่วัน docs มีแค่แนวคิด ยังไม่มีตัวอย่าง code1 ลอง pilot ได้ แต่อย่าเอา signing flow ไปไว้บน critical path ของ launch จนกว่าจะรัน end-to-end เองแล้ว

กฎคือ ความเข้มต้องเท่ากับ blast radius คืนเงิน $4,200 คุ้มที่จะทำครบสาม layer แต่ agent ภายในที่แค่ร่าง Jira ticket ไม่คุ้ม ให้แค่ Layer 1 แล้วไปทำอย่างอื่นต่อ ถ้า verify agent ที่ความเสี่ยงต่ำหนักเกินไป ก็เท่ากับเผางบ engineering ที่วันหนึ่งคุณจะอยากได้คืน ตอนที่ต้อง ship agent ที่ความเสี่ยงสูง


Checklist: agent ตัวนี้ observable พอจะ ship หรือยัง?

คำถามใช่/ไม่ใช่สิบข้อ ถ้าตอบ ใช่ ไม่ครบทั้งสิบ แปลว่าคุณ reconstruct หรืออธิบายพฤติกรรมของ agent ไม่ได้ ยังไม่ควรปล่อยให้ agent ทำ side-effect ใน production

  • Replay: เอา record ของ run เก่ามา replay แบบ deterministic แล้วได้การตัดสินใจเดิมไหม?
  • Evidence: เก็บ context ที่ดึงมา (doc ID + score) ไว้ด้วยไหม ไม่ใช่เก็บแค่คำตอบสุดท้าย?
  • Decisions: LLM output ทุกตัวบันทึกแบบคำต่อคำ พร้อม finish_reason หรือเปล่า?
  • Side-effects: Tool call ทุกตัวมี idempotency key และบันทึกผลลัพธ์ไว้หรือเปล่า?
  • Durability: Pod crash กลางทางแล้ว run ยังไปต่อได้ โดยไม่ยิง side-effect ซ้ำไหม?
  • Gates: Action เสี่ยงสูงต้องผ่าน durable approval checkpoint จริงๆ ไม่ใช่แค่เขียนห้ามไว้ใน prompt ใช่ไหม?
  • Identity: ทุก step ผูกกับ workload identity (SPIFFE หรือเทียบเท่า) หรือเปล่า?
  • Integrity: History sign หรือ hash-chain ไว้ จนใครแก้ก็จับได้หรือเปล่า?
  • State visibility: On-call ดู state ของ agent ที่กำลังรันได้ โดยไม่ต้องอ่าน raw log ไหม?
  • DLQ wiring: Message ทุกตัวที่ตกไป dead-letter มี run_id ติดไปและยิง alert หรือเปล่า?

สี่ข้อแรกเป็น observability ที่ทำได้วันนี้เลยด้วย OTel + Langfuse สี่ข้อกลางเป็น durability กับ verification คือ Dapr Workflow บวก signing และ attestation ของ 1.18 สองข้อสุดท้ายเป็นงาน operation ที่ทำให้อีกแปดข้อใช้ได้จริงตอนตีสอง


สรุป

Observability กับ verification เป็นสอง layer ไม่ใช่เรื่องเดียวกัน Tracing บอกว่า agent ทำอะไร ส่วน verification พิสูจน์ว่าทำถูก ทำภายใต้สิทธิ์ที่ถูก และใช้หลักฐานที่ replay ได้ Agent แบบ read-only มี Layer 1 ก็เหลือเฟือ แต่เมื่อไหร่ที่ agent แก้ของใน production ต้องมีครบทั้งสาม layer

Layer Tool ตอบคำถาม
Trace OTel GenAI + Langfuse "เกิดอะไรขึ้น?"
Durable Dapr Workflow "Replay ได้ไหม และ crash แล้วรอดไหม?"
Proof Dapr 1.18 Verifiable Execution "พิสูจน์ได้ไหมว่าไม่มีใครแก้หรือแอบข้ามขั้นตอน?"

ก่อน ship ถามตัวเองข้อเดียว: ถ้า agent คืนเงินผิด $4,200 ตอนตีสอง คุณ replay run นั้นได้ตรงทุก step ไหม เปิดหลักฐานที่ agent ใช้ตัดสินใจพร้อม signature ให้ดูได้ไหม และพิสูจน์ได้ไหมว่ามันควรไปติดที่ gate ไหน? ถ้าได้ ship ได้เลย ถ้าไม่ได้ แปลว่าคุณมีแค่ observability ยังไม่มี verification และสำหรับ agent ที่แตะ prod ครึ่งที่ยังขาดคือครึ่งที่สำคัญ


แหล่งอ้างอิง

  • มุมมองเรื่อง agent failure ("ตอบมาอย่างมั่นใจ format เรียบร้อย แต่ผิดทั้งหมด") และข้อเสนอว่า verification เป็นเรื่องของ runtime มาจาก The New Stack2
  • OTel GenAI agent-span conventions (invoke_agent, chat, execute_tool และ attribute gen_ai.*) ยังมีสถานะ experimental ณ กลางปี 2026 แต่ backend หลักๆ รองรับแล้ว3

มีคำถามหรืออยากคุยต่อ? ติดต่อได้ทาง LinkedIn, X หรือส่ง email


  1. Diagrid / CNCF, Introducing Verifiable Execution in Dapr 1.18 (11 มิถุนายน 2026) — Workflow History Signing, Propagation และ Attestation บน SPIFFE identity, Jobs API เป็น stable, hot-reloading เป็น GA เป็นประกาศระดับแนวคิด ยังไม่มีตัวอย่าง code ↩↩↩↩↩↩

  2. The New Stack, Agentic development hinges on verification — for cloud-native software, that's a runtime problem (มิถุนายน 2026) ↩↩↩

  3. OpenTelemetry, GenAI agent and framework span conventions และ GenAI semantic-conventions repository ↩↩

Discussion

Have thoughts on this post? Share them below — questions, corrections, or your own experience are all welcome.