THINXSTER
Blog/AI Agents
AI Agents10 min readAugust 11, 2026

How to Build AI Agents That Actually Work in Production

Most AI agent projects die between the demo and production. Here's the architecture, the evaluation loop, and the guardrails that separate the two.

RK
Ryan Korsz
Founder & CEO, Thinxster

TL;DR

Most AI agent projects die between the demo and production. Here's the architecture, the evaluation loop, and the guardrails that separate the two.

→ See how this applies to your business (free 30-min call)

Building an AI agent that demos well takes an afternoon. Building one that runs unattended against real customers for six months takes considerably more, and the gap between those two things is where most agent projects die.

The demo works because you drove it. Production fails because reality supplies inputs you didn't imagine, at 3am, with money attached.

Here's the architecture and the process that survives that.

Start by Defining the Job, Not the Agent

The most common mistake is starting with capability instead of scope. "We want an AI agent for customer service" is not a specification, it's a wish.

A buildable agent job has four properties:

  • Bounded. You can enumerate what it's allowed to do. Not "handle customer inquiries" but "answer questions about order status, process returns under $200, and escalate everything else."
  • Verifiable. There's a way to check whether the outcome was correct. If nobody can tell whether the agent did well, you cannot improve it and you shouldn't ship it.
  • Repetitive. High enough volume that automation pays. A task performed four times a month isn't worth building for.
  • Tolerant of a known failure mode. You know what happens when it's wrong, and that outcome is acceptable and recoverable.
  • Write the job description as if hiring a person. If you can't write it clearly enough for a new employee, the agent has no chance.

    The Core Loop

    Every agent, regardless of framework, is the same loop:

    1.

    Observe. Take in the current state — the user's message, the conversation history, retrieved documents, tool results.

    2.

    Decide. The model reasons about what to do next given the goal and the available tools.

    3.

    Act. Call a tool, send a message, write to a database.

    4.

    Observe the result. Feed the outcome back in.

    5.

    Repeat until the goal is met or a stop condition triggers.

    Everything else in agent engineering is making each of those five steps reliable. The frameworks — LangGraph, the Claude Agent SDK, OpenAI's Agents SDK, custom loops — differ mainly in how much of the plumbing they hand you.

    For a first production agent, I'd genuinely recommend writing the loop yourself. It's maybe 200 lines, and understanding it completely is worth more than any framework's convenience when you're debugging a bad conversation at midnight.

    Tools Are the Actual Product

    The model is a commodity. Your tools are what make the agent useful and what make it dangerous.

    Design rules that matter:

  • One tool, one job. A tool called manage_customer that does six things will be called incorrectly. Split it.
  • Descriptions are prompts. The tool description is the only instruction the model gets about when to use it. Write it like documentation for a competent new hire, including when NOT to use it.
  • Validate at the tool boundary, not in the prompt. Never rely on instructions to prevent bad inputs. If a refund tool shouldn't process over $200, enforce that in code. The prompt is a suggestion; the code is a rule.
  • Return errors the model can act on. "Error 400" teaches it nothing. "Customer ID not found — try searching by email first" gets a correct retry.
  • Make destructive actions require confirmation. Anything irreversible — sending an email, charging a card, deleting a record — should either need explicit human approval or be reversible by design.
  • That fourth point does more for reliability than most prompt engineering. Models recover well from informative failures and badly from opaque ones.

    Context Is a Budget, Not a Container

    The single biggest quality difference between amateur and production agents is context management.

    Naive agents stuff everything into the prompt: full conversation history, entire documents, every tool result. Then quality degrades, latency rises, and cost climbs, and nobody knows why.

    What production systems do instead:

  • Retrieve selectively. Pull the three relevant document chunks, not the whole knowledge base.
  • Summarize long histories. Past a threshold, compress older turns into a running summary and keep recent turns verbatim.
  • Strip verbose tool output. A database query returning 400 rows should be summarized before it enters context. The model needs the answer, not the payload.
  • Keep a structured state object outside the model. Order ID, customer tier, qualification score — these should live in your application state and be injected deliberately, not remembered from twenty turns ago.
  • Treat context like a budget you're spending, not a bucket you're filling. Every token you add dilutes attention on the ones that matter.

    Evaluations, or You're Flying Blind

    This is the step that separates people who ship agents from people who demo them, and it's the one most teams skip.

    Build an eval set before you build the agent. Twenty to fifty real cases with known correct outcomes. Pull them from actual transcripts if you have them — real user messages, including the confused and hostile ones.

    Then:

    1.

    Run the full set after every meaningful change. Prompt edits, tool changes, model upgrades.

    2.

    Score against your definition of correct. Some cases are exact-match checkable. Some need a judge model with a clear rubric. Some need a human.

    3.

    Never accept an unexplained regression. If a change improves 40 cases and breaks 3, understand the 3 before shipping.

    4.

    Grow the set from production failures. Every real-world mistake becomes a permanent test case. This is how the system compounds.

    Without this, you're editing prompts based on vibes and the last conversation you happened to read. That approach plateaus fast and then quietly degrades.

    Guardrails

    Layered, because any single layer fails.

  • Input filtering. Reject or flag obviously out-of-scope or adversarial inputs before they reach the model.
  • Tool-level authorization. The agent operates with the minimum permissions the job requires. It should not have a credential it doesn't need for its defined scope.
  • Output validation. Check the response for policy violations, made-up specifics, or anything containing data the agent shouldn't disclose.
  • Hard stops. Maximum turns, maximum spend, maximum tool calls. An agent stuck in a loop should stop, not run all night.
  • Clean escalation. When confidence is low or the request is out of scope, hand to a human with the full transcript and the reason for escalation. A good handoff is a feature, not an admission of failure.
  • Deployment Realities

    Things that only show up in production:

    Latency compounds. Each loop iteration is a model call plus a tool call. Five iterations at two seconds each is ten seconds of silence. For voice agents this is fatal — you need streaming, and you need to fill dead air. For async agents it's fine.

    Cost scales with conversation length, not conversation count. A pathological 60-turn conversation can cost more than a hundred normal ones. Cap turns and monitor per-conversation cost distribution, not just averages.

    Models change underneath you. Pin versions. Re-run your eval suite before adopting a new model, every time, even when it's supposedly better.

    Observability is not optional. Log every turn: input, reasoning, tool calls, tool results, output. When something goes wrong you need the whole trace, not the final message. Budget for this from day one — retrofitting it is painful.

    What This Looks Like Concretely

    Our AI caller agents are a working example of everything above. The job is bounded: call an inbound lead within 90 seconds, confirm fit and urgency through natural conversation, book qualified leads onto a calendar, escalate the rest.

    The tools are narrow — check calendar availability, book a slot, look up service area, write to the CRM, escalate to a human. The context is managed tightly because voice latency punishes bloat. The guardrails are hard-coded: it cannot quote a price it wasn't given, it cannot book outside real availability, and it hands off cleanly when a caller asks something outside scope.

    The eval set is built from real transcripts, and every conversation that goes badly becomes a permanent test case. That's why the qualification questions in month six are sharper than the ones in week one.

    62%
    average lead qualification rate across client accounts
    90s
    response time on every inbound lead, day or night

    A Realistic First Build

    If you're starting: pick a task that runs 50+ times a week, has a clearly checkable outcome, and where being wrong costs an apology rather than money. Build the loop yourself. Give it three tools. Write twenty eval cases before you write the prompt. Ship it with a human reviewing every output for the first two weeks, then sample.

    You'll learn more from that than from six months of architecture discussion.

    If you'd rather have a production agent built against your actual business process than build the muscle yourself, [book a free strategy call](/book) — that's what we do, and we'll tell you honestly whether your use case is a good agent job or not.

    Free Weekly Briefing

    One AI Marketing Tactic.
    Every Tuesday. Free.

    What's actually working across our client accounts right now — ROAS moves, follow-up sequences, creative angles. The stuff that isn't in any blog post yet.

    No spam. Unsubscribe anytime. 1,200+ business owners already in.

    Ready to Deploy

    SEE THIS IN
    YOUR BUSINESS.

    30 minutes. We scope the exact systems that apply to your situation and give you a plan.

    ★★★★★ Trusted by 47+ local service businesses

    BOOK A STRATEGY CALL →