Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions uc-0a/agents.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# agents.md — UC-0A Complaint Classifier
# INSTRUCTIONS: Generate a draft using your RICE prompt, then manually refine this file.
# Delete these comments before committing.

role: >
[FILL IN: Who is this agent? What is its operational boundary?]
You are an expert Citizen Complaint Triage Agent for the City Municipal Corporation. Your role is to accurately classify incoming citizen complaints to ensure they are routed to the correct department with the appropriate priority level.

intent: >
[FILL IN: What does a correct output look like — make it verifiable]
For every complaint, produce a structured output containing:
- category: One of the 10 allowed taxonomic categories.
- priority: Based on severity cues in the text.
- reason: A single sentence justifying the classification by citing specific keywords from the user's description.
- flag: Marked as 'NEEDS_REVIEW' if the description is genuinely ambiguous.

context: >
[FILL IN: What information is the agent allowed to use? State exclusions explicitly.]
You are operating strictly on the text provided in the complaint description. You must ignore any external assumptions or geographical context not present in the input.

enforcement:
- "[FILL IN: Specific testable rule 1 — e.g. Category must be exactly one of: Pothole, Flooding, ...]"
- "[FILL IN: Specific testable rule 2 — e.g. Priority must be Urgent if description contains: injury, child, school, ...]"
- "[FILL IN: Specific testable rule 3 — e.g. Every output row must include a reason field citing specific words from the description]"
- "[FILL IN: Refusal condition — e.g. If category cannot be determined from description alone, output category: Other and flag: NEEDS_REVIEW]"
- "category must be exactly one of: Pothole, Flooding, Streetlight, Waste, Noise, Road Damage, Heritage Damage, Heat Hazard, Drain Blockage, Other. No variations or hallucinations allowed."
- "priority must be 'Urgent' if the description contains any of the following severity keywords: injury, child, school, hospital, ambulance, fire, hazard, fell, collapse. Otherwise, assign 'Standard' or 'Low'."
- "Every output must include a 'reason' field consisting of exactly one sentence that cites specific anchor words from the original description."
- "If a complaint is genuinely ambiguous (could fit two categories equally well), assign the most likely category but set the 'flag' field to 'NEEDS_REVIEW'."
115 changes: 106 additions & 9 deletions uc-0a/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,123 @@
"""
import argparse
import csv
import os
import re

# Severity keywords from README/agents.md
SEVERITY_KEYWORDS = [
'injury', 'child', 'school', 'hospital', 'ambulance', 'fire', 'hazard', 'fell', 'collapse'
]

# Allowed categories from README/agents.md
ALLOWED_CATEGORIES = [
'Pothole', 'Flooding', 'Streetlight', 'Waste', 'Noise', 'Road Damage',
'Heritage Damage', 'Heat Hazard', 'Drain Blockage', 'Other'
]

def classify_complaint(row: dict) -> dict:
"""
Classify a single complaint row.
Classify a single complaint row using rule-based logic to simulate the agent's behavior.
Returns: dict with keys: complaint_id, category, priority, reason, flag

