
Cost-Effective Gen AI Workflows in Google Dataflow

Google Dataflow and the Agent Development Kit (ADK) can be combined to make generative-AI workflows affordable in high-throughput streaming. The article describes a pre-filter plus agentic action pattern: a lightweight, CPU-only machine learning model upstream filters incoming events, and only the complex or negative cases are passed to a heavyweight model and agent. This avoids routing every event to an LLM, which would otherwise create high API cost, latency, and quota exhaustion.
The motivating example is customer support triage. When a customer sends an angry message about a damaged order, the pipeline should look up the order, decide on a remediation such as a replacement or refund, email the customer, and log the resolution. But sending every raw event to a multi-step agent with database and email tools is impractical. The article positions this as a universal blueprint for high-volume streams where the majority of events are routine; IT operations log triage, financial fraud detection, and industrial IoT monitoring are listed as other possible applications.
The concrete pipeline reads raw customer messages from Google Pub/Sub, classifies sentiment on Dataflow worker CPUs using the Hugging Face model distilbert-base-uncased-finetuned-sst-2-english via Apache Beam‘s RunInference transform, and drops positive and neutral messages in a DoFn gate. For negative messages, the pipeline invokes an ADK agent backed by gemini-3.5-flash. The agent uses three tools: lookup_user to query BigQuery for the customer’s email, lookup_orders for orders and inventory, and send_email via the Gmail API. The agent is exposed to Beam through ADKAgentModelHandler, so the static Beam DAG can contain a dynamic node: the agent decides which tools to call and in what sequence at runtime, instead of having thousands of hardcoded conditional branches.
The reported benefits are lower cost, because Gemini tokens are paid only for the small fraction of negative messages which are typically under 5%; high throughput, because CPU inference is fast and horizontally scalable while the slower agent is called sparingly; and clean native Apache Beam integration, because RunInference handles parallel threads, batching, and agent management. The article’s key takeaway is that streaming is fast and high-volume while heavyweight generative-AI reasoning is slow and costly, so placing a pre-filter before an agent balances both. The full code is available in the next-2026-demo GitHub repository.


