|
|
ADK with Cloud Pub/Sub
Author: Venkata Sudhakar
Cloud Pub/Sub enables event-driven ADK agent workflows - an agent tool publishes or subscribes to topics, triggering actions in response to real-time business events. ShopMax India uses Pub/Sub to connect its ADK agents to order, inventory, and delivery event streams, enabling agents to react to system events without polling. The integration works in two directions: an ADK tool can publish messages to a Pub/Sub topic (outbound), or a Cloud Run service can subscribe to a topic and invoke an ADK agent for each incoming event (inbound). Both patterns are stateless and scale automatically. The below example shows an ADK tool that publishes order events to a Pub/Sub topic when an agent completes a booking.
It gives the following output,
Publisher connected to: projects/shopmax-india/topics/order-events
Agent initialized: shopmax_order_agent
The below example shows the inbound pattern - a Pub/Sub push subscription triggers an ADK agent via Cloud Run when a delivery status event arrives.
It gives the following output,
* Running on http://0.0.0.0:8080
Delivery event received: ORD-5521 -> OUT_FOR_DELIVERY
Delivery event received: ORD-5521 -> DELIVERED
ShopMax India connects its ADK agents to six Pub/Sub topics: order-events, delivery-updates, inventory-alerts, refund-requests, review-submitted, and payment-confirmed. Each topic fans out to the relevant agent handler. This decoupled architecture means new agent capabilities can be added by subscribing to existing topics - no changes to upstream order or payment systems required.
|
|