TODO: Build this using your AI tool guided by your agents.md and skills.md.
Your RICE enforcement rules must be reflected in this function's behaviour.
"""
raise NotImplementedError("Build this using your AI tool + RICE prompt")
description = row.get('description', '').strip()
desc_lower = description.lower()

# 1. Determine Category (Taxonomy Match)
category = "Other"
reason_word = ""

category_map = {
'Pothole': ['pothole', 'crater', 'hole in road'],
'Flooding': ['flood', 'water logging', 'waterlogged', 'submerged', 'inundation'],
'Streetlight': ['streetlight', 'street light', 'lamp', 'dark', 'light out', 'flickering'],
'Waste': ['garbage', 'trash', 'waste', 'litter', 'dump', 'smell', 'bins', 'dead animal'],
'Noise': ['noise', 'loud', 'music', 'sound', 'volume', 'midnight'],
'Road Damage': ['road surface', 'cracked', 'sinking', 'footpath', 'tiles', 'uneven'],
'Heritage Damage': ['heritage', 'monument', 'historical', 'old city'],
'Heat Hazard': ['heat', 'cooling', 'dehydration', 'sunstroke'],
'Drain Blockage': ['drain', 'sewage', 'overflow', 'blocked', 'gutter', 'manhole']
}

# Simple keyword search for category
found_categories = []
for cat, keywords in category_map.items():
for kw in keywords:
if kw in desc_lower:
found_categories.append((cat, kw))
break

if found_categories:
# If multiple, take the first one found (simplification)
category, reason_word = found_categories[0]

# 2. Determine Priority (Severity Blindness Prevention)
priority = "Standard"
severity_trigger = ""
for kw in SEVERITY_KEYWORDS:
if kw in desc_lower:
priority = "Urgent"
severity_trigger = kw
break

# 3. Handle Ambiguity (NEEDS_REVIEW flag)
flag = ""
if len(found_categories) > 1 or not found_categories:
flag = "NEEDS_REVIEW"
if not found_categories:
category = "Other"

# 4. Generate Reason (Citation Enforcement)
if severity_trigger:
reason = f"Classified as {category} with Urgent priority due to the mention of '{severity_trigger}'."
elif reason_word:
reason = f"Identified as {category} based on the description of '{reason_word}'."
else:
reason = "Classified as Other due to lack of specific category keywords in the description."

return {
'complaint_id': row.get('complaint_id', 'Unknown'),
'category': category,
'priority': priority,
'reason': reason,
'flag': flag
}


def batch_classify(input_path: str, output_path: str):
"""
Read input CSV, classify each row, write results CSV.

