We Replaced a Manual Workflow With an AI Agent: The Architecture

November 23, 202610 mins
Replacing a manual workflow with an AI agent — Unsplash
Most of what we shipped as an "AI agent" is plain code. That's why it works.

Xperiencify is a gamified course platform for coaches. Coaching Genie is a coaching platform we've worked on with Milana Leshinsky for five years. On both, content-idea research used to be manual work. Now it runs end to end without anyone copying and pasting.

Manual content research looks much the same wherever you find it. Someone reads the coach's material and checks what the audience keeps asking. They draft a list of ideas, rewrite the weak ones, format the result and paste it where the coach will see it. Every step moves text from one document to another, and next week it starts over.

When we automated it, we gave the model the smallest job we could. It isn't one program. It's a few pipelines across the two products, and they share one shape. This post is that shape, with the line between what the model does and what code does. If you read AI agent vs n8n vs custom code, this is the same argument running in production.

The rule we built by

Code does every step that has one right answer: fetching, parsing, matching, checking, saving, charging. The model does the steps that need judgment, like reading a transcript for the useful part or writing a draft. When a step could go either way, it goes to code. Code is cheaper, and when it fails, it fails the same way twice.

1. Intake: a form, not a chat box

The pipeline starts from what the coach already has: answers to a short set of questions about their audience and offer, plus their own documents and videos. Documents become text through plain extraction or OCR. Videos go through a speech-to-text model, which is the first model call in the pipeline and a narrow one.

We skipped the chat box on purpose. A chat box gets whatever the coach remembers to type that day. A form gets the same fields every time, and every later step depends on that.

2. Context: a fact sheet built by code

Before the model writes anything, code assembles what it's allowed to use. Names, prices and durations are pulled from the coach's answers with plain pattern matching. Empty sections are dropped, so the model never sees a heading with nothing under it and fills the gap on its own.

Source material is split into pieces and stored in a searchable index. When the pipeline needs material for the next item, code searches the index and skips anything an earlier item already used. That's how the list avoids repeating itself without asking the model to remember what it wrote.

3. Research: code fetches, the model reads

Sometimes the coach's material doesn't cover a topic. Then code calls a search API and, once the results are ready, hands them to a summarizing step. Sending the query and keeping track of what came back are code. Reading the results is the only part that needs a model.

Split your own workflow

Describe a manual workflow step by step and get a first cut of which steps need a model and which are plain code.

“|”

4. Generation: small model steps, checked by code

Depending on the job, the model writes in one call or in stages: plan the list, then draft and revise each item. Then code checks every item against rules, such as required markers and keyword lists. Only the items that fail go back to the model, and each section gets at most two rewrites.

A rule check costs nothing. A full regeneration costs a whole call and can break the items that were already fine.

5. Approval: the coach stays the editor

The output is a draft, and the coach decides what gets used. They can keep an idea, rewrite it, regenerate one item or ask for more. When they ask for more, the earlier results go along with an instruction not to repeat them. Ratings and saved items are stored with each result.

6. Log and cost: every call leaves a record

Every model call logs its token usage. Where coaches pay per generation, the credit is reserved before the call and refunded if the call fails, so nobody pays for an error. Output length is capped. The stable part of each prompt goes first, so the provider's prompt cache can reuse it.

7. Retry path: assume every step fails sometimes

Long steps run as background jobs with a status record. A scheduled job restarts any task that has been stuck for 15 minutes, up to three times. Model responses are validated against a fixed schema before anything is saved, so a malformed answer never turns into a half-saved record.

The split, step by step

StepModel or code
Turn documents into textcode
Turn video into textspeech-to-text model
Build the fact sheetcode
Find source material, skip what's usedcode, over a search index
Search the web when material runs outcode fetches, a model summarizes
Plan and draft the ideasmodel
Check each item against rulescode
Rewrite the items that failed, at most twicemodel
Log usage, reserve or refund credits, savecode
Keep, edit, regeneratethe coach

What we'd add from day one next time

None of these pipelines has a fallback model. When the provider has a bad afternoon, jobs wait and retry instead of switching. That's acceptable for content research. For anything a customer waits on, I'd put a second model behind a gateway in week one.

We'd also make the research step fail loudly. A web search that fails quietly produces a list that looks complete and isn't.

Is someone on your team still copying between documents every week?

We map the workflow, split it into code steps and model steps, and ship it with approval and a retry path built in. Flat price, one senior engineer, your repo and your cloud account. Send your email and we'll set up a 30-minute call within 24 hours.

Is your workflow a candidate?

The workflows worth automating first share a few traits. Count how many fit yours.

  1. It runs every week or more often.
  2. Its inputs are digital and already exist somewhere.
  3. A person can check the output in a couple of minutes.
  4. Most steps have one right answer, and only a few need judgment.
  5. A mistake costs a rewrite, not a refund.
  6. Someone owns the result and will review it.

Five or six: build it. Three or four: automate the code steps first and leave the judgment to a person. Fewer than that: keep doing it by hand for now.

What a first version looks like

  • Week 1: write the manual workflow down step by step, mark each step as code, model or person, and collect 20 real examples of good output.
  • Weeks 2 and 3: intake and the fact sheet with its rule checks, then the model steps, tested against the 20 examples.
  • Week 4: the approval screen and the retry path, then real users.

Related reading

The service: AI Product Development. The products: Coaching Genie and Xperiencify.

Enjoyed this article? Share it with others

Related Posts