|
|
ADK Event-Driven Agents with Pub/Sub
Author: Venkata Sudhakar
Event-driven architecture decouples the systems that produce events from the systems that react to them. Google Cloud Pub/Sub is a fully managed messaging service that delivers events reliably at scale. By subscribing an ADK agent to a Pub/Sub topic, you can trigger agent logic automatically whenever a business event occurs - without polling, cron jobs, or manual triggers.
ShopMax India publishes events to Pub/Sub topics when orders are placed, stock falls below reorder level, and payment failures occur. An ADK agent subscribes to these topics and takes appropriate action - drafting customer notifications, raising purchase orders, or escalating payment issues - all without any human intervention in the trigger loop.
The below example shows how to subscribe an ADK agent to a ShopMax India Pub/Sub topic and process incoming order events automatically.
It gives the following output,
Listening on projects/shopmax-india/subscriptions/order-events-sub ...
[PubSub] Received: NEW_ORDER | Order: ORD-20260406-9921
[Agent Action] Order ORD-20260406-9921 confirmed.
Items: Samsung 55 QLED TV (stock: 41 - OK), boAt Airdopes (stock: 12 - LOW)
Action: Flag boAt Airdopes for reorder. Order processing can proceed.
[PubSub] Received: PAYMENT_FAILED | Order: ORD-20260406-9918
[Agent Action] Draft follow-up for customer CUST-44201:
"Your payment for order ORD-20260406-9918 (Rs 74,999) could not be processed.
Please retry via UPI, net banking, or call 1800-SHOPMAX for assistance."
The below example shows a Cloud Run service that exposes a Pub/Sub push endpoint, so Pub/Sub delivers messages via HTTP POST rather than the pull model - better suited for serverless deployments.
It gives the following output,
INFO: Serving on http://0.0.0.0:8080
[Push] ORDER_CANCELLED | ORD-20260406-9905
[Agent] Order ORD-20260406-9905 cancelled by customer (reason: found cheaper elsewhere).
Win-back action: Send 7% loyalty coupon valid 14 days.
Coupon code: WINBACK-9905 | Category: All Electronics
Trigger: automated email within 2 hours of cancellation.
[Push] NEW_ORDER | ORD-20260406-9930
[Agent] Order ORD-20260406-9930 confirmed. All 3 items in stock. No action required.
Pub/Sub-driven ADK agents give ShopMax India a fully automated event response layer. Orders, payments, and inventory changes each trigger the right agent action within seconds of the event occurring, without any manual monitoring. The pull subscriber suits long-running services while the push endpoint suits Cloud Run serverless deployments that scale to zero when idle.
|
|