Inspiration
My inspiration for CivicSense came from a simple observation: most city management is reactive. When a power line falls, a water main breaks, or a dangerous pothole forms, cities typically have to wait for a citizen to notice it and call a 311 hotline. This delay between an event's occurrence and its official report can directly impact public safety and quality of life.
I was inspired to ask a critical question: In an age of real-time data and powerful AI, why are we still waiting? I envisioned a system that could act as a digital watchdog for a city, a proactive force that constantly monitors the digital pulse of the community to find and flag issues the moment they surface. I wanted to build a tool that doesn't just solve problems but helps prevent them from escalating.
What it does
CivicSense is an autonomous, multi-agent AI system that transforms raw, real-time public data into actionable civic intelligence. Here's what it does:
Ingests Real-Time Data: The system continuously monitors public data streams, such as tweets from the Twitter/X API and simulated 311 reports, to capture citizen observations as they happen.
Analyzes with an AI Team: The core of the system is a collaborative team of four specialized AI agents. They read unstructured text, classify the type of issue (e.g., "Traffic Hazard," "Power Outage"), and assess its priority level.
Generates Deep Insights: The most powerful feature is the Analyst agent. It doesn't just look at individual issues; it analyzes the entire set of active problems to find hidden patterns and trends. For example, it can identify a "cluster" of related infrastructure issues, turning scattered data points into a single, high-level insight for city managers.
Dispatches & Visualizes: For high-priority events, the system automatically dispatches an SMS alert to the relevant personnel. All detected issues and generated insights are plotted in real-time on a live, map-based dashboard, providing a complete, at-a-glance operational overview of the city.
How I built it
I designed CivicSense as a stateful, multi-agent system to enable complex analysis over time.
Backend: The system's core is an asynchronous FastAPI server written in Python. It runs two parallel background tasks: a high-frequency poller for new data and a low-frequency task for deep analysis. I created a central CityState manager to act as the system's in-memory "short-term memory."
The AI Core: The intelligence is powered by a team of four agents orchestrated using LangChain. All AI reasoning, from classification to pattern analysis, is performed by a local Llama 3 Large Language Model served by Ollama. This ensures the system is private, cost-effective, and can run on a local machine with a GPU. The four agents are:
The Observer: Ingests and structures raw text.
The Analyst: Synthesizes data to find patterns.
The Dispatcher: Decides on the correct action protocol.
The Communicator: Handles all external alerts via a Twilio tool.
Frontend: The user interface is a responsive dashboard built with React and Vite. It polls the backend API for the latest state and uses Leaflet to render the interactive map, providing a dynamic and intuitive visualization of the data.
Challenges I ran into
AI Consistency and Reliability: My biggest initial challenge was that the LLM, in its creativity, would return JSON data with slightly different key names (summary, issue_description, etc.), which would break the frontend. I overcame this by implementing very strict prompt engineering and using Pydantic models to enforce a consistent output schema. This was a critical lesson in making AI reliable for application development.
API Limitations: I quickly discovered the free Twitter/X API has strict rate limits and does not support the advanced geospatial search operators we initially planned for. I adapted by re-engineering my data ingestion module to use a smart keyword-based search and carefully timing my API calls to stay within the rate limits, building a more resilient system in the process.
Achieving True Analysis: My first version of the Analyst agent used simple rules (like counting issue types) and was too rigid to find meaningful patterns. I re-architected it to use its own LLM chain, allowing it to perform semantic clustering based on the meaning of the issues. This upgrade transformed it from a simple counter into a true analytical brain for my system.
Accomplishments that I'm proud of
I'm incredibly proud of building a complete, end-to-end multi-agent AI system in such a short time. I went far beyond a simple script and created a collaborative team of agents with specialized roles.
Designing and implementing the stateful architecture was a major accomplishment. Giving the system a "memory" is what unlocks its most powerful feature: the ability to perform analysis over time.
Successfully leveraging a fully local LLM for all AI tasks is another point of pride. I built a powerful AI application that is completely free to run, is 100% private, and doesn't depend on any external paid APIs.
Finally, seeing the entire pipeline work—from a random tweet to a structured issue, to a high-level insight appearing on the map, to a real SMS alert on my phone—was an incredibly rewarding moment.
What I learned
This project was a deep dive into the practicalities of building with modern AI. I learned that prompt engineering is a critical skill; the quality of your instructions to the AI directly determines the quality and reliability of its output.
I also learned the importance of designing for resilience. Real-world data is messy, and APIs have limitations. Building systems that can gracefully handle errors and adapt their strategy is essential.
Most importantly, I learned how to think in terms of agentic architectures. Breaking a complex problem down into smaller, specialized tasks that can be assigned to different AI agents is a powerful new paradigm for software development.
What's next for CivicSense
This prototype is a strong foundation, and I have a clear vision for its future. My next steps include:
Upgrading to a Persistent Database: I plan to replace the in-memory state with a PostgreSQL database with the PostGIS extension. This will unlock the ability to perform historical and complex geospatial analysis.
Integrating More Data Sources: I want to expand the system's senses by integrating with real-time weather APIs, public transit feeds (GTFS-RT), and municipal IoT sensors.
Developing Predictive Analytics: With a historical database, I can enhance the Analyst agent to move beyond pattern recognition and into predictive analytics, forecasting potential infrastructure failures before they happen.
Containerization and Deployment: Finally, I'll containerize the application with Docker and prepare it for deployment to a scalable cloud platform like AWS for real-world use by municipalities.

Log in or sign up for Devpost to join the conversation.