Building a Graph PoC using Agents: a case study (part 2 - the data model)
Step by step output of using agents to build a graph proof of concept. Part 2 creates the data model.
GenAI isn't just good for writing code. It is also very useful for building data models. This is part 2 of a series covering building a graph proof of concept using agentic AI. It is recommended to start at part 1 .
In part 1, we created our environment and ran our first agent to take our theme of
Create trip plans for walking tours of cities and generated a full use case with questions we want the graph to answer.<use_case>
Create trip plans for walking tours of cities
</use_case>
<response>
Walking tour planning involves complex spatial and categorical relationships
between points of interest (POIs), streets, neighborhoods, and visitor
preferences. A graph database excels at modeling cities as interconnected
networks where nodes represent locations (museums, restaurants, parks,
historical sites) and edges represent walking paths with properties like
distance, elevation, accessibility, and estimated walking time. The challenge
lies in finding optimal routes that maximize visitor satisfaction while
respecting constraints like time, physical difficulty, and opening hours.
Traditional databases struggle with the multi-criteria pathfinding needed to
create personalized itineraries that flow naturally through city streets while
considering factors like "must-see" attractions, cuisine preferences, and
avoiding backtracking. Graph databases can efficiently calculate weighted paths,
suggest alternative routes when attractions are closed, and discover hidden gems
along the way based on similarity to visited locations.
Questions:
- What is the optimal walking route that visits 5 historical landmarks within 3
hours while minimizing elevation changes and including a lunch stop?
- Which lesser-known attractions are located along the path between two popular
tourist destinations and match a visitor's interest in art galleries?
- How can a multi-day itinerary be optimized to minimize repeated walking
through the same neighborhoods while covering all requested POI categories?
</response>Next we run the prompt @generate-model in Kiro CLI , and it will run a workflow launching the Graph Modeler Agent . This agent will pass the LLM a prompt and the use case document, and receive a vendor neutral JSON formatted graph schema. It is again a simple single round trip call to the LLM which produces the following schema:
{
"nodes": [
"POI",
"Street",
"Neighborhood",
"Visitor",
"TripPlan",
"Category",
"DayItinerary"
],
"edges": [
{
"label": "WALKING_PATH",
"from_label": "POI",
"to_label": "POI"
},
{
"label": "LOCATED_ON",
"from_label": "POI",
"to_label": "Street"
},
{
"label": "WITHIN",
"from_label": "POI",
"to_label": "Neighborhood"
},
{
"label": "WITHIN",
"from_label": "Street",
"to_label": "Neighborhood"
},
{
"label": "BELONGS_TO",
"from_label": "POI",
"to_label": "Category"
},
{
"label": "INTERESTED_IN",
"from_label": "Visitor",
"to_label": "Category"
},
{
"label": "CREATED_BY",
"from_label": "TripPlan",
"to_label": "Visitor"
},
{
"label": "INCLUDES_DAY",
"from_label": "TripPlan",
"to_label": "DayItinerary"
},
{
"label": "VISITS",
"from_label": "DayItinerary",
"to_label": "POI"
},
{
"label": "SIMILAR_TO",
"from_label": "POI",
"to_label": "POI"
}
],
"properties": {
"POI": [
"name",
"poi_type",
"latitude",
"longitude",
"elevation",
"popularity_score",
"opening_time",
"closing_time",
"is_must_see",
"average_visit_duration_minutes",
"accessibility_rating",
"description"
],
"Street": [
"name",
"surface_type",
"has_sidewalk",
"avg_grade_percent"
],
"Neighborhood": [
"name",
"description",
"character_type"
],
"Visitor": [
"visitor_id",
"name",
"fitness_level",
"max_daily_walking_minutes",
"accessibility_requirements"
],
"TripPlan": [
"plan_id",
"name",
"start_date",
"end_date",
"total_duration_days",
"created_datetime"
],
"Category": [
"category_name",
"description"
],
"DayItinerary": [
"day_number",
"date",
"total_walking_minutes",
"total_distance_meters"
],
"WALKING_PATH": [
"distance_meters",
"estimated_walking_minutes",
"elevation_change_meters",
"difficulty_level",
"accessibility_score",
"has_shade",
"scenic_rating"
],
"LOCATED_ON": [
"address_number"
],
"WITHIN": [],
"BELONGS_TO": [],
"INTERESTED_IN": [
"preference_level"
],
"CREATED_BY": [],
"INCLUDES_DAY": [
"sequence_number"
],
"VISITS": [
"visit_order",
"planned_arrival_time",
"planned_departure_time"
],
"SIMILAR_TO": [
"similarity_score"
]
}
}Notice there are 3 sections. First is a list of node label types. Node labels are similar to object oriented classes or tables in other models. Second is a list of edges or relationships between the nodes, each object showing the edge label (or relationship type) and the types of nodes it connects. Finally we have a list of properties for each node or edge label type. There are some simplicities in this schema that can introduce ambiguity, but that simplicity also allows the LLMs to have a strong understanding of it within its context window. As before, if you know better than the LLM, you can modify this schema document to better fit your workload.
Now that our model is ready, we will start getting into the more complex steps starting with @generate-data in part 3 .
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article