TODO: Build this using your AI tool.
Must: flag nulls, not crash on bad rows, produce output even if some rows fail.
"""
raise NotImplementedError("Build this using your AI tool + RICE prompt")
if not os.path.exists(input_path):
print(f"Error: Input file {input_path} not found.")
return

results = []
fieldnames = []

try:
with open(input_path, mode='r', encoding='utf-8') as infile:
reader = csv.DictReader(infile)
fieldnames = reader.fieldnames + ['category', 'priority', 'reason', 'flag']

for row in reader:
try:
classification = classify_complaint(row)
# Merge classification results into the row
row.update(classification)
results.append(row)
except Exception as e:
print(f"Error processing row {row.get('complaint_id')}: {e}")
# Ensure we don't crash the whole batch
continue

with open(output_path, mode='w', encoding='utf-8', newline='') as outfile:
writer = csv.DictWriter(outfile, fieldnames=fieldnames)
writer.writeheader()
writer.writerows(results)

except Exception as e:
print(f"Critical error during batch processing: {e}")


if __name__ == "__main__":
Expand Down
16 changes: 16 additions & 0 deletions uc-0a/results_ahmedabad.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
complaint_id,date_raised,city,ward,location,description,reported_by,days_open,category,priority,reason,flag
AM-202401,2024-04-24,Ahmedabad,Ward 13 – Sabarmati,Kankaria Lake promenade,Tarmac surface melting at 44°C. Footwear sticking. Park users unsafe.,Email,1,Other,Standard,Classified as Other due to lack of specific category keywords in the description.,NEEDS_REVIEW
AM-202402,2024-04-23,Ahmedabad,Ward 12 – Maninagar,"Naroda Industrial Area, main gate",Metal bus shelter reaching dangerous temperatures. Commuters refusing to use.,Citizen Portal,4,Other,Standard,Classified as Other due to lack of specific category keywords in the description.,NEEDS_REVIEW
AM-202405,2024-05-08,Ahmedabad,Ward 11 – Vastrapur,"Sabarmati Riverfront, North section",Dead trees with split branches. Fall risk to walkers. 3 trees affected.,WhatsApp Helpline,19,Other,Standard,Classified as Other due to lack of specific category keywords in the description.,NEEDS_REVIEW
AM-202406,2024-04-21,Ahmedabad,Ward 15 – Chandkheda,"Chandkheda, Sector 22 park",Irrigation system broken. Grass dying in heatwave conditions.,Phone Helpline,18,Heat Hazard,Standard,Identified as Heat Hazard based on the description of 'heat'.,
AM-202407,2024-04-25,Ahmedabad,Ward 15 – Chandkheda,"Thaltej, residential park",Broken bench and upturned paving. Child injured last week.,Email,20,Other,Urgent,Classified as Other with Urgent priority due to the mention of 'child'.,NEEDS_REVIEW
AM-202410,2024-05-02,Ahmedabad,Ward 12 – Maninagar,SG Highway near Prahladnagar,Pothole on main highway causing morning rush lane closure.,Ward Office Walk-in,4,Pothole,Standard,Identified as Pothole based on the description of 'pothole'.,
AM-202414,2024-04-20,Ahmedabad,Ward 14 – Odhav,"Jodhpur Village, off SG Highway",Residential colony unlit after 9pm. Wiring theft reported.,Citizen Portal,10,Other,Standard,Classified as Other due to lack of specific category keywords in the description.,NEEDS_REVIEW
AM-202417,2024-05-08,Ahmedabad,Ward 13 – Sabarmati,"Manek Chowk, Old City",Night market waste not cleared before morning. Heritage area affected.,Councillor Referral,21,Waste,Standard,Identified as Waste based on the description of 'waste'.,NEEDS_REVIEW
AM-202421,2024-05-03,Ahmedabad,Ward 14 – Odhav,"CG Road, commercial zone",Club music audible at residential buildings at 2am.,Citizen Portal,18,Noise,Standard,Identified as Noise based on the description of 'music'.,
AM-202424,2024-05-04,Ahmedabad,Ward 11 – Vastrapur,"Shahibaug, near zoo",Zoo approach road surface bubbling at 45°C. Visitor complaints.,Councillor Referral,19,Road Damage,Standard,Identified as Road Damage based on the description of 'road surface'.,
AM-202429,2024-04-24,Ahmedabad,Ward 11 – Vastrapur,Ellis Bridge walking track,River walk surface temperature unbearable. Installed temperature reads 52°C.,Councillor Referral,3,Other,Standard,Classified as Other due to lack of specific category keywords in the description.,NEEDS_REVIEW
AM-202431,2024-04-26,Ahmedabad,Ward 14 – Odhav,"Paldi, Ratanpol area",Old city road subsidence near ancient step well. Heritage concern.,Citizen Portal,18,Heritage Damage,Standard,Identified as Heritage Damage based on the description of 'heritage'.,
AM-202435,2024-05-07,Ahmedabad,Ward 11 – Vastrapur,"New CG Road, Chandkheda",Black metal road dividers storing heat. Motorists reporting burns on contact.,WhatsApp Helpline,16,Heat Hazard,Standard,Identified as Heat Hazard based on the description of 'heat'.,
AM-202444,2024-05-15,Ahmedabad,Ward 12 – Maninagar,"Jivraj Park, commercial area",Restaurant waste bins overflowing on Sunday night. Health risk.,Councillor Referral,20,Waste,Standard,Identified as Waste based on the description of 'waste'.,NEEDS_REVIEW
AM-202445,2024-04-19,Ahmedabad,Ward 13 – Sabarmati,Ranip Bus Rapid Transit stop,BRT shelter roof glass broken. Users exposed to full sun.,Councillor Referral,9,Other,Standard,Classified as Other due to lack of specific category keywords in the description.,NEEDS_REVIEW
16 changes: 16 additions & 0 deletions uc-0a/results_hyderabad.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
complaint_id,date_raised,city,ward,location,description,reported_by,days_open,category,priority,reason,flag
GH-202401,2024-07-01,Hyderabad,Ward 55 – Secunderabad,Tank Bund Road underpass,Underpass flooded after 1hr rain. Ambulance diverted. Lives at risk.,WhatsApp Helpline,13,Flooding,Urgent,Classified as Flooding with Urgent priority due to the mention of 'ambulance'.,
GH-202402,2024-07-13,Hyderabad,Ward 55 – Secunderabad,Dilsukhnagar Monda Market area,Market area flooded. Traders suffering losses. Drain completely blocked.,Citizen Portal,20,Flooding,Standard,Identified as Flooding based on the description of 'flood'.,NEEDS_REVIEW
GH-202406,2024-07-26,Hyderabad,Ward 54 – Kukatpally,"Mehdipatnam, Rethibowli Road",Main stormwater drain 100% blocked with construction debris.,Phone Helpline,3,Drain Blockage,Standard,Identified as Drain Blockage based on the description of 'drain'.,
GH-202407,2024-07-15,Hyderabad,Ward 55 – Secunderabad,"Santoshnagar, Saidabad",Drain blocked and mosquito breeding. Dengue concern.,WhatsApp Helpline,4,Drain Blockage,Standard,Identified as Drain Blockage based on the description of 'drain'.,
GH-202410,2024-07-23,Hyderabad,Ward 55 – Secunderabad,"Outer Ring Road service lane, Narsingi",Potholes causing vehicles to slow to 20kmph on fast road.,Councillor Referral,18,Pothole,Standard,Identified as Pothole based on the description of 'pothole'.,
GH-202411,2024-07-31,Hyderabad,Ward 55 – Secunderabad,"Tolichowki, Mount Pleasant Road",Pothole swallowed entire motorcycle wheel. Rider hospitalised.,Ward Office Walk-in,17,Pothole,Urgent,Classified as Pothole with Urgent priority due to the mention of 'hospital'.,
GH-202412,2024-07-24,Hyderabad,Ward 53 – LB Nagar,"Nagole, Ramanthapur Road",School bus struggling to navigate 6 potholes in 200m stretch.,Citizen Portal,4,Pothole,Urgent,Classified as Pothole with Urgent priority due to the mention of 'school'.,
GH-202417,2024-07-16,Hyderabad,Ward 53 – LB Nagar,"Charminar area, old city",Heritage zone garbage overflow. Tourist photographs showing piles of waste.,WhatsApp Helpline,11,Waste,Standard,Identified as Waste based on the description of 'garbage'.,NEEDS_REVIEW
GH-202420,2024-07-10,Hyderabad,Ward 55 – Secunderabad,Hitech City co-working zone,Construction drilling from 5am daily near residential towers.,WhatsApp Helpline,12,Other,Standard,Classified as Other due to lack of specific category keywords in the description.,NEEDS_REVIEW
GH-202422,2024-07-31,Hyderabad,Ward 52 – Madhapur,"Attapur, Shaikpet Road",Road collapsed partially. Crater 1m deep near residential gate.,Social Media,1,Pothole,Urgent,Classified as Pothole with Urgent priority due to the mention of 'collapse'.,
GH-202424,2024-07-19,Hyderabad,Ward 52 – Madhapur,Malkajgiri railway underpass,Underpass floods in light rain. Cars regularly abandoned.,Councillor Referral,5,Flooding,Standard,Identified as Flooding based on the description of 'flood'.,
GH-202428,2024-07-24,Hyderabad,Ward 54 – Kukatpally,Tolichowki Friday Market area,Post-market waste not cleared. Area unusable by Sunday morning.,Ward Office Walk-in,8,Waste,Standard,Identified as Waste based on the description of 'waste'.,
GH-202432,2024-07-19,Hyderabad,Ward 51 – Jubilee Hills,"Kukatpally, KPHB Phase 7",24hr supermarket delivery trucks idling with engines on.,Citizen Portal,2,Other,Standard,Classified as Other due to lack of specific category keywords in the description.,NEEDS_REVIEW
GH-202448,2024-07-22,Hyderabad,Ward 52 – Madhapur,Kondapur main drain,Main drain blocked — entire locality at flooding risk this week.,Councillor Referral,8,Flooding,Standard,Identified as Flooding based on the description of 'flood'.,NEEDS_REVIEW
GH-202438,2024-07-06,Hyderabad,Ward 53 – LB Nagar,Hayathnagar residential colony,Colony surrounded by fields that channel rainwater through main road.,Social Media,11,Other,Standard,Classified as Other due to lack of specific category keywords in the description.,NEEDS_REVIEW
16 changes: 16 additions & 0 deletions uc-0a/results_kolkata.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
complaint_id,date_raised,city,ward,location,description,reported_by,days_open,category,priority,reason,flag
KM-202401,2024-06-19,Kolkata,Ward 27 – Salt Lake,"Park Street, Victoria area",Heritage lamp post knocked over by delivery vehicle. Not restored.,Email,17,Streetlight,Standard,Identified as Streetlight based on the description of 'lamp'.,NEEDS_REVIEW
KM-202402,2024-06-07,Kolkata,Ward 25 – Jadavpur,"College Street, Boi Para",Historic tram road cobblestones broken up by cable laying work.,Councillor Referral,16,Other,Standard,Classified as Other due to lack of specific category keywords in the description.,NEEDS_REVIEW
KM-202405,2024-06-13,Kolkata,Ward 25 – Jadavpur,"Jorasanko, heritage zone",Wedding band playing near Tagore Museum at 11pm. Festival season ongoing.,Ward Office Walk-in,10,Other,Standard,Classified as Other due to lack of specific category keywords in the description.,NEEDS_REVIEW
KM-202409,2024-06-05,Kolkata,Ward 26 – Behala,VIP Road near Dum Dum Airport,Airport access road full of potholes. Diplomatic complaint received.,Councillor Referral,7,Pothole,Standard,Identified as Pothole based on the description of 'pothole'.,
KM-202410,2024-06-21,Kolkata,Ward 26 – Behala,EM Bypass near Science City,Pothole causing tyre blowouts. Three incidents this week.,Email,1,Pothole,Standard,Identified as Pothole based on the description of 'pothole'.,
KM-202411,2024-06-23,Kolkata,Ward 26 – Behala,"Tollygunge, Sardar Shankar Road",Deep pothole filling with rainwater. Depth invisible. Accident risk.,Councillor Referral,12,Pothole,Standard,Identified as Pothole based on the description of 'pothole'.,
KM-202415,2024-06-28,Kolkata,Ward 26 – Behala,"Kasba, off bypass",New residential complex draining directly onto public road.,WhatsApp Helpline,13,Drain Blockage,Standard,Identified as Drain Blockage based on the description of 'drain'.,
KM-202418,2024-06-04,Kolkata,Ward 23 – Park Street,"New Market, Lindsay Street",Tourist zone waste overflowing. Foreign visitors photographing piles.,Ward Office Walk-in,15,Waste,Standard,Identified as Waste based on the description of 'waste'.,NEEDS_REVIEW
KM-202421,2024-06-08,Kolkata,Ward 23 – Park Street,Rashbehari Avenue,Footpath broken and sinking. Elderly pedestrian fell. Hospital visit.,Social Media,3,Road Damage,Urgent,Classified as Road Damage with Urgent priority due to the mention of 'hospital'.,
KM-202422,2024-06-06,Kolkata,Ward 24 – Shyambazar,"Howrah Bridge approach, Kolkata side",Road surface buckled near bridge. Structural concern raised.,Social Media,1,Road Damage,Standard,Identified as Road Damage based on the description of 'road surface'.,
KM-202426,2024-06-17,Kolkata,Ward 24 – Shyambazar,"Bow Barracks, central Kolkata",Heritage residential building exterior defaced by billboard installation.,Phone Helpline,1,Heritage Damage,Standard,Identified as Heritage Damage based on the description of 'heritage'.,
KM-202430,2024-06-08,Kolkata,Ward 23 – Park Street,"Park Street, restaurant zone",Road subsided near gas pipeline. Gas leak smell reported too.,Social Media,21,Waste,Standard,Identified as Waste based on the description of 'smell'.,
KM-202434,2024-06-15,Kolkata,Ward 23 – Park Street,"Marble Palace, Muktaram Babu Street",Street paving removed for utility work — heritage stone not replaced.,Email,14,Heritage Damage,Standard,Identified as Heritage Damage based on the description of 'heritage'.,
KM-202436,2024-06-26,Kolkata,Ward 27 – Salt Lake,"New Alipore, residential colony",Entire colony substation tripped. Darkness for 3 nights.,Councillor Referral,17,Streetlight,Standard,Identified as Streetlight based on the description of 'dark'.,
KM-202438,2024-06-22,Kolkata,Ward 25 – Jadavpur,"Esplanade, near Metro",Street vendors using amplifiers illegally in heritage precinct.,Councillor Referral,19,Heritage Damage,Standard,Identified as Heritage Damage based on the description of 'heritage'.,
Loading