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
18 changes: 7 additions & 11 deletions uc-0a/agents.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# 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?]
An agent that classifies citizen complaints by category and determines priority based on the complaint description.

intent: >
[FILL IN: What does a correct output look like — make it verifiable]
To accurately assign a category from a predefined list, calculate priority based on severity keywords, and extract a one-sentence reason citing specific words from the description, outputting the results as a CSV file to uc-0a/results_[your-city].csv.

context: >
[FILL IN: What information is the agent allowed to use? State exclusions explicitly.]
The agent is allowed to use only the text description of the complaint.

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. Exact strings only - no variations."
- "Priority must be 'Urgent' if description contains any of: injury, child, school, hospital, ambulance, fire, hazard, fell, collapse. Otherwise 'Standard' or 'Low'."
- "The reason field must be one sentence citing specific words from the description."
- "If the category is genuinely ambiguous, set flag to 'NEEDS_REVIEW'."
92 changes: 84 additions & 8 deletions uc-0a/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,102 @@
"""
import argparse
import csv
import re

def classify_complaint(row: dict) -> dict:
"""
Classify a single complaint row.
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", "").lower()

# Check for priority keywords
urgent_keywords = ["injury", "child", "school", "hospital", "ambulance", "fire", "hazard", "fell", "collapse"]
priority = "Standard"
urgent_matches = []

for kw in urgent_keywords:
if kw in description:
priority = "Urgent"
urgent_matches.append(kw)

# Check for exact category strings only - no variations
allowed_categories = [
"Pothole", "Flooding", "Streetlight", "Waste", "Noise",
"Road Damage", "Heritage Damage", "Heat Hazard", "Drain Blockage", "Other"
]

found_categories = []

for cat in allowed_categories:
if cat.lower() in description:
found_categories.append(cat)

if len(found_categories) == 1:
category = found_categories[0]
flag = ""
reason = f"Classified as {category} because description mentions it exactly."
elif len(found_categories) > 1:
category = ""
flag = "NEEDS_REVIEW"
reason = f"Ambiguous category. Description mentions exact keywords for {', '.join(found_categories)}."
else:
category = ""
flag = "NEEDS_REVIEW"
reason = "Could not definitively determine category from the text."

if priority == "Urgent":
reason += f" Priority is Urgent due to severity keyword(s): {', '.join(urgent_matches)}."

return {
"complaint_id": row.get("complaint_id", ""),
"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")
results = []
fieldnames = []

try:
with open(input_path, mode='r', encoding='utf-8') as infile:
reader = csv.DictReader(infile)
for row in reader:
try:
result = classify_complaint(row)
out_row = {**row, **result}
results.append(out_row)
if not fieldnames:
fieldnames = list(row.keys()) + ["category", "priority", "reason", "flag"]
except Exception as e:
print(f"Error processing row {row.get('complaint_id', 'unknown')}: {e}")
results.append(row)
except Exception as e:
print(f"Error reading input file: {e}")
return

try:
with open(output_path, mode='w', encoding='utf-8', newline='') as outfile:
if not fieldnames:
fieldnames = ["complaint_id", "category", "priority", "reason", "flag"]

final_fieldnames = []
for f in fieldnames:
if f not in final_fieldnames:
final_fieldnames.append(f)

