# Production AI Agent Observability Checklist (20-Point Audit)

Companion resource from **AI Agent Observability** by Dany Paredes ([danywalls.com/book](https://danywalls.com/book)).
Verify all 20 checkboxes before putting any AI agent in front of real users.

---

## 1. Agent Architecture & Cost Control (Part I)
- [ ] **1. Hard loop cap:** the ReAct loop enforces `maxTurns: 5` (Genkit) or `toolCallLimitMiddleware` + `modelCallLimitMiddleware` (LangChain).
- [ ] **2. Lean Tools:** no tool dumps raw database rows; every tool filters and returns only the 4-6 fields the LLM actually needs.
- [ ] **3. Descriptive Zod schemas:** all tool parameters include clear `.describe()` strings and format validations (`.trim().toUpperCase()` where appropriate).
- [ ] **4. Graceful tool error handling:** when an external API fails, the tool catches the exception and returns structured JSON so the model can recover cleanly.
- [ ] **5. Static prompt prefix first:** fixed instructions sit at the top of the `SystemMessage` to maximize Prompt Caching.

## 2. Tracing & Instrumentation (Part II)
- [ ] **6. Traced entry point:** the agent is wrapped in `ai.defineFlow` (Genkit), `traceable` (LangSmith), or a root `invoke_agent` span (OpenTelemetry).
- [ ] **7. Visible internal steps:** intermediate business logic uses `ai.run()` or child `traceable` functions so there are zero blind gaps in the waterfall.
- [ ] **8. Thread grouping (`thread_id`):** every multi-turn conversation attaches `thread_id` (or `gen_ai.conversation.id`) to trace metadata so full user sessions can be reconstructed.
- [ ] **9. Indexed business metadata:** every root trace records `customer_tier`, `prompt_version`, and `environment`.
- [ ] **10. Non-blocking batch export:** production uses `BatchSpanProcessor` with bounded `maxQueueSize` and `exportTimeoutMillis`, flushing cleanly on `SIGTERM`.

## 3. Pre-Production Evaluation (Part III)
- [ ] **11. Active Golden Dataset:** a versioned dataset exists with at least 20 real-world examples (happy paths, edge cases, and adversarial prompts).
- [ ] **12. Deterministic evaluators first:** formatting, JSON validity, latency budgets, and forbidden phrases are checked with fast, zero-cost deterministic code.
- [ ] **13. Calibrated LLM judges:** LLM-as-a-Judge evaluators use `temperature: 0`, structured Zod schemas, and binary or small integer rubrics.
- [ ] **14. Trajectory evaluation:** tests verify that the agent calls required verification tools (e.g., `checkReturnPolicy`) before taking action.
- [ ] **15. CI/CD quality gate:** no prompt or model change deploys without passing an automated side-by-side experiment threshold.

## 4. Production, Feedback & Security (Part IV)
- [ ] **16. `runId` returned to the frontend:** the API returns `{ runId, traceId }` to connect thumbs-up/down buttons and implicit behavioral signals (human escalation) to the exact trace.
- [ ] **17. Annotation Queue & Data Flywheel:** traces with negative feedback or hallucinations flow into a human review queue and feed back into the Golden Dataset.
- [ ] **18. The 4 Golden Signals with percentiles:** dashboards monitor `P50`/`P95`/`P99` latency, `TTFT`, USD/hour burn rate, error rate, and quality drift.
- [ ] **19. PII & secret redaction:** `piiMiddleware` and `createAnonymizer` / `createSecretAnonymizer` mask payment cards, hash emails, and strip API keys before export.
- [ ] **20. Human-in-the-Loop on irreversible actions:** tools that move money or mutate critical records are gated by `humanInTheLoopMiddleware` or deterministic policy checks.
