Business Process Automation
Agents orchestrating APIs, databases, documents and humans replace glue work — but side effects demand idempotency, audit trails, and often a workflow engine instead of an agent.
What automation agents orchestrate
The bulk of enterprise agentic work is not chat. It is background processing: an invoice PDF arrives, fields are extracted, the vendor is matched in the ERP, a purchase order is checked, an approval is requested if amounts differ, the payment is scheduled, and the outcome is logged. The model contributes judgment at a few steps (extraction, matching ambiguity, drafting the approval note); everything else is integration code.
The systems involved are the usual suspects, and each brings its own failure modes: REST APIs rate-limit and time out, databases need transactions, documents parse badly, SaaS tools have webhooks that fire twice, internal services have undocumented auth, and humans take three days to click approve.
- APIs and SaaS: CRM, ticketing, payments, email. Retries with exponential backoff and jitter; idempotency keys on writes.
- Databases: transactional reads and writes; the agent never gets raw SQL, it gets narrow tools like
find_vendor(name). - Documents: PDFs, scans, spreadsheets, emails. Extraction is a structured-output problem — see Structured Outputs.
- Internal services: gRPC/REST behind service auth; wrap them in tools with least privilege — see Tool Permissions and Least Privilege.
- Humans: approvals and exceptions handled asynchronously, which means the process must pause and resume — see Approval Gates and Risk Classes.
Idempotency: the non-negotiable
Automation runs fail halfway. The network drops after the payment API accepted the request but before the response arrived; the worker restarts; the model, seeing no result, calls schedule_payment again. Without idempotency the vendor is paid twice. With it, the second call carries the same key and the API returns the original result.
Idempotency has to be designed in at the tool layer, not hoped for at the model layer. The runtime derives a key deterministically from the run id and step (or from business identity like invoice_id), passes it with every write, and stores the result so replays are served from the store. The model never sees or invents keys.
- Key =
hash(run_id, step_index, tool_name, canonical_args)or a natural business key such asinvoice:{id}:payment. - Make every write tool either naturally idempotent (
PUTwith full state) or key-protected; reject tools that are neither. - On resume, replay from the last persisted step; already-completed writes return their stored results.
- Detail and code in Idempotency and Tool Errors, Retries and Timeouts.
Audit trails and approvals
When an automated process moves money, changes a customer record or sends a contract, someone will eventually ask "why did this happen?". The answer must be reconstructible from stored data: the input document, the extracted fields, the model's reasoning for the vendor match, the tool calls with arguments and results, who approved what and when, and the final action. This is a trace with retention and access control, not a debug log — see Tracing Agents.
Approvals turn a run into a long-lived process. The state must be persisted so the run can wait hours or days, survive deploys, and resume exactly where it paused. Approvals should carry enough context for a two-minute decision: what will happen, why the system is unsure, and what the alternative is. Route by risk: auto-approve under a threshold, one approver up to another, two above.
- Store the exact prompt and model version per step; "the model changed" is a real root cause six months later.
- Audit records are append-only and separated from operational tables.
- Approval timeouts need a defined default — usually "do nothing and escalate", never "assume yes".
When a workflow engine beats an agent
Most business processes are known in advance. The invoice flow above has five steps in a fixed order with one decision point. That is a graph, and graphs are what workflow engines (durable execution systems, state machines, BPMN tools) are built for: they persist state per step, retry with policies, handle timers and human tasks, and give you a visual of where every run is. The model is called inside a step; it does not own the control flow.
Reserve the agent for the step whose path is unknowable: reconciling a vendor whose name, address and tax id all differ slightly across three systems may take one lookup or seven. Put that step in a bounded agent loop inside the workflow. You get durability and auditability from the engine and adaptability only where it pays.
- Use a workflow engine when: steps are enumerable, ordering is fixed, runs are long-lived, compliance requires a visible process.
- Use an agent when: the number and choice of lookups depends on intermediate results and cannot be scripted.
- Use both when: a deterministic graph has one or two genuinely fuzzy nodes. See Workflow State Graph.
- Signals you chose wrong: an "agent" whose traces show the identical tool sequence every run, or a workflow with a 200-branch
switchtrying to anticipate every case.
Key points
- Automation agents orchestrate APIs, databases, documents, SaaS, internal services and humans; the model adds judgment at a few steps.
- Every write needs an idempotency key derived by the runtime, because runs fail halfway and get retried.
- An audit trail must reconstruct inputs, model reasoning, tool calls, approvals and outcomes per run.
- Approvals make runs long-lived; state must be persisted and resumable across days and deploys.
- If the steps are known in advance, a workflow engine beats an agent; embed a bounded agent only in the fuzzy nodes.
When to use — and when not to
- Multi-system processes with unstructured inputs (documents, emails) that currently need a human to read and re-key.
- Exception handling in an existing workflow where the rules cannot be fully enumerated.
- High-volume, low-risk decisions where a wrong call is cheap to reverse and a human reviews samples.
- The process is fully specified — use a workflow engine or plain code; add no model at all.
- Writes are irreversible and cannot be made idempotent or gated.
- No audit or replay infrastructure exists yet; build that first.
- Volume is tiny and a human doing it takes minutes a day.
Failure modes
- Duplicate payments or emails after a retry because writes had no idempotency key.
- A run stuck waiting for approval is lost on deploy because state lived in process memory.
- Extraction errors flow silently into the ERP because no validation step checked totals against line items.
- The agent re-plans a fixed process differently on each run, making outcomes unreproducible.
- Audit log lacks the model version and prompt, so a regression cannot be dated.
- A webhook fires twice and starts two runs for one document.
Tradeoffs
Assumes workflow engine plus bounded agent steps; a pure free-running agent over the same process would be 3/3/4/2/2.