|
|
ADK Sequential Agent Workflows
Author: Venkata Sudhakar
A SequentialAgent in ADK runs a fixed ordered list of sub-agents one after another, passing each output as context to the next. This is the right pattern when your workflow has clearly defined stages that must always happen in a specific order - no dynamic routing, no conditional branching, just a reliable deterministic pipeline. Think of it as an assembly line: Stage 1 validates the input, Stage 2 enriches it with data lookups, Stage 3 formats the output. Each stage is a focused specialist that does one thing well and hands off to the next. SequentialAgent takes a list of Agent objects in the sub_agents parameter. When run, it executes them in order and automatically passes the accumulated conversation context forward. Each sub-agent sees all prior messages including previous agent outputs - the conversation history is a growing shared workspace where each agent adds its contribution. This makes sequential agents ideal for document processing pipelines, multi-step approval workflows, and any staged transformation that needs a clean per-stage audit trail. The below example builds a three-stage invoice processing pipeline for an accounts payable team: a validator checks completeness, an enricher looks up vendor details and GL codes, and a formatter produces the final ERP-ready JSON record.
Running an invoice through the three-stage pipeline,
It gives the following output showing all three stages completing in sequence,
=== PIPELINE OUTPUT (Stage 3 - ERP Record) ===
{
"vendor_id": "VND-0042",
"invoice_number": "MSF-2025-0847",
"invoice_date": "2025-03-28",
"amount_before_tax": 14500,
"gst_amount": 2610,
"total_amount": 17110,
"gl_account": "5001-RAW-MATERIAL",
"payment_due_date": "2025-04-27",
"status": "APPROVED",
"hold_reason": null
}
# Stage 1 (Validator): PASS - all fields present, GST 18% correct, date within 90 days
# Stage 2 (Enricher): Called get_vendor_details("Metro Steel Fabricators")
# Added vendor_id, GL code, payment_due_date (Net 30)
# Stage 3 (Formatter): Combined all context into clean ERP JSON
# Total: 3 specialised agents, 1 runner.run() call, deterministic pipeline
Sequential pipelines shine when every invoice, every document, every request must go through the same stages in the same order. The pipeline is self-documenting: each stage name describes what it does and the conversation history shows exactly what each stage contributed. For higher volume, run multiple invoices as concurrent runner.run() calls (different session IDs) - each gets its own isolated pipeline execution. Add an error-handling stage at the end to catch HOLD status records and route them to a human review queue via a tool call, making the pipeline fully end-to-end automated for approved invoices and human-assisted for exceptions.
|
|