Instant Actions
AI Engineering
Live Browser Tools
Field Notes••By Eternitech Operator•4 min read

Production AI Agents: Evals and Guardrails

Architecting Production AI Agents: Bounded State Graphs, Evals, and Enterprise Guardrails

Executive Summary: Production AI agents succeed when language models operate inside deterministic state machines rather than unconstrained autonomous loops. By enforcing strict JSON Schema tool contracts, cryptographic idempotency keys, human-in-the-loop approval gates for mutating operations, per-run token budgets, and CI evaluation suites over golden trajectories, engineering teams achieve reliable multi-step automation without hallucinations or runaway cloud bills.

Why Demo ReAct Loops Collapse Under Real Customer Traffic

Across the hundreds of architecture reviews our Miami and Tel Aviv operators run for Seed through Series C engineering teams, we see the exact same failure pattern: a team builds an impressive weekend prototype using an open-ended while (!done) agent loop, ships it to staging, and hits four immediate production walls:

  • Infinite Retry & Cost Spirals: When a downstream CRM or billing API returns an ambiguous 422 validation error, unconstrained agents retry variations twenty times—burning $4.80 in frontier tokens on a single request.
  • Non-Idempotent Side Effects: Network timeouts during tool execution cause the orchestrator to re-invoke a tool that already succeeded upstream, sending duplicate customer emails or double-issuing credits.
  • Prompt Injection Privilege Escalation: Untrusted external text (an inbound support ticket or scraped webpage) instructs the model to call an internal admin tool that shares the same execution context.
  • Silent Regression on Model Updates: Updating a system prompt to fix one edge case breaks twelve previously working workflows because no automated trajectory benchmark exists in CI.

The Four-Layer Operator Blueprint for Production Agents

Running fifteen proprietary SaaS and AI platforms of our own—including Tabitha—forced Eternitech to treat agent orchestration as distributed systems engineering first and prompt engineering second.

Layer Weekend Prototype Pattern Eternitech Production Standard
Control Flow Unbounded autonomous ReAct text loop Explicit typed state graph with max-step & dollar circuit breakers
Tool Contracts Free-form JSON parsed with regex fallbacks Strict JSON Schema constrained decoding (additionalProperties: false)
Write Safety Direct database/API mutation inside LLM callback Redis idempotency lock + RBAC policy check + human approval gate
Release Gate Manual “vibe check” on three prompts 100+ golden-dataset trajectories scored automatically on every PR

1. Typed State Transitions & Constrained Tool Decoding

Instead of giving one mega-agent twenty-five tools and hoping it picks wisely, decompose the workflow into explicit states (classify_intent → retrieve_context → propose_plan → await_approval → execute_idempotent_tool). Each state exposes at most three to five narrowly scoped tools validated with strict JSON Schema contracts—which you can verify directly in our JSON Schema Structured Output Validator.

// Production TypeScript / FastAPI pattern: deterministic guard before tool execution
interface ToolExecutionEnvelope<T> {
  runId: string;
  stepIndex: number;
  tenantId: string;
  actorRole: "viewer" | "operator" | "admin";
  idempotencyKey: string;
  payload: T;
}

export async function executeRefundTool(env: ToolExecutionEnvelope<{ invoiceId: string; amountCents: number }>) {
  // 1. Deterministic authorization independent of the LLM context
  if (env.actorRole === "viewer") {
    throw new Error("FORBIDDEN_ROLE: Refund tool requires operator or admin scope.");
  }
  // 2. Hard policy threshold -> pause state machine for human cryptographic sign-off
  if (env.payload.amountCents > 25_000) {
    return { status: "PENDING_HUMAN_APPROVAL", approvalQueueId: `apr_${env.runId}_${env.stepIndex}` };
  }
  // 3. Idempotent execution lock prevents duplicate side-effects on retry
  return await withRedisIdempotency(env.idempotencyKey, () =>
    billingClient.issueRefund(env.tenantId, env.payload.invoiceId, env.payload.amountCents)
  );
}

2. Context Isolation Against Indirect Prompt Injection

Whenever an agent ingests untrusted third-party text—customer emails, PDF attachments, webhook bodies, or scraped HTML—never concatenate that text into privileged instructions. Process untrusted documents inside a zero-tool extraction call that outputs a strictly typed Pydantic/JSON summary, then pass only validated enum/scalar fields to the tool-capable planner.

3. CI Trajectory Evals & Prefix-Caching Unit Economics

Before our autonomous AI agent engineers expose any workflow to customer traffic, we wire a deterministic evaluation suite into GitHub Actions:

  1. Tool-Selection Precision: Given fifty realistic multi-turn fixtures (including adversarial injection attempts and malformed user inputs), does the planner select the exact expected tool and schema-valid arguments ≥ 98% of the time?
  2. Latency & Cost Budgets: Route intent routing and classification to fast, low-cost models while caching static system schemas via provider prompt prefix caching—routinely reducing monthly inference spend by 45–65% (model your exact traffic in our LLM Token & Prompt-Caching Cost Calculator).

Ready to Ship Agents That Survive Enterprise Security Audits?

Explore Eternitech's AI Agents, Hybrid RAG & MCP Engineering service or book a 30-minute architecture session with an Eternitech Technical Project Manager to review your workflow graph, compliance posture, and rollout roadmap.

Tell us what you're building.

No pitch deck required. Just a description of what you need. We'll come back with a scope breakdown — and we'll be honest if we're not the right fit.

⚡️Scope & architectural analysis in roughly 60 seconds.