tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Google Gemini API > ADK Agents with Knowledge Graphs

ADK Agents with Knowledge Graphs

Author: Venkata Sudhakar

A knowledge graph stores entities and their relationships - products, brands, categories, compatibility links. For ShopMax India, this means an agent can answer questions like 'what cases fit my OnePlus 12?' or 'which earphones work with the Samsung S24?' without those answers being hard-coded. The agent queries the graph as a tool, traversing relationships at runtime.

The example below models the ShopMax India catalogue as a simple in-memory graph using a dictionary of nodes and edges. In production this would be Cloud Spanner or Neo4j. The agent uses two tools - one to look up product nodes, another to traverse compatibility edges.


It gives the following output,

Answer: For the OnePlus 12 (Rs 64,999), ShopMax India has two compatible accessories:
1. OnePlus Buds Pro 2 - Rs 9,999 (wireless earphones with active noise cancellation)
2. OnePlus 12 Silicone Case - Rs 999 (official protective case)
Both are designed to work seamlessly with your OnePlus 12.

Answer: For your Samsung Galaxy S24, the best compatible earphones are the
Samsung Galaxy Buds2 at Rs 8,999. They pair automatically with your Galaxy S24
via Bluetooth and integrate with Samsung Sound settings for a seamless experience.

The agent traversed the knowledge graph in two steps - first calling lookup_product to get the product ID, then calling get_compatible_accessories to traverse the edges. This graph traversal pattern scales to hundreds of products and thousands of compatibility relationships without any hard-coding in the agent instruction.

For ShopMax India production, store the knowledge graph in Cloud Spanner using a node table and an edge table. The edge table has columns: source_product_id, target_product_id, relationship_type (compatible, replaces, bundles_with). The agent tools run parameterised Spanner queries - no escaped quotes needed. Refresh the graph nightly from the product catalogue database so new products and compatibility data are always current.


 
  


  
bl  br