AI Engineering · The Wrenlet Saga · Free article
Make It Fast, and Stop It Falling Over
Wrenlet's drafter is accurate now, but it hangs for eight seconds, the auto-tagging you added returns JSON that crashes half the time, and the first real bill just landed. The model is doing fine work: everything around it is the problem. This chapter is about the engineering that turns a good demo into a product people can lean on.
Chapter 2 is the one where the model stops being the hard part. You'll fix three production wounds that have nothing to do with the model's intelligence and everything to do with how you wire it: a reply that feels frozen because you're not streaming it, structured data that won't parse because you asked nicely instead of guaranteeing it, and a bill that's quietly making each resolved ticket cost more than a human. Each wound opens a full concept page you can go deep on.
You solved trust in Chapter 1: Wrenlet's drafter abstains instead of inventing policies, and agents rely on it. So you got ambitious. You added auto-tagging: every incoming ticket gets an intent, a refund amount, and a priority, extracted by the model, so the queue sorts itself. You shipped it Thursday.
Notice what these have in common: none of them is the model being wrong. The drafts are good, the tags are accurate when they parse, the answers are sound. Every one of these is a failure in the engineering around the model, how you deliver it, how you demand structure from it, how you pay for it. That's what Chapter 2 is: the three disciplines that turn a clever demo into something a business can depend on.
The eight-second spinner
The drafter isn't slow to start, it's slow to finish, and you're making the agent wait for the finish. The model produces the first word in a few hundred milliseconds and the rest over the next several seconds, one token at a time. Right now you're hiding all of that behind a spinner until the last word lands. Show the words as they arrive instead, and the wait: the same wait, stops feeling broken. Same total time, completely different experience:
The interactive version of this example is available when JavaScript loads.
The number the agent feels is when the first word appears, not the last. Streaming isn't a cosmetic animation, it's the model's own generation rhythm made visible, and getting it right (plus not letting a proxy silently re-batch it, and cancelling replies nobody's reading) is its own small craft. The streaming page is the full read.
The JSON that won't parse
Your auto-tagging asks the model to “respond in JSON,” and half the time it wraps the answer in a code fence, or opens with “Sure! Here's the JSON:”, or writes $50 where you wanted 50. JSON.parse throws, and the ticket falls through. The fix isn't a better prompt, it's a stronger guarantee. You can compile your schema into a grammar and force the model to stay inside it, so the structure cannot break.
But a guarantee about the shape is not a guarantee about the value, and that distinction is the one that would have saved you a much worse Friday. Every output below is 100% schema-valid, and some of them would refund a customer ten times too much. Click through:
The interactive version of this example is available when JavaScript loads.
So the real design is two layers: constrain the structure so it always parses, and add a semantic check for the meaning, a rule that a refund can't exceed the charge on file, that an intent has to be one the ticket supports. Valid is the floor, not the finish line. The structured outputs page walks the whole ladder, from asking nicely to a real guarantee.
The bill that made your co-founder wince
The invoice is real, and the arithmetic behind it is worth doing yourself before you scale, because it surprises people in two ways. The first is the per-token price: output costs about five times more than input. The trap is assuming that settles where your money goes. It does not, because there is usually far more prompt than reply, and the five turns into an exact rule you can check below. Your prompt has to be more than five times your reply before the input side takes over the bill. Wrenlet's tagging call is nowhere near that, so its money is going out with the reply. The drafting call, with a system prompt and a retrieved doc in front of a short answer, is well past it. Same product, same week, opposite advice. The second surprise is that a single resolved ticket is not one call. It is a chain of them, read, search, draft and tag, each re-sending the growing context, so the honest unit is the task and not the call. Slide the two token counts until the split bar flips, then turn on agentic mode and watch the bill jump:
The interactive version of this example is available when JavaScript loads.
The way out isn't one trick; it's a set of levers pulled in order, cap the output, trim the prompt, route easy tickets to a cheap model and hard ones to a strong one, cache the parts that don't change, and a habit of measuring the one number that matters: cost per resolved conversation, failures included. Some of those levers even fight each other. The cost optimization page is the field guide.
What you ship this sprint
None of these fixes touches the model. They are all about the system you wrap around it, which is the same move three times: stop hoping, start engineering. Turn them on one at a time and watch which number each one moves. One of them moves a number you are not expecting.
The interactive version of this example is available when JavaScript loads.
Two of those sixteen wirings are worth sitting with. Constraining the schema doubles the over-refunds, and it did not create that bug, it uncovered one that the crash had been hiding: a ticket that never parsed was never tagged, so it never refunded anything. And capping the output puts a small crash rate back, because a reply cut off mid-object is not valid however well the grammar constrained it. Fixes that pull against each other are the normal case, not a sign you did something wrong.
The pattern from Chapter 1 holds: you didn't learn a bag of tricks, you learned that the model is one component in a system, and most of the reliability lives in the wiring. A capable model delivered badly feels broken and costs too much; the same model, wired with care, feels instant and turns a profit.
Go deep on the three that matter
The Chapter 2 reads
- LLM Streaming, why replies stream, why it's the decode phase made visible, the proxy trap that silently un-streams you, and how a closed tab costs money.
- Structured Outputs: the ladder from prompt-and-pray to a real guarantee, how constrained decoding works, and the distinction that saves you: valid is not correct.
- LLM Cost Optimization: the cost model that surprises everyone, the levers that move the bill (and the ones that backfire), and measuring cost per resolved outcome.
Where the story goes next
Wrenlet is fast, reliable, and affordable now. Then the head of support reads a batch of replies and frowns: they're correct, but they sound like a generic chatbot, not like Wrenlet, and definitely not like Wrenlet's best agent. The model doesn't know your voice, your policies, or your product's quirks, because you never told it. That is the next crisis: shaping what the model says with system prompts, examples, and everything you pack into its context. That is Chapter 3: Make It Sound Like Us.
By GOAT Engineer. Back to The Wrenlet Saga. Privacy Policy · Contact.