Uncategorized

Building an AI Agent That Actually Works in Production

Most AI agents fail in production. Here's what separates working systems from expensive chatbots that break when they meet real users.

Most AI agents never make it past a demo. They work fine in your Jupyter notebook or on a Wednesday afternoon with your co-founder, then hit production and immediately start hallucinating, timing out, or confidently giving users wrong answers. The gap between “works locally” and “works at scale with real money on the line” is where most teams get buried.

We’ve shipped AI agents that handle real transactions, integrate with live databases, and don’t embarrass you in front of customers. The difference isn’t magic-it’s architecture, error handling, and brutally honest testing. Here’s what matters.

The Production Reality Check

An AI agent in production faces three problems your prototype never did:

  • Latency matters. A 5-second response time is fine for a prototype. A user waiting 5 seconds for your agent to book a meeting or pull data will assume it’s broken. You’re competing against instant expectations.
  • Edge cases are infinite. Your test data was clean. Real user inputs are typos, abbreviations, contradictions, and edge cases you didn’t imagine.
  • Failures are visible. A hallucination in your lab is “interesting.” A hallucination that tells a customer their account is closed is a support ticket and a reputation hit.

The first thing we do on any agent project is kill the assumption that a smart model solves everything. It doesn’t. The model is maybe 40% of a working system.

Architecture: It’s Not Just a Wrapper Around an API

A lot of teams build an agent like this:

  1. User message comes in
  2. Throw it at the LLM
  3. LLM returns a tool call
  4. Execute the tool
  5. Return the result

This is how you end up with an agent that occasionally calls the wrong tool, invents parameters, or gets stuck in loops. Real production agents need a proper state machine.

Here’s the structure that works:

  • Input validation layer – Parse and clean the user input before it ever touches the model. Catch nonsense early. Standardise formats.
  • Context builder – Assemble what the agent actually needs to know: user history, relevant data, permissions, constraints. Don’t dump everything into the prompt.
  • Tool definition layer – Your tools should be strict. Enforce schemas with validation. If a tool expects an integer ID, reject strings. Make tools fail loudly.
  • Execution sandbox – When the model calls a tool, run it in a controlled environment. Catch exceptions. Log everything. Have a fallback.
  • Output validation – Before you return anything to the user, verify the agent didn’t hallucinate. Check the response against what actually happened.
  • Retry logic – Some failures are transient. Build exponential backoff for database timeouts, API rate limits, temporary service issues. Some failures mean “ask the user for clarification.” Know the difference.

This sounds like a lot. It is. But it’s the difference between an agent that works three times a day and one that works thirty times.

Model Selection and Token Economics

The model you choose affects both speed and cost in ways that matter at scale.

GPT-4 is clever but slow and expensive. A request might take 2-4 seconds, and costs roughly AUD 0.03-0.15 per typical interaction depending on context length. If you’re aiming to run 1,000 agent calls a day, you’re looking at AUD 30-150 just in model costs. Claude is similar territory. For some use cases that’s fine. For high-volume or real-time work, it’s not.

Smaller models like Llama or Mistral (7B-13B) are fast (sub-second response times) and cheap (AUD 0.001-0.005 per call), but they’re less reliable at complex reasoning and tool-calling accuracy. They hallucinate more. They need tighter control.

Our approach: start with what works, not what’s fashionable. If your agent needs to reason across five data sources and make a business decision, a smaller model will disappoint you. If it’s mostly routing requests and fetching data, a smaller model is smart economics. Test both. Measure latency and accuracy in your actual use case, not on benchmarks.

One thing teams consistently get wrong: they build the whole agent on GPT-4 for development, then try to swap in a cheaper model at the end. The whole system breaks. Build cost awareness into your choice from week one.

Testing Before Production Isn’t Optional

Manual testing of AI agents is useless at scale. You need automated tests that check whether your agent actually works.

Set up a test suite that includes:

  1. Happy path tests – The agent receives a normal request and produces the right output. Simple, but you’d be surprised how many agents fail these.
  2. Hallucination tests – Ask the agent something it shouldn’t know. Verify it says “I don’t have that information” instead of making something up.
  3. Malformed input tests – Send typos, contradictions, incomplete requests. The agent should either handle them gracefully or ask for clarification.
  4. Latency tests – Time every call. Set a maximum acceptable response time. If it breaches consistently, you have an architecture problem.
  5. Tool failure tests – Simulate a database timeout or API error. Does the agent retry sensibly? Does it tell the user what went wrong?

Run these tests daily. Treat a regression like a bug in your Python code-because it is.

Monitoring and When to Escalate

Deploy monitoring that answers these questions every hour:

  • How many requests succeeded vs. failed?
  • What’s the average latency?
  • Which tools are being called most often?
  • Are there patterns in failures (e.g., always fails on dates)?
  • Is the agent making the same mistake repeatedly?

Set up alerts. If latency spikes above 8 seconds, you want to know immediately. If the failure rate jumps from 2% to 15%, that’s worth a page.

Build a human-in-the-loop fallback. If the agent can’t confidently handle a request, it should escalate to a person-a Slack notification, a support queue, whatever fits your operation. An agent that gets stuck trying to be clever and failing is worse than no agent.

Some teams skip this because it feels like admitting defeat. It’s not. It’s how you ship on time and keep customers happy.

The Real Timeline

We ship AI agent MVPs in 28 days. That’s possible because we skip the vanity work (fancy UI, 47 integrations) and focus on making the core loop work: receive input, reason, take action, return result. Everything else is detail.

What takes time: integration with your actual data sources (database, APIs, files), building proper error handling, and testing until you’re confident it won’t embarrass you.

If you’re considering building an AI agent or adding one to your platform, the time to start is now. But start with clear-eyed expectations about what it takes to ship something reliable. Talk to Amora about your build if you want to move faster without cutting corners.

The teams winning with AI agents right now aren’t the ones with the fanciest models. They’re the ones with clean architecture, strict validation, and the discipline to test properly before they hit production.

Got something you want built?

Amora Digital is an Australian software and AI agency. We scope it, build it, and ship it – live in 28 days. No offshore teams. No surprises.

Book a discovery call

Ready to stop guessing and start growing?

Book a 30-minute strategy call. No pitch, no pressure — just a clear read on what's working, what isn't, and where the lift is.

Book your strategy call