writer = csv.DictWriter(outfile, fieldnames=final_fieldnames)
writer.writeheader()
for row in results:
writer.writerow(row)
except Exception as e:
print(f"Error writing output file: {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,,Standard,Could not definitively determine category from the text.,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,,Standard,Could not definitively determine category from the text.,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,,Standard,Could not definitively determine category from the text.,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,,Standard,Could not definitively determine category from the text.,NEEDS_REVIEW
AM-202407,2024-04-25,Ahmedabad,Ward 15 – Chandkheda,"Thaltej, residential park",Broken bench and upturned paving. Child injured last week.,Email,20,,Urgent,Could not definitively determine category from the text. Priority is Urgent due to severity keyword(s): 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,Classified as Pothole because description mentions it exactly.,
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,,Standard,Could not definitively determine category from the text.,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,Classified as Waste because description mentions it exactly.,
AM-202421,2024-05-03,Ahmedabad,Ward 14 – Odhav,"CG Road, commercial zone",Club music audible at residential buildings at 2am.,Citizen Portal,18,,Standard,Could not definitively determine category from the text.,NEEDS_REVIEW
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,,Standard,Could not definitively determine category from the text.,NEEDS_REVIEW
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,,Standard,Could not definitively determine category from the text.,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,,Standard,Could not definitively determine category from the text.,NEEDS_REVIEW
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,,Standard,Could not definitively determine category from the text.,NEEDS_REVIEW
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,Classified as Waste because description mentions it exactly.,
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,,Standard,Could not definitively determine category from the text.,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,,Urgent,Could not definitively determine category from the text. Priority is Urgent due to severity keyword(s): ambulance.,NEEDS_REVIEW
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,,Standard,Could not definitively determine category from the text.,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,,Standard,Could not definitively determine category from the text.,NEEDS_REVIEW
GH-202407,2024-07-15,Hyderabad,Ward 55 – Secunderabad,"Santoshnagar, Saidabad",Drain blocked and mosquito breeding. Dengue concern.,WhatsApp Helpline,4,,Standard,Could not definitively determine category from the text.,NEEDS_REVIEW
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,Classified as Pothole because description mentions it exactly.,
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 because description mentions it exactly. Priority is Urgent due to severity keyword(s): 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 because description mentions it exactly. Priority is Urgent due to severity keyword(s): 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,Classified as Waste because description mentions it exactly.,
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,,Standard,Could not definitively determine category from the text.,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,,Urgent,Could not definitively determine category from the text. Priority is Urgent due to severity keyword(s): collapse.,NEEDS_REVIEW
GH-202424,2024-07-19,Hyderabad,Ward 52 – Madhapur,Malkajgiri railway underpass,Underpass floods in light rain. Cars regularly abandoned.,Councillor Referral,5,,Standard,Could not definitively determine category from the text.,NEEDS_REVIEW
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,Classified as Waste because description mentions it exactly.,
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,,Standard,Could not definitively determine category from the text.,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,Classified as Flooding because description mentions it exactly.,
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,,Standard,Could not definitively determine category from the text.,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,,Standard,Could not definitively determine category from the text.,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,,Standard,Could not definitively determine category from the text.,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,,Standard,Could not definitively determine category from the text.,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,Classified as Pothole because description mentions it exactly.,
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,Classified as Pothole because description mentions it exactly.,
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,Classified as Pothole because description mentions it exactly.,
KM-202415,2024-06-28,Kolkata,Ward 26 – Behala,"Kasba, off bypass",New residential complex draining directly onto public road.,WhatsApp Helpline,13,,Standard,Could not definitively determine category from the text.,NEEDS_REVIEW
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,Classified as Waste because description mentions it exactly.,
KM-202421,2024-06-08,Kolkata,Ward 23 – Park Street,Rashbehari Avenue,Footpath broken and sinking. Elderly pedestrian fell. Hospital visit.,Social Media,3,,Urgent,"Could not definitively determine category from the text. Priority is Urgent due to severity keyword(s): hospital, fell.",NEEDS_REVIEW
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,,Standard,Could not definitively determine category from the text.,NEEDS_REVIEW
KM-202426,2024-06-17,Kolkata,Ward 24 – Shyambazar,"Bow Barracks, central Kolkata",Heritage residential building exterior defaced by billboard installation.,Phone Helpline,1,,Standard,Could not definitively determine category from the text.,NEEDS_REVIEW
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,,Standard,Could not definitively determine category from the text.,NEEDS_REVIEW
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,,Standard,Could not definitively determine category from the text.,NEEDS_REVIEW
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,,Standard,Could not definitively determine category from the text.,NEEDS_REVIEW
KM-202438,2024-06-22,Kolkata,Ward 25 – Jadavpur,"Esplanade, near Metro",Street vendors using amplifiers illegally in heritage precinct.,Councillor Referral,19,,Standard,Could not definitively determine category from the text.,NEEDS_REVIEW
Loading