Step 15 of 16
Trace the full run, protect data and tools, register services in ASP.NET Core, and prepare hosting.
ปิด production gaps ด้วย OpenTelemetry, tenant isolation, data controls, health checks และ failure tests ครับ
Level: Advanced
ก่อนเปิดให้ผู้ใช้ คุณต้องมองเห็น agent run ทั้งเส้นและจำกัดข้อมูลที่แต่ละ component เข้าถึงครับ Agent Framework รองรับ OpenTelemetry ผ่าน builder API จึงเชื่อม trace ของ model, tool และ application ได้
เลือก hosting model, protocol และ durability แยกกัน จากนั้น deploy ด้วย identity, telemetry, health checks, release gates และ rollback ครับ
using OpenTelemetry;
using OpenTelemetry.Trace;
const string sourceName = "TPCoder.KnowledgeAgent";
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource(sourceName)
.AddConsoleExporter()
.Build();
AIAgent observedAgent = agent
.AsBuilder()
.UseOpenTelemetry(sourceName: sourceName)
.Build();
ส่ง correlation ID จาก HTTP request ผ่าน background job, retrieval และ tool call ครับ Metric ขั้นต่ำควรมี run count, error rate, latency, input/output tokens, tool failures, approval rate, retrieval hit count และ refusal rate
EnableSensitiveData ควรเป็น false บน production ครับ เปิดเฉพาะ isolated troubleshooting environment ที่มี access control กับ retention สั้น
Prompt injection ในเอกสารถือเป็น untrusted data ครับ บอก agent ให้ใช้ retrieved text เป็นข้อมูลอ้างอิง ไม่ใช้เป็น system instruction และบังคับ tool policy ใน code
ย้าย agent registration เข้า ASP.NET Core DI กำหนด health checks แยก readiness ของ app จาก dependency ภายนอก และใช้ queue สำหรับงานยาว Deploy แบบ container ด้วย non-root user, resource limits และ graceful shutdown
เลือกสามเรื่องแยกกัน:
| Decision | Options |
|---|---|
| Who runs infrastructure | Foundry Hosted Agents or self-hosting |
| How clients connect | Responses, A2A, AG-UI, MCP, or application API |
| How work survives failure | Session store, workflow checkpoint, or Durable Extension |
Foundry Hosted Agents เหมาะเมื่อคุณต้องการ managed scaling และ session lifecycle ส่วน self-hosting เหมาะเมื่อ application ต้องคุม routes, identity, storage, network และ deployment เองครับ
เพิ่ม integration test สำหรับ authentication, tenant isolation, approval, timeout, cancellation และ provider outage จากนั้น run load test ที่มี multi-turn session กับ RAG พร้อมกันครับ
Deploy staging ด้วย production-like identity และ network policy Run smoke, evaluation, load, restart, rollback และ secret-rotation tests ตรวจ dashboards กับ alerts จาก generated failures ก่อนเปิด traffic
Release ต้องผ่าน threat model, dependency scan, evaluation thresholds, SLO budget และ rollback rehearsal Runbook ต้องระบุ owner, dashboard, common error codes, disable switches, index rollback และ provider outage behavior
ส่ง hosting decision record, infrastructure definition, CI/CD gates, dashboards, alerts, health endpoints, rollback steps และ incident runbook