Workflow or Agent?
By the Syncfusion DevTutorials team · Last updated
The four shapes of an AI helper inside an app: one model call, a chain, a router and an agent. Learn what each one can do, what it costs, and how to pick the simplest one that works.
Workflow or Agent?
You run an online shop. You want an AI helper in the chat box.
So you build it as an agent. An agent sounds smart.
A customer asks, "What time does your chat team open?"
The agent picks a tool. It searches the help pages. It answers correctly.
But it called the model twice, and it read a long list of tools each time. One simple model call would have given the same answer for a small part of the cost.
This lesson teaches the four ways to build an AI helper, and how to pick the right one.
Simple lesson: the best agent is often not an agent.
A Real-World Example
Think about a busy café.
- A menu board answers "What do you sell?" Nobody has to think.
- The coffee machine follows the same steps for every latte.
- A host at the door sends you to the right counter.
- The manager sorts out the strange problems, such as a lost bag and a wrong bill at the same time.
The café does not send every customer to the manager. That would be slow and costly.
Your app works the same way. Most questions need the menu board. Only a few need the manager.
Simple lesson: use the simplest helper that can do the job.
What You Will Learn
In this lesson, you will learn:
- The four shapes of an AI helper: one call, chain, router and agent.
- What a workflow is, and how it differs from an agent.
- Why an agent costs more time and money.
- How to pick the simplest shape that still works.
- Which messages a workflow cannot handle.
About Shop Helper and the animations
- Every lesson in this course uses one app: an online shop with a chat helper called Shop Helper.
- The animations run Shop Helper on real shop data. Every result comes from that run.
- The AI model in this course is a pretend model. It follows fixed rules, so it gives the same result every time.
- A real model may act a little differently. The ideas stay the same.
How the pretend model decides
Later lessons point back to these rules by number.
- It picks the tool whose description best matches what is still needed.
- It fills tool inputs from the customer's words. If something is missing, it guesses (it may grab any number it saw) unless the tool card says to ask.
- If a tool error says how to fix the problem, it tries again. If not, it repeats the same request or makes something up. Limits and checks in the app must catch both.
- It obeys instructions found inside tool results unless the app marks them as "just data". Even then, a real model may still slip, so the app's checks are the real protection.
- When the chat gets too long, the oldest messages drop out.
Meet Shop Helper
Shop Helper answers customer messages. To do that, it needs two things.
Model call = the app sends text to the AI model, and the model sends text back.
Prompt = the text the app sends to the model: instructions, the customer's message and any pasted facts.
Tool = an action the app can run when the model asks for it, such as looking up an order.
The model cannot touch the shop by itself. It can only ask. The app runs the tool and sends back the result.
Shop Helper has six tools:
- Look up order: finds an order and its delivery date.
- Search help pages: finds a shop rule, such as opening hours.
- Give refund: sends money back.
- Change address: changes where an order goes.
- Send email: emails the customer.
- Pass to a person: hands the chat to the support team.
Each model call costs money and takes time. In this course, cost is shown in coins.
Token = a small piece of a word. Models count text in tokens. (Tokens are covered in Large Language Models.)
Coin = 100 tokens of text the model reads or writes.
Simple lesson: the model decides, and the app does.
The Four Shapes
There are four common ways to build Shop Helper. We call them shapes.
They go from the least freedom to the most.
One Call
One call = a single model call. The help pages are pasted into the prompt, and the model answers.
It is the cheapest and fastest shape. It cannot look anything up.
This works when the needed text is short, such as a few help pages. When the text is huge, such as a whole help centre, pasting it into every call gets expensive. Then let a tool fetch only the page needed (see Observability, Cost and Reliability).
Chain
Chain = fixed steps that a developer writes, always in the same order.
For example: find the order number, look up the order, then write the reply.
Router
Router = one model call that sorts each message to a fixed desk. Each desk is its own chain or one call.
For example: help questions go to the help desk. Order questions go to the order desk.
Agent
Agent = the model picks its own next step, again and again, until the job is done.
Nobody draws its path in advance. It looks at what is still missing and picks a tool for it.
Now watch all four shapes answer the same easy question.
Press Play and watch each lane.
- One call: it answers from the pasted help pages, in one step.
- Chain: it was built for order questions. It finds no order number, so it guesses.
- Router and agent: both get it right, but they make more model calls.
Simple lesson: for an easy question, extra freedom only adds cost.
A Workflow Follows Your Path
One call, chain and router have something in common.
Workflow = a helper whose steps a developer wrote in advance. Chains and routers are workflows.
A workflow is predictable. It does the same thing every time. That makes it cheap and easy to test.
But it cannot add a step it was not given.
Press Play and compare the two paths on the board.
- Workflow: the dashed path was planned. It never visits the help pages, so it guesses the late-parcel rule.
- Agent: it draws its own path. It adds a help search because the question needs it.
- The numbers: they show the order of steps. The agent's path is different from the plan.
Simple lesson: a workflow follows your path. An agent picks its own.
The Router Sorts Messages
A router is still a workflow. It just has more than one path.
It reads the message once and picks a desk. Then that desk's fixed steps run.
Press Play and watch where each message lands.
- One job per message: returns, one order or one address change each fit a desk.
- Two jobs in one message: the late order needs a lookup and a help page. No desk does both.
- No desk fits: the router passes the message to a person. That is safe, but the customer waits.
Simple lesson: a router handles many kinds of message, but only one kind at a time.
When You Need an Agent
Some messages mix several jobs. The mix changes from customer to customer.
You cannot draw one path for all of them. That is when an agent earns its cost.
Watch the four shapes on a message with two parts.
Press Play and watch each lane's stamp.
- One call: it makes up a date. It also says the address changed, but it did not.
- Chain: it gets the real date, but it has no step to change the address.
- Router: it has no desk for two jobs, so a person must answer.
- Agent: it does both jobs, and the shop really shows the new address.
A made-up answer is worse than no answer.
The one call sounded sure. It said the address was changed. Nothing changed in the shop.
Always check what the helper did, not only what it said.
Now look inside the agent, one step at a time.
Press Play and watch the chat window and the shop record below it.
- Each pick: the model looks at what is still not done and picks one tool.
- Each result: the app runs the tool and sends the result back to the model.
- The shop record: it only changes when the "Change address" tool really runs.
- The end: when nothing is left to do, the model writes the answer and stops.
Simple lesson: use an agent when the steps depend on what the message asks.
The Price of Freedom
An agent is not free. Each step adds cost and time.
There are two reasons:
- Every agent model call also carries the list of tools, so the model knows what it can use.
- Every tool result goes back to the model, so the next call is bigger.
Here are the bills for the easy question from earlier.
Press Play and watch the receipts print.
- One call: one line on the bill.
- Agent: two model calls and one tool step, for the same answer.
- The totals: compare the coins and the seconds at the bottom.
Simple lesson: pay for freedom only when the job needs it.
How to Choose a Shape
Start at the bottom and climb only when you must.
The shape ladder
- One call. Does one model call pass every test chat? Stop here.
- Chain. Do the same fixed steps work for every message? Use a chain.
- Router. Does each message fit one of a few kinds? Use a router.
- Agent. Do messages mix jobs in ways you cannot plan? Use an agent.
Test chat = a sample customer message with the answer it should get. You run it to check your helper.
To pick a shape, run your test chats through each shape. Then choose the first one that passes them all.
Many teams work this way. They test a few real messages before they add freedom.
Simple lesson: pick the least freedom that still passes every test chat.
Where This Is Used
AI helpers inside apps come in many forms:
- Support helpers answer customers and fix simple order problems.
- Operations helpers read alerts and logs, and write a short report.
- In-app copilots help a user fill in a form or find a setting.
Each one starts with the same choice: workflow or agent.
Many good products use a router for most messages. They send only the hard ones to an agent.
Simple lesson: most real helpers mix shapes, and agents handle the hard cases.
In Code
Here is the developer view. The code builds three of the four shapes over a tiny fake shop. It uses the same orders as Shop Helper.
One Call, a Chain and a Router
// A tiny fake shop. No real model: plain functions stand in for model calls.
type Order = { id: string; item: string; status: string; arrives: string };
const ORDERS: Record<string, Order> = {
"1042": { id: "1042", item: "Blue running shoes", status: "shipped", arrives: "Thursday 30 Oct" },
"1043": { id: "1043", item: "Desk lamp", status: "packing", arrives: "Friday 31 Oct" },
};
const HELP_PAGES = "Returns: you can return an item within 30 days for a full refund.";
// One call: the help pages are pasted in, one answer comes out.
function oneCall(message: string): string {
return message.includes("return") ? HELP_PAGES : "Sorry, I am not sure.";
}
// Chain: fixed steps, always in this order.
function orderChain(message: string): string {
const found = message.match(/\d{4}/); // step 1: find the order number
if (!found) return "Which order do you mean?";
const order = ORDERS[found[0]]; // step 2: look it up
if (!order) return `I cannot find order ${found[0]}.`;
return `${order.item} (${order.status}) arrives ${order.arrives}.`; // step 3: reply
}
// Router: sort the message to one desk, or pass it to a person.
type Desk = "help desk" | "order desk" | "a person";
const SHAPE: Record<Desk, string> = { "help desk": "one call", "order desk": "chain", "a person": "no desk fits" };
function route(message: string): Desk {
if (/return|refund policy/i.test(message)) return "help desk";
if (/order \d{4}/i.test(message)) return "order desk";
return "a person";
}
const messages: string[] = [
"Can I return my shoes?",
"Where is order 1043?",
"My jacket smells odd and I want a new one",
];
for (const m of messages) {
const desk = route(m);
const reply = desk === "help desk" ? oneCall(m)
: desk === "order desk" ? orderChain(m)
: "Passing you to a person.";
console.log(`${desk} (${SHAPE[desk]}): ${reply}`);
}
Expected output:
help desk (one call): Returns: you can return an item within 30 days for a full refund.
order desk (chain): Desk lamp (packing) arrives Friday 31 Oct.
a person (no desk fits): Passing you to a person.
oneCall: one answer from the pasted help pages. It cannot look anything up.orderChain: three fixed steps, always in the same order. It never adds a step.route: it sorts each message to one desk. In a real app this is a model call. Here it is a plain function, so the output stays the same every run.- "a person": no desk fits the smelly jacket, so the router passes it on. That is safe, but slow.
An agent is not in this cell. It needs a loop, and The Agent Loop by Hand writes one.
In a Real App
In a real app, one call is a request to a model API. The app sends a list of messages. The help pages go into the system prompt.
This sketch is simplified. It uses a small ModelClient interface instead of one vendor's library, because field names differ between providers and SDK versions.
interface ChatMessage { role: "system" | "user" | "assistant"; content: string }
interface ModelRequest { model: string; messages: ChatMessage[]; maxTokens: number }
interface ModelReply { text: string; usage: { inputTokens: number; outputTokens: number } }
interface ModelClient { send(req: ModelRequest): Promise<ModelReply> }
const HELP_PAGES = [
"Returns: You can return an item within 30 days for a full refund.",
"Late parcels: If a parcel is late, we can send a new one for free or give a full refund.",
].join("\n");
export async function oneCall(client: ModelClient, customerMessage: string): Promise<string> {
const reply = await client.send({
model: "your-model-name",
maxTokens: 300,
messages: [
{
role: "system",
content: "You are Shop Helper. Answer only from these help pages. " +
"If they do not cover it, say so.\n\n" + HELP_PAGES,
},
{ role: "user", content: customerMessage },
],
});
return reply.text; // one model call, no tools, no loop
}
Some APIs take the system prompt as its own field instead of a message. The idea is the same. The pasted pages travel with every call, so a long help centre makes every call cost more.
Simple lesson: one call, a chain and a router are plain code you write, and only the agent needs a loop.
TL;DR
- Model call = the app sends text to the model, and the model answers.
- Tool = an action the app runs when the model asks for it.
- One call = one model call with the needed facts pasted in.
- Chain = fixed steps, always in the same order.
- Router = a model call that sorts each message to a fixed desk.
- Workflow = steps a developer wrote in advance. Chains and routers are workflows.
- Agent = the model picks its own next step until the job is done.
- The rule = pick the least freedom that passes every test chat.
Common mistakes
| Mistake | Wrong idea | Correct idea | What goes wrong |
|---|---|---|---|
| Making every helper an agent | "Agents are smarter, so they are always better." | Start with one call and climb only when tests fail. | Simple questions cost more and take longer. |
| Trusting a sure-sounding reply | "It said the address changed, so it did." | Check what changed in the shop. | The customer is told a lie and the parcel goes to the old address. |
| A chain for every kind of message | "One chain can handle all questions." | Use a router, or an agent when jobs mix. | Messages that do not fit the chain get guessed answers. |
| No test chats | "It worked on my one example." | Write a few test chats and run every shape on them. | The helper fails on the first unusual customer. |
| Fearing the person hand-off | "Passing to a person means the helper failed." | A safe hand-off beats a wrong answer. | The helper guesses instead, and the shop pays for it. |
Check Your Understanding
Exercises
What to Remember
- There are four shapes: one call, chain, router and agent.
- A workflow follows steps you wrote. An agent picks its own steps.
- More freedom means more model calls, more cost and more time.
- Use an agent only when messages mix jobs in ways you cannot plan.
- Check what the helper did in the shop, not only what it said.
- Pick the least freedom that passes every test chat.
Next: The Agent Loop by Hand, how an agent asks, acts, reads the result and repeats until the job is done.