tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Google Gemini API > ADK with Pub/Sub for Event-Driven Agents

ADK with Pub/Sub for Event-Driven Agents

Author: Venkata Sudhakar

Google Cloud Pub/Sub enables asynchronous messaging between services. ADK agents can subscribe to Pub/Sub topics and trigger actions when messages arrive - without polling. ShopMax India uses this pattern to trigger inventory reorder agents when stock levels drop below threshold.

The integration works by deploying an ADK agent as a Cloud Run service that exposes an HTTP endpoint. A Pub/Sub push subscription delivers messages to that endpoint. The agent processes the payload and responds.

The below example shows how ShopMax India builds a Pub/Sub triggered reorder agent that processes stock alert messages.


The Cloud Run HTTP handler that receives Pub/Sub push messages,


It gives the following output when a Pub/Sub message arrives,

Pub/Sub message received for: LAPTOP-DELL-XPS-15
Current stock: 3 units
Agent response: Reorder placed - 100 units of LAPTOP-DELL-XPS-15
Supplier: ShopMax Wholesale Delhi
Expected delivery: 3-5 business days

To set up the Pub/Sub subscription, create a push subscription pointing to your Cloud Run endpoint. Messages published to the stock-alerts topic are automatically forwarded to your agent for processing without any polling loop.


 
  


  
bl  br