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
17 changes: 8 additions & 9 deletions uc-0a/agents.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# 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?]
Expert Citizen Complaint Classifier. Responsible for mapping raw citizen complaints into a standardized taxonomy while identifying high-risk safety hazards.

intent: >
[FILL IN: What does a correct output look like — make it verifiable]
Produce a verifiable classification record for every complaint. A correct output includes a category chosen strictly from the allowed list, a priority level that correctly flags safety risks, a one-sentence justification citing evidence, and a review flag for ambiguity.

context: >
[FILL IN: What information is the agent allowed to use? State exclusions explicitly.]
The agent is provided with a single complaint description at a time. It must use the classification schema defined in the project. It is strictly forbidden from hallucinating categories outside the taxonomy or assuming priority without evidence from the text.

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 combined categories allowed."
-"Priority has to be either urgent,standard or low"
- "Priority must be 'Urgent' if the description contains any of: injury, child, school, hospital, ambulance, fire, hazard, fell, collapse. Otherwise, use 'Standard' or 'Low' based on severity."
- "The 'reason' field must be exactly one sentence and must cite specific words/phrases from the input description."
- "The 'flag' field must be set to 'NEEDS_REVIEW' if the category is genuinely ambiguous or if multiple categories seem equally valid. Otherwise, leave blank."
111 changes: 102 additions & 9 deletions uc-0a/classifier.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,122 @@
"""
UC-0A — Complaint Classifier
Starter file. Build this using the RICE → agents.md → skills.md → CRAFT workflow.
Built using the RICE → agents.md → skills.md → CRAFT workflow.
"""
import argparse
import csv
import os

# Configuration from agents.md
ALLOWED_CATEGORIES = [
"Pothole", "Flooding", "Streetlight", "Waste", "Noise",
"Road Damage", "Heritage Damage", "Heat Hazard", "Drain Blockage", "Other"
]

URGENT_KEYWORDS = [
"injury", "child", "school", "hospital", "ambulance",
"fire", "hazard", "fell", "collapse"
]

CATEGORY_KEYWORDS = {
"Pothole": ["pothole", "crater", "hole in road"],
"Flooding": ["flood", "waterlogging", "rain water", "submerged"],
"Streetlight": ["light", "dark", "lamp", "street light"],
"Waste": ["garbage", "trash", "waste", "dump", "plastic", "bin"],
"Noise": ["noise", "loud", "sound", "music", "disturbance"],
"Road Damage": ["road", "broken road", "surface", "pavement"],
"Heritage Damage": ["heritage", "monument", "statue", "old building"],
"Heat Hazard": ["heat", "hot", "sunstroke", "extreme temperature"],
"Drain Blockage": ["drain", "sewage", "overflow", "gutter", "blockage"]
}

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", "").strip()
complaint_id = row.get("complaint_id", "Unknown")

if not description or len(description) < 5:
return {
"complaint_id": complaint_id,
"category": "Other",
"priority": "Low",
"reason": "Description is missing or too short to classify.",
"flag": "NEEDS_REVIEW"
}

desc_lower = description.lower()

# 1. Determine Category
category = "Other"
for cat, keywords in CATEGORY_KEYWORDS.items():
if any(kw in desc_lower for kw in keywords):
category = cat
break

# 2. Determine Priority
priority = "Standard"
urgent_trigger = [kw for kw in URGENT_KEYWORDS if kw in desc_lower]
if urgent_trigger:
priority = "Urgent"
elif "low" in desc_lower or "minor" in desc_lower:
priority = "Low"

# 3. Generate Reason
if priority == "Urgent":
reason = f"Classified as Urgent because it mentions safety-critical terms like '{urgent_trigger[0]}'."
elif category != "Other":
reason = f"Classified as {category} based on the mention of related infrastructure issues."
else:
reason = "Classified as Other due to lack of specific infrastructure keywords."

# 4. Set Flag
flag = ""
if category == "Other" or "not sure" in desc_lower or "unclear" in desc_lower:
flag = "NEEDS_REVIEW"

