When to Use an Agent vs a Deterministic Workflow
One of the most common mistakes in AI engineering is reaching for an autonomous agent when a simple, deterministic workflow would do the job better, faster, and cheaper. Let's build a framework for deciding.
Key Definitions
| Concept | Definition | Analogy |
| Workflow | A fixed, deterministic pipeline where each step is pre-defined | Assembly line — same steps every time |
| Agent | An autonomous system that decides its own steps at runtime | Freelancer — interprets the goal, chooses methods |
The Decision Matrix
| Factor | Use a Workflow | Use an Agent |
| Task Predictability | Steps are always the same | Steps depend on intermediate results |
| Error Tolerance | Must be 100% reliable | Can tolerate occasional mistakes |
| Cost Sensitivity | Minimize API costs | Value > cost of extra tokens |
| Task Complexity | 3-5 fixed steps | Unknown number of steps, branching paths |
| Input Variety | Inputs are structured and predictable | Inputs are diverse, ambiguous, or messy |
Real-World Examples
| Task | Best Approach | Reasoning |
| Classify support tickets into 5 categories | Workflow | Fixed input format, fixed output format, no tool use needed |
| Research a company and write an investment memo | Agent | Requires web search, reading multiple sources, synthesizing — unpredictable steps |
| Extract fields from invoices into JSON | Workflow | Structured extraction with a fixed schema — no autonomy needed |
| Debug a failing CI/CD pipeline | Agent | Requires reading logs, forming hypotheses, trying fixes — highly dynamic |
| Translate documents to 3 languages | Workflow | Fixed steps: detect language → translate → validate |
| Plan and execute a marketing campaign | Agent | Requires research, creative decisions, iterative refinement |
🚧 Golden Rule: Start with the simplest solution that works. Use a workflow first. Only upgrade to an agent when the workflow can't handle the variability of the task.
Hybrid Patterns
In production, you often combine both:
- Workflow with an Agent Step: A pipeline where Step 3 is an agent that handles a complex, variable sub-task.
- Agent-Orchestrated Workflows: An agent that decides which workflow to run, then hands off to deterministic code.
- Guardrailed Agent: An agent that operates freely within strict boundaries (allowed tools, iteration caps, approval gates).
// Hybrid: Agent decides, Workflow executes
const decision = await agent.decide(userRequest);
switch (decision.workflow) {
case "invoice_extract": return runInvoicePipeline(input);
case "research_report": return runResearchAgent(input);
case "translation": return runTranslationPipeline(input);
}