How I made an LLM agent reliable

Dwelio’s vendor agent had to source contractors by email, negotiate bids, and advance jobs without dropping state when a reply was late, malformed, or never came.

Agent reliability loop Four stages in sequence: durable Intent, Send via email, Reconcile late or malformed replies, Escalate to a human after retries. Intent Send Reconcile Escalate

The problem — silent stalls at 40% of jobs

The first loop treated each vendor thread as a happy-path conversation. When a vendor ignored a message, sent a PDF instead of a quote, or replied three days later, the agent stalled. Roughly two in five jobs never reached a bid without a human nudge.

The failure mode was not model quality. It was missing ownership of state, timeouts, and recovery — the same class of fault I had already solved for BLE sensors that drop mid-stream.

Approach — queue, reconcile, then escalate

I rebuilt the loop as an explicit state machine on FastAPI and Postgres: every outbound email wrote a durable intent; inbound mail matched by thread id; unmatched or late replies went to a reconcile queue instead of dying on the hot path.

LangGraph owned the decision graph. SendGrid webhooks owned delivery truth. A watchdog reaped intents past SLA and either re-prompted once or escalated to a human with the full transcript attached.

Guards — 3 retries, then a human

Each vendor node allowed three model-assisted follow-ups. After that the job surface showed a single action: take over. No silent loops. No duplicate asks to the same vendor within a cooldown window.

Malformed attachments were parked with a classifier label rather than crashing the worker. The agent continued other branches of the same job.

Outcome — happy path unblocked; stalls became tickets

Jobs that previously froze now either completed the bid round or landed as an explicit ticket with context. The mobile apps (TestFlight and Play) and the web console showed the same state machine — one source of truth.

The shape matches offline-first device work: write locally, reconcile on reconnect, escalate when the protocol cannot proceed. The model is a component inside that protocol, not the protocol itself.

What I would change next

Tighten evaluation with recorded vendor corpora and a regression suite on the graph. Push more of the classify-and-route step on-device where privacy and cost justify it — same conversion discipline as the Core ML vision path.

← Selected work