Workflow or Agent: Where the Decisions Live
TL;DR
The first architectural decision in an LLM automation is how much of the work the model does and how much code does. On a customer support automation, we gave code the order of operations and the model one job: reading the message. That guaranteed a security check before any unlock, but what drove the decision was stakeholders wanting their templates. It worked for the commonest requests and ran out on the rest: rarer requests, and common ones on accounts in states we had no rule for. Next time I would make the agent the default, and move a request type into code once it is common and the agent gets it wrong, or its action can’t be undone.
The system as one map: a message goes to a workflow in code or to an agent, both act through the same tools, and experts grade the replies. Their feedback goes back into both: new branches for the workflow, the prompt and examples for the agent. Each section’s map highlights its part.
The first design: one agent with every tool
The running example is invented to protect the client, but the project behind it is real. Customers write in to first-level support at Northstar Bank with messages like this:
To answer Alex, something has to work out what Alex wants and which account is theirs, check whether it is safe to help, and choose the reply. Each of those steps can be code or the model.
Two facts pushed us toward code. No model was trained on Northstar’s escalation rules or on Alex’s account. And no test can tell us whether a reply to Alex is right, the way a test suite tells a coding agent its code works: someone who knows the bank has to read the reply. The Missing Test Suite makes the longer argument for the second.
The first design we tried left all of it to the model: a single support agent that held every tool (account lookup, security-flag check, send unlock instructions, escalate to security), decided which to call next, and wrote the reply itself.
Nothing in that design guarantees that the agent checks the security flag before it sends unlock instructions, and unlocking a flagged account is an expensive mistake. And if the model chooses the order, a customer’s message can talk it out of the check: that is prompt injection. A check inside the unlock tool would close that hole, but that is code deciding the order again. As the ServiceNow CEO put it: people forgive other people for making mistakes. They don’t forgive software.
In practice, though, a different complaint drove the decision: stakeholders said the agent’s replies didn’t match the established message templates. We tried to fix that in the prompt, but a prompt makes a template more likely, never certain. Judged on template match, code can’t lose, because code picks the template. So we tried a workflow, where code decides the next step and the model only fills in single steps.
For well-understood requests, the workflow works
We labelled and clustered a sample of past tickets with an AI-assisted, iterative process. A handful of intents accounted for the large majority of them, which encouraged us to build one.
To get both the ordering guarantee and the fixed templates, the workflow kept code in charge of the sequence and gave the LLM one job: reading the message. Once the tree has an Account locked intent, the LLM recognises Alex’s message as one and pulls out the identifier, the account number or the name and branch. Everything after that is a small decision tree in code: look up the account, check the flag, then send the unlock-instructions template or escalate to security. The flag check comes before any unlock instructions, every time.
For an intent like this one, the workflow was the clear fit. The logic is explicit and the cases are few: the account is flagged or it isn’t. Because code selects the reply, the template is guaranteed rather than prompted for. The LLM’s part is narrow enough to have its own evals, a cheaper model, or a Named Entity Recognition model in its place. And a fix is local: when a message is misread or a policy changes, you edit the extraction prompt or add a branch, and you know what the next message of that shape will do.
The full version is the four-step pipeline in Architecture of a First-Level Support Automation, with the typing that holds its seams together in Type-Safe Hybrid Workflows with Pydantic AI.
A workflow needs a branch for every cell
We ran the pipeline in shadow deployment: it drafted a reply to every incoming ticket, subject-matter experts graded the drafts, and nothing was sent automatically. Each round of their feedback landed a new branch in the tree, and for a while that worked.
But a workflow can only answer a request if someone has written a branch for its intent and the fetched data behind it. Those branches form a grid: every kind of request against every state its record can be in.
Had Alex’s account been closed, the request would land top right, in a cell nobody decided.
Every question mark is a decision someone has to make, write down and keep current. This toy already leaves seven open, and we had many more than three of each. A handful of intents covered most messages, not most cells: each intent still fanned out across every state its record could be in, and every new state meant another branch and another template.
Schematic, not measured: branches grew faster than the share of tickets the tree could answer.
The agent got the leftovers
Eventually the workflow wasn’t expressive enough, so we bolted an agent onto the tree as a fallback for the “Other” leaves it couldn’t cover (the fallback in the plan-generation step). Code stayed the default, and the agent only got the requests the code hadn’t reached yet.
The grading worked against it, too. Drafts were scored on template match rather than on whether the customer’s issue got resolved, so a clearer, more helpful answer in the agent’s own words still scored badly, purely for departing from a template. We were asking the agent to be a worse workflow.
Before the tree had an Account locked intent, Alex’s message landed in “Other”, and the agent’s draft asked Alex for the email address on the account. It was rejected for “Wrong process”. The reviewer wrote: “We have the account number, so look them up: never ask for what we can find. Locked accounts get the unlock link, or go to security if flagged.” With code as the default, our fix was a new intent. The reviewer’s two sentences could just as well have gone into the agent’s prompt.
Next time: make the agent the default
Compare the map in “The agent got the leftovers”: the same routes, the default swapped.
I would invert the default, following Will Larson’s Building an internal agent, which starts every workflow with the LLM in charge. A path graduates into a workflow only once it shows up often and the agent handles it unreliably, or when the action is irreversible enough that you don’t want a model deciding it. Rarer request types stay with the agent. Anthropic has since reached the same conclusion.
Schematic, not measured: request types by how often they come in. The agent drafts replies for all of them first; code takes a type over only once it is common and the experts keep rejecting the agent’s drafts, or its action can’t be undone.
I would start with an agent with a set of tools. For Alex, it would read the message, look up NSB01234, check the flag and propose sending the unlock steps. As in our pipeline, a plan that touches account access would still wait for a person to approve it.
That is also the shortest path into shadow deployment, since an agent with a set of tools is much less to build than a tree of intents, plans and templates, and every week before the experts see real drafts is a week of grades lost.
The experts’ feedback would reach the agent too, just not as a branch. A rejection like the one above becomes a line in the agent’s prompt, and an approved reply becomes an example it can look up for the next ticket of that kind. A line in the prompt covers every ticket it fits, where a branch covers one cell; but the agent may still not follow it, which is when that request type moves into code.
The agent has its own problems:
- The agent doesn’t shrink the grid; it spares you enumerating it. Enumerating it was where we hit the wall, but skipping a cell is not the same as answering it correctly.
- The agent starts out knowing no more than the tree did. It can read Alex’s record, but how to get Alex back in depends on the bank’s rules, and most of them live in the heads of the people who answer the tickets.
- Resolved tickets need curating. Pointing the agent at all of them is no fix: their resolutions contradict each other and current policy. The examples it looks up have to be chosen and kept current, as the tree’s branches were.
- Past tickets carry personal data. An agent that looks them up can leak one customer’s details into a reply to another; a fixed tree reads only the record of the customer in front of it.
- An agent is mostly judged end to end, so a regression is hard to locate.