# AI Coding Assistant Rules Pack (`AGENTS.md`, `.cursorrules`, `CLAUDE.md`, `GEMINI.md`)

Companion resource from **AI Agent Observability** by Dany Paredes ([danywalls.com/book](https://danywalls.com/book)).
Copy the template below into the root of your repository as `AGENTS.md`, `.cursorrules`, `CLAUDE.md`, or `GEMINI.md` so your AI coding assistant builds observable, bounded, and safe agents from day one.

---

```markdown
# AI Agent Observability & Production Standards

Whenever you create or modify an AI agent, flow, or tool in this repository, you MUST enforce the following rules:

1. **No Blind Agents:**
   - Every agent entry point must be instrumented with Genkit (`ai.defineFlow` + `ai.run` + `setCustomMetadataAttributes`), LangSmith (`traceable`), or OpenTelemetry (`gen_ai.*` semantic conventions).
   - Always attach `thread_id`, `customer_tier`, and `prompt_version` to the root trace metadata.
   - Always return `{ runId, traceId }` alongside the agent response so the UI can attach user feedback.

2. **Bounded ReAct Loops & Lean Tools:**
   - Never leave an agent loop unbounded. Always set `maxTurns: 5` (Genkit) or `toolCallLimitMiddleware` + `modelCallLimitMiddleware` (LangChain).
   - Tools must validate inputs with strict Zod schemas (`z.object(...)` with `.describe()`) and return ONLY the minimum fields required by the LLM. Never return raw database rows or stack traces.
   - When a tool returns a structured business failure (e.g., `{ applied: false }`), explicitly flag the span/run status or attach a tag/metadata key so dashboards do not report a false 0% error rate.

3. **Privacy & Safety by Default:**
   - Scrub PII (emails, payment cards, government IDs, API keys) using `piiMiddleware` and `createSecretAnonymizer()` before traces leave the server.
   - Any tool that mutates billing, deletes records, or sends external communications MUST be gated by `humanInTheLoopMiddleware` or deterministic code checks.

4. **Evaluation Before Merge:**
   - Every new tool or prompt change must include at least one test case in our Golden Dataset verifying both the final answer and the tool trajectory (`trajectory_subset_match`).
```

---

## Bonus: Connect Your Observability MCP Server

If you use **Progress Observability Platform** or **LangSmith**, connect its MCP server to your editor (Cursor, Claude Code, Antigravity, Windsurf). That way, your coding assistant does not just read your rules file; it can query live traces to see why a trajectory test failed or which tool call is burning tokens.
