Skip to content

Building agents that actually ship

Agents are easy to demo and hard to ship. Guardrails, retrieval, citations, and a refusal path are what separate the ones that survive from the ones that get turned off.

Hasan Abbas Sorathiya3 min read

AI agents are easy to demo and hard to ship. A conversational prototype that can browse your docs and draft a reply takes an afternoon. An agent that reliably takes action in production — without hallucinating a refund, leaking customer data, or costing you dollars per turn — is a different engineering problem entirely.

I've shipped agents inside mobile and web products with real support queues, and the pattern that separates the ones that survive from the ones that get turned off is almost never the model. It's the boundaries around it.

Define the failure mode before you define the capability

Most agent projects start with what the agent "can do": search the knowledge base, write a ticket, update a record. That's the wrong place to start.

Start with what happens when the agent is wrong. If your agent drafts a customer reply, does it send automatically, or does a human review it first? If it creates a support ticket, what happens when it picks the wrong category? If it calls an API, what happens when the API returns a 500 or a 429?

Write the failure modes down before you write the prompt. The answer to each one becomes a guardrail: a human-in-the-loop step, a schema-validated tool call, a rate limit, or a hard refusal path. Guardrails are not an afterthought; they are the product.

Use tools, not prose, for actions

A model that writes "I've refunded your order" in prose has not refunded anything. It has written a sentence. For anything that changes state, give the agent a tool with a strict JSON schema, and require the tool call before any user-facing confirmation.

This is where most agent security bugs appear: an agent that composes an API request from free-form model output is an injection vector. Validate every argument against the schema before it reaches the network, and never let the model construct raw SQL, raw headers, or raw URLs.

Observe the retrieval, not just the generation

If your agent answers questions from a knowledge base, the failure mode is almost always retrieval, not generation. Instrument which chunks were returned, at what rank, and whether a human would have judged them sufficient. If recall is bad, no amount of prompt engineering fixes it.

Run dense and keyword search together, fuse the results, and rerank before generating. Measure retrieval recall separately from answer accuracy on a golden set of real questions. If recall is below roughly 90 percent, stop touching the prompt and fix the retrieval layer.

Give every answer a citation contract

Every answer the agent gives should carry the sources it used, returned as structured data, not prose. Validate that every citation id exists in the retrieved set. Treat an answer with no citations as a failure, not a success. A model that cannot point at a source is usually making something up.

Budget latency and cost like any other requirement

Agents are slow and expensive compared to ordinary API calls. Write latency budgets down and test them like any other non-functional requirement. Stream responses where you can, cache embeddings and retrieval results where you can't, and set hard turn and token limits so a runaway loop cannot silently burn budget.

Ship the refusal path first

The most important feature of a production agent is knowing when not to act. When the user asks something outside scope, when the retrieved evidence is thin, or when the action is high-stakes, the agent should refuse explicitly and offer a human handoff. A refusal is not a bug; it's a trust boundary.

The model will change every few months. These decisions will not. That's the point: a production agent is mostly an observability, validation, and operations system, with a language model at the end of it.

If you're building one and want a second opinion on the retrieval or guardrail layer, send me the details. I've shipped enough of these to know where they fail.

AIAgentsArchitecture

The next one

Get new essays by email

One email when a new essay or app ships. No newsletter treadmill, no noise.

No spam · Unsubscribe anytime

Hasan Abbas Sorathiya

Hasan Abbas Sorathiya

Senior mobile & AI engineer in Dubai. I build iOS, Android and Flutter products, and write about the parts that were hard.

Work with me