return {
"complaint_id": 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")
if not os.path.exists(input_path):
print(f"Error: Input file {input_path} not found.")
return

results = []
try:
with open(input_path, mode='r', encoding='utf-8') as f:
reader = csv.DictReader(f)
for row in reader:
try:
classified = classify_complaint(row)
results.append(classified)
except Exception as e:
print(f"Warning: Failed to process row {row.get('complaint_id', 'unknown')}: {e}")
continue

if not results:
print("No data found in input file.")
return

keys = results[0].keys()
with open(output_path, mode='w', encoding='utf-8', newline='') as f:
writer = csv.DictWriter(f, fieldnames=keys)
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,category,priority,reason,flag
AM-202401,Road Damage,Standard,Classified as Road Damage based on the mention of related infrastructure issues.,
AM-202402,Other,Standard,Classified as Other due to lack of specific infrastructure keywords.,NEEDS_REVIEW
AM-202405,Other,Standard,Classified as Other due to lack of specific infrastructure keywords.,NEEDS_REVIEW
AM-202406,Heat Hazard,Standard,Classified as Heat Hazard based on the mention of related infrastructure issues.,
AM-202407,Other,Urgent,Classified as Urgent because it mentions safety-critical terms like 'child'.,NEEDS_REVIEW
AM-202410,Pothole,Standard,Classified as Pothole based on the mention of related infrastructure issues.,
AM-202414,Other,Standard,Classified as Other due to lack of specific infrastructure keywords.,NEEDS_REVIEW
AM-202417,Waste,Standard,Classified as Waste based on the mention of related infrastructure issues.,
AM-202421,Noise,Standard,Classified as Noise based on the mention of related infrastructure issues.,
AM-202424,Road Damage,Standard,Classified as Road Damage based on the mention of related infrastructure issues.,
AM-202429,Road Damage,Standard,Classified as Road Damage based on the mention of related infrastructure issues.,
AM-202431,Road Damage,Standard,Classified as Road Damage based on the mention of related infrastructure issues.,
AM-202435,Road Damage,Standard,Classified as Road Damage based on the mention of related infrastructure issues.,
AM-202444,Waste,Low,Classified as Waste based on the mention of related infrastructure issues.,
AM-202445,Other,Standard,Classified as Other due to lack of specific infrastructure keywords.,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,category,priority,reason,flag
GH-202401,Flooding,Urgent,Classified as Urgent because it mentions safety-critical terms like 'ambulance'.,
GH-202402,Flooding,Standard,Classified as Flooding based on the mention of related infrastructure issues.,
GH-202406,Drain Blockage,Standard,Classified as Drain Blockage based on the mention of related infrastructure issues.,
GH-202407,Drain Blockage,Standard,Classified as Drain Blockage based on the mention of related infrastructure issues.,
GH-202410,Pothole,Low,Classified as Pothole based on the mention of related infrastructure issues.,
GH-202411,Pothole,Urgent,Classified as Urgent because it mentions safety-critical terms like 'hospital'.,
GH-202412,Pothole,Urgent,Classified as Urgent because it mentions safety-critical terms like 'school'.,
GH-202417,Waste,Low,Classified as Waste based on the mention of related infrastructure issues.,
GH-202420,Other,Standard,Classified as Other due to lack of specific infrastructure keywords.,NEEDS_REVIEW
GH-202422,Pothole,Urgent,Classified as Urgent because it mentions safety-critical terms like 'collapse'.,
GH-202424,Flooding,Standard,Classified as Flooding based on the mention of related infrastructure issues.,
GH-202428,Waste,Standard,Classified as Waste based on the mention of related infrastructure issues.,
GH-202432,Other,Standard,Classified as Other due to lack of specific infrastructure keywords.,NEEDS_REVIEW
GH-202448,Flooding,Standard,Classified as Flooding based on the mention of related infrastructure issues.,
GH-202438,Road Damage,Standard,Classified as Road Damage based on the mention of related infrastructure issues.,
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,category,priority,reason,flag
KM-202401,Streetlight,Standard,Classified as Streetlight based on the mention of related infrastructure issues.,
KM-202402,Road Damage,Standard,Classified as Road Damage based on the mention of related infrastructure issues.,
KM-202405,Other,Standard,Classified as Other due to lack of specific infrastructure keywords.,NEEDS_REVIEW
KM-202409,Pothole,Standard,Classified as Pothole based on the mention of related infrastructure issues.,
KM-202410,Pothole,Low,Classified as Pothole based on the mention of related infrastructure issues.,
KM-202411,Pothole,Standard,Classified as Pothole based on the mention of related infrastructure issues.,
KM-202415,Road Damage,Standard,Classified as Road Damage based on the mention of related infrastructure issues.,
KM-202418,Waste,Low,Classified as Waste based on the mention of related infrastructure issues.,
KM-202421,Other,Urgent,Classified as Urgent because it mentions safety-critical terms like 'hospital'.,NEEDS_REVIEW
KM-202422,Road Damage,Standard,Classified as Road Damage based on the mention of related infrastructure issues.,
KM-202426,Heritage Damage,Standard,Classified as Heritage Damage based on the mention of related infrastructure issues.,
KM-202430,Road Damage,Standard,Classified as Road Damage based on the mention of related infrastructure issues.,
KM-202434,Heritage Damage,Standard,Classified as Heritage Damage based on the mention of related infrastructure issues.,
KM-202436,Streetlight,Standard,Classified as Streetlight based on the mention of related infrastructure issues.,
KM-202438,Heritage Damage,Standard,Classified as Heritage Damage based on the mention of related infrastructure issues.,
16 changes: 16 additions & 0 deletions uc-0a/results_pune.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
complaint_id,category,priority,reason,flag
PM-202401,Pothole,Standard,Classified as Pothole based on the mention of related infrastructure issues.,
PM-202402,Pothole,Urgent,Classified as Urgent because it mentions safety-critical terms like 'child'.,
PM-202406,Flooding,Standard,Classified as Flooding based on the mention of related infrastructure issues.,
PM-202408,Flooding,Standard,Classified as Flooding based on the mention of related infrastructure issues.,
PM-202410,Streetlight,Standard,Classified as Streetlight based on the mention of related infrastructure issues.,
PM-202411,Streetlight,Urgent,Classified as Urgent because it mentions safety-critical terms like 'hazard'.,
PM-202413,Waste,Low,Classified as Waste based on the mention of related infrastructure issues.,
PM-202418,Noise,Standard,Classified as Noise based on the mention of related infrastructure issues.,
PM-202419,Road Damage,Standard,Classified as Road Damage based on the mention of related infrastructure issues.,
PM-202420,Other,Urgent,Classified as Urgent because it mentions safety-critical terms like 'injury'.,NEEDS_REVIEW
PM-202427,Flooding,Standard,Classified as Flooding based on the mention of related infrastructure issues.,
PM-202428,Other,Standard,Classified as Other due to lack of specific infrastructure keywords.,NEEDS_REVIEW
PM-202430,Streetlight,Standard,Classified as Streetlight based on the mention of related infrastructure issues.,
PM-202433,Waste,Standard,Classified as Waste based on the mention of related infrastructure issues.,
PM-202446,Other,Urgent,Classified as Urgent because it mentions safety-critical terms like 'fell'.,NEEDS_REVIEW
22 changes: 10 additions & 12 deletions uc-0a/skills.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# skills.md
# INSTRUCTIONS: Generate a draft by prompting AI, then manually refine this file.
# Delete these comments before committing.

skills:
- name: [skill_name]
description: [One sentence — what does this skill do?]
input: [What does it receive? Type and format.]
output: [What does it return? Type and format.]
error_handling: [What does it do when input is invalid or ambiguous?]
- name: classify_complaint
description: Analyzes a single citizen complaint to determine its category and priority level, providing a justified reason and an optional flag for review.
input: String (the complaint description text).
output: Structured record containing category (from taxonomy), priority (Urgent/Standard/Low), reason (single sentence), and flag (NEEDS_REVIEW or blank).
error_handling: If the description is empty or excessively vague, categorize as 'Other' and set the flag to 'NEEDS_REVIEW'.

- name: [second_skill_name]
description: [One sentence]
input: [Type and format]
output: [Type and format]
error_handling: [What does it do when input is invalid or ambiguous?]
- name: batch_classify
description: Iterates through a CSV file of complaints, applying the classification logic to each row and generating a consolidated results file.
input: File path to a CSV containing a list of complaints (e.g., test_pune.csv).
output: File path to a CSV containing the original descriptions plus the new classification columns (category, priority, reason, flag).
error_handling: Skips malformed CSV rows and logs errors for individual classification failures to ensure the entire batch is processed.
18 changes: 8 additions & 10 deletions uc-0b/agents.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# agents.md
# INSTRUCTIONS: Generate a draft using your RICE prompt, then manually refine this file.
# Delete these comments before committing.
# agents.md — UC-0B Summary That Changes Meaning

role: >
[FILL IN: Who is this agent? What is its operational boundary?]
Legal Policy Auditor and Summarizer. Responsible for distilling HR and municipal policies into concise summaries without losing any binding conditions, specifically multi-approver requirements and strict deadlines.

intent: >
[FILL IN: What does a correct output look like — make it verifiable]
Generate a verifiable policy summary where every source clause is accounted for. A successful summary must retain all "binding verbs" (must, will, required) and preserve all complex conditions (e.g., dual-approval workflows) from the source text.

context: >
[FILL IN: What information is the agent allowed to use? State exclusions explicitly.]
The agent is provided with the full text of a municipal policy document. It must only use information explicitly stated in the source file. It is strictly forbidden from adding "standard industry practice" or "common sense" assumptions not present in the text.

enforcement:
- "[FILL IN: Specific testable rule 1]"
- "[FILL IN: Specific testable rule 2]"
- "[FILL IN: Specific testable rule 3]"
- "[FILL IN: Refusal condition — when should the system refuse rather than guess?]"
- "Every numbered clause from the source document (e.g., 2.3, 5.2) must be explicitly represented in the summary."
- "Multi-condition obligations must preserve all conditions; for instance, if a clause requires approval from two distinct roles, the summary must list both roles."
- "The summary must not include any external context, generalizations, or language like 'typically' or 'generally' if not in the source."
- "Refusal Condition: If a clause contains ambiguous legal phrasing that cannot be summarized without losing specific binding meaning, the agent must quote the source text verbatim and add a [FLAG: LITERAL] marker."
Loading