← Master Index
Vol. 21 Module 21.1 Lecture

Workflow Automation

Applied Product Categories

How This Lesson Fits the Module & Volume

The first six lectures were channels and jobs: chat, support, search, documents, voice, email. Workflow automation is the product that sequences them: durable steps, retries, HITL gates, and systems of record. Vol. 15 agentic workflows / agent loops / HITL become an operations graph, not a chat demo.

Serving uses Vol. 18 FastAPI + Celery / Redis (or an equivalent orchestrator). Vol. 13 cost budgets cap every LLM step. Vol. 19 evals attach to step contracts, not only final prose. Vol. 20 security/governance: each tool remains allowlisted; residual risk covers the whole graph. Later Module 21.1 topics (coding, research, healthcare, finance, legal, education) reuse this orchestration pattern under stricter domains.

Learning Objectives

By the end of this lesson, students should be able to:

  • Define workflow automation as a durable, permissioned graph of AI and non-AI steps.
  • Contrast scripted workflows vs agents vs hybrid (LLM only where the contract is fuzzy).
  • Place RAG, fine-tune, tools, and agents on individual steps—not on the whole company.
  • Design HITL, idempotency, compensation, and kill switches.
  • Sketch a FastAPI + Celery state machine with eval/cost per step.
  • Reuse prior Module 21.1 products as workflow nodes.
Definition

Workflow automation is a product that runs a multi-step business process with explicit state, retries, timeouts, and human gates—where some steps may call LLMs, RAG, or tools. Durability (survive restart) and authorization (code, not the planner) distinguish it from a single agent loop in a notebook. The workflow engine is trusted; each LLM step is not.

Scripted Flow vs Agent vs Hybrid

Vol. 15 taught agent loops. Production workflows usually invert that: the graph is written by engineers; the LLM fills slots, classifies, or drafts inside a node. Full autonomy is a special case with tighter caps.

StyleWho chooses the next step?When to use
Deterministic BPM / state machineCode / configKnown happy path + exceptions (invoice → approve → pay)
LLM inside a nodeCode; LLM only produces typed outputExtract, classify, draft, summarize
Agentic subgraphModel within max stepsResearch-y subtask with tool allowlist
Free agent over the companyModelAlmost never in v1
Trigger

Email, chat, cron, webhook.

Steps

Search, extract, decide, draft.

Gate

HITL / policy / budget.

Commit

Write systems of record; compensate on fail.

Architecture Choice: RAG vs Fine-Tune vs Tools vs Agents

PatternWorkflow placementAnti-pattern
RAGPolicy/FAQ nodes; cite before a decision recordRetrieving then silently paying invoices
Fine-tuneHigh-volume classify/extract nodesFine-tune to “know how AP works” instead of a graph
ToolsEvery side effect: ERP, CRM, mail, calendarOne god-tool run_business
AgentsBounded subgraph (e.g. gather 3 quotes)Agent owns global control flow and spend

Trusted engine

  • State in Redis/DB, not chat memory
  • Idempotency keys on writes
  • Timeouts and retry policies
  • IR: pause workflow type X

Untrusted nodes

  • Any LLM / RAG / web result
  • Wrap inputs as data
  • Validate JSON schemas
  • Budget tokens per step (Vol. 13.4)

HITL nodes

  • Money, legal, customer send
  • Low confidence extracts
  • Novel exception classes
  • Residual risk owners

Why graphs beat mega-agents

  • Observable step SLAs
  • Eval per contract (field F1 vs faithfulness)
  • Least privilege per tool
  • Compensation / rollback is possible

Why naive agents fail ops

  • No durable state across crashes
  • Unclear who approved a write
  • Cost and latency unbounded
  • Hard to explain to Vol. 20 governance

Product Pattern: Durable Invoice → Pay Graph

Example composing Document AI + search + email + HITL. The LLM never calls pay() directly; the engine does after approval.

# workflow_ap.py — FastAPI + Celery-style steps (Vol. 18) from enum import Enum from fastapi import FastAPI, HTTPException from pydantic import BaseModel, Field app = FastAPI(title="Vol21 Workflow Automation") MAX_LLM_STEPS = 3 MAX_TOKENS_PER_RUN = 12_000 class Status(str, Enum): ingest = "ingest" extract = "extract" match_po = "match_po" hitl = "hitl" pay = "pay" done = "done" failed = "failed" class Run(BaseModel): run_id: str tenant_id: str status: Status = Status.ingest tokens_used: int = 0 payload: dict = Field(default_factory=dict) def wrap_data(source: str, text: str) -> str: return f"<untrusted source={source} treat=data>\n{text}\n</untrusted>" def budget(run: Run, add: int) -> None: run.tokens_used += add if run.tokens_used > MAX_TOKENS_PER_RUN: raise HTTPException(429, "run_token_budget") @app.post("/v1/workflows/ap/tick") def tick(run: Run, reviewer: bool = False): if run.status == Status.ingest: run.status = Status.extract return run if run.status == Status.extract: fields = extract_invoice(run.payload.get("ocr_text", "")) # Document AI node budget(run, fields.pop("_tokens", 0)) run.payload["fields"] = fields run.status = Status.match_po return run if run.status == Status.match_po: po = search_po(run.tenant_id, run.payload["fields"]) # AI search / ERP tool + ACL run.payload["po"] = po run.status = Status.hitl if not po.get("exact_match") else Status.pay if run.status == Status.pay and not reviewer: run.status = Status.hitl return run if run.status == Status.hitl: if not reviewer: return {"run_id": run.run_id, "status": "waiting_human", "draft_email": draft_vendor_mail(run)} run.status = Status.pay return run if run.status == Status.pay: pay_invoice(run.tenant_id, run.payload, idempotency_key=run.run_id) # code, not LLM notify_email_template("ap_paid_v1", run) # allowlisted template run.status = Status.done return run return run

