AI & Agents·5 min read·January 10, 2024

What building custom AI agents actually looks like

Most writing about AI agents is about the demo. This is about the other 90% - the boundaries, the validation, the decomposition and the unglamorous engineering that decides whether an agent survives contact with production.

There is a lot of writing about AI agents, and most of it is about the demo — the part where the agent does something impressive in a controlled setting and everyone is delighted. We have built agents into real products, and we can tell you that the demo is roughly ten percent of the work. This post is about the other ninety.

An agent is a system, not a prompt

The first reframe that matters: a useful agent is not a clever prompt, it is a system that happens to have a language model in it. The model is one component. Around it sits input handling, output validation, tools, state, error handling, observability and a control flow that decides what happens next. If you build the prompt and treat the rest as glue, the rest is where it breaks.

So we build agents the way we build any system — with boundaries, contracts and the assumption that every part will eventually misbehave.

Decompose, relentlessly

The single most reliable technique we have is decomposition. One model call that has to do five things is hard to test, hard to debug, and fails in ways that are hard to attribute. Five calls that each do one thing are each easy to test, easy to debug, and fail in ways you can point at.

On the brand-profiling agent we built for Pockla, this was the whole game — one pass per dimension instead of one prompt for everything. Every pass became individually testable. When something was wrong, it was wrong in a specific, locatable place. A monolithic prompt does not give you that, and you feel the absence of it every time you try to fix something.

The agent's output is untrusted input

This is the lesson that costs people the most time, so we will be blunt about it: whatever an agent produces, treat it the way you would treat data from outside your system. Validate it at the boundary, hard, every time.

A language model will usually return what you asked for. Usually. It will also, often enough to matter, return valid JSON that is missing a field, or the right shape with a value that makes no sense, or something almost-right that a downstream component then chokes on with an error that points nowhere near the real cause. If you validate strictly at the agent boundary, a bad output fails immediately and legibly. If you do not, it leaks three steps downstream and you spend an afternoon tracing it back.

Schema validation on every agent output is not defensive over-engineering. It is the difference between a debuggable system and a haunted one.

Make the model do the work, not grade the work

A pattern we keep returning to: models are much better at doing a task than at rating one in the abstract. Asking "is this good, score 1-10" gets you a confident number that does not mean much. Asking the model to produce the actual artifact — the draft, the answer, the plan — and then judging that gets you something you can inspect. On Pockla's content scoring, switching from "rate this moment's usability" to "draft the actual content angle, then we score the draft" was the change that made the feature trustworthy.

Plan for the failure cases, because they are not edge cases

With an agent, the failure cases are not rare events at the margins. They are part of normal operation, and they need designed responses:

  • The model returns something malformed. Validate, reject, retry with a bounded policy, and have a path for when retries are exhausted.
  • The model is confidently wrong. Where the cost of being wrong is real, you need a check — a verification pass, a constraint, a human in the loop — not blind trust.
  • The model is slow. Latency is a failure mode. An agent that is correct but takes thirty seconds has failed a user-facing requirement.
  • Cost runs away. Every model call is a line on a bill. An agent that loops, or retries without limit, or fans out unboundedly, is a cost incident waiting to happen. Budget it like you budget any resource.

Observability is not optional

When an agent does something strange in production — and it will — you need to be able to see exactly what it received, what it produced, which tools it called and why it went the way it went. Without that, every incident is a guess. We log the full trace of an agent's decisions, because an agent you cannot inspect is an agent you cannot actually run.

What we would tell you

If you are putting an agent into a real product:

  • Build it as a system. The model is a component. The engineering around it is the product.
  • Decompose. One job per call. Small pieces are testable pieces.
  • Validate every output at the boundary. The agent's output is untrusted input. Full stop.
  • Make the model produce artifacts, then judge the artifacts. Do not ask it to grade things in the abstract.
  • Design for the failure modes — malformed, wrong, slow, expensive — because they are normal, not exceptional.
  • Log everything. An agent you cannot inspect is one you cannot trust.

The demo is the easy ten percent and it is the part everyone shows you. The ninety percent that follows is ordinary, careful software engineering. That is not a disappointment. That is the good news — it means you already know how to do it.

AI AgentsLLMProductionEngineering

Working on something similar?

We have probably hit the exact scaling or architectural bottlenecks you are navigating. Book a call and we'll walk through the technical trade-offs.