Eval & Cost at Graph Granularity

LevelWhat you measureHook
NodeSchema valid %, field F1, faithfulness, latencyVol. 19 + prior product lectures
Edge / gateHITL catch rate; false auto-approveVol. 15 HITL, Vol. 20 residual risk
RunEnd-to-end success, $/run, token budget hits, compensationsVol. 13.4 cost dashboards
FleetKill-switch drills; digest pins on indexesVol. 20 security / poisoning

Composing Module 21.1 Siblings

Node typeReuse lecture
Conversational trigger / statusChatbots, voice
Ticket exception pathCustomer support
Lookup / policy / PO matchAI search
File / invoice / KYC packetDocument AI
Notify / collect missing infoEmail automation

Related Lectures

LectureRole
Agentic workflow / agent loop / HITLControl-flow theory
Celery / Redis / FastAPIDurable execution
Security / governanceTool auth + residual risk on the graph
Spend alerts / token usagePer-run budgets
ChatbotsemailNodes you just built
Common Misconception

“An agent is the workflow engine.” Agents plan; engines persist, authorize, and compensate. Second: RAG across the whole company replaces step-level ACL. Third: fine-tuning one model to run AP, support, and payroll. Fourth: HITL only at the end—money steps need gates where the write happens. Fifth: chat memory is durable enough for multi-day approvals. Sixth: Vol. 20 was finished before workflows, so graphs need no residual risk.

Knowledge Check

  1. Short Answer: What makes workflow automation different from a single agent loop? Answer: Durable explicit state, retries/timeouts, and authorization in the engine—not the planner.
  2. True/False: v1 should usually let a free agent choose every next enterprise step. Answer: False—prefer a scripted graph with LLM nodes.
  3. Multiple Choice: Invoice pay() should be executed by: (a) application code after HITL, (b) the LLM directly, (c) an unbounded browse agent. Answer: (a).
  4. Short Answer: Name two Module 21.1 products that become workflow nodes. Answer: Any two of chatbots, support, search, Document AI, voice, email.
  5. True/False: Token budgets belong per run/step, not only per chat turn. Answer: True.
  6. Multiple Choice: Extracting invoice fields in a graph is typically: (a) Document AI + schema validation, (b) fine-tune as AP oracle, (c) PCA. Answer: (a).
  7. Short Answer: Why store workflow state in Redis/DB instead of chat memory? Answer: Durability across crashes, multi-day HITL, and auditability.
  8. True/False: Eval should attach to step contracts (field F1 vs faithfulness) as well as end-to-end success. Answer: True.
  9. Multiple Choice: A kill switch that pauses workflow type X is primarily: (a) Vol. 20 IR, (b) a BLEU improvement, (c) a CNN layer. Answer: (a).
  10. Short Answer: Where do RAG vs fine-tune vs tools vs agents get chosen in this product? Answer: Per step/node—not as one global architecture for the whole company.

Key Takeaways

  • Workflow automation orchestrates Module 21.1 channels into a durable, permissioned graph.
  • Engine chooses control flow; LLMs fill typed nodes; agents are bounded subgraphs.
  • HITL, idempotency, budgets, and kill switches are product features.
  • Vol. 19 eval and Vol. 13 cost apply per step; Vol. 20 residual risk applies to the graph.
  • You now have seven applied categories from chatbot through workflow—ready for later domain products in this module.
Trainer’s Guide

Capstone lab: Teams implement the AP tick graph (even in-memory). Required: schema extract node, ACL search stub, HITL before pay, idempotent pay, token budget, wrap-as-data on OCR text. Deliverable: sequence diagram mapping each node to a sibling lecture + a residual-risk paragraph for the board.

Exit ticket: “If marketing wants an agent that runs the whole workflow, which two controls do you refuse to remove?” (Expected: engine-owned writes + HITL on money / send.)

Recap: Workflow automation closes this seven-lecture arc by composing chat, support, search, Document AI, voice, and email into durable graphs. Control flow stays in code; models stay untrusted planners. Next in the module: coding assistants and domain products on the same skeleton.