πŸ”¬ Forensic AI Chatbot

← Back to Investigation

About This Project

An AI-powered forensic investigation tool that helps police officers analyze telecom data (CDR, IPDR, Tower Dumps) through natural language conversation β€” built for the Police Hackathon.

πŸ€– AI Agent Architecture

We use a ReAct-style autonomous agent powered by a large language model that can reason, plan, and execute forensic analysis tools in a loop.

Model

gpt-5.4-mini via OpenAI-compatible API

Agent Type

ReAct Tool-Calling Agent β€” reasons about the question, picks tools, reads results, chains up to 8 iterations

Agent Role

Prompted as a forensic analyst specialising in Indian telecom data with knowledge of +91 formats, tower IDs, and investigation procedures

Error Recovery

Built-in retry detection β€” stops after 2 failures on same tool, force-answers after 3 total errors

πŸ”§ 9 Forensic Analysis Tools

The agent has access to 9 specialized tools. Tools 7-9 work across all 3 datasets simultaneously.

#ToolDatasetsWhat It Does
1filter_recordsSingleFilter any dataset by phone number, time range, or tower ID
2find_connectionsCDRFind direct call links between a set of suspect numbers
3cross_referenceCDR+IPDR+TowerBuild a full profile of one number across all datasets
4tower_lookupTowerFind all devices near a specific cell tower in a time window
5flag_anomalySingleDetect high call volume (50+), burner phones, IMEI swaps, burst calling
6generate_summaryCDR+IPDR+TowerGenerate structured case report with suspect profiles
7correlate_suspectsALL 3Find numbers appearing in multiple datasets, rank by suspiciousness, filter by tower/time
8timelineALL 3Chronological timeline of calls, internet, tower pings for a suspect
9deep_analysisALL 3Crime scene analysis: phones near tower + mutual calls + IMEI cross-match

πŸ“Š Data Types Supported

πŸ“ž CDR β€” Call Detail Records

Who called who, when, call duration, tower used, IMEI. Auto-detected by a_party_number column.

🌐 IPDR β€” Internet Protocol Detail Records

Internet sessions, source/destination IPs, services accessed, data transferred. Auto-detected by source_ip or destination_ip.

πŸ—Ό Tower Dump

All phones that pinged a cell tower in a time window, with IMEI, signal type, location. Auto-detected by time_of_activity.

⚑ How It Works β€” Data Flow

πŸ“ Upload CSV/XLSX
β†’
πŸ” Auto-detect type (CDR/IPDR/Tower)
β†’
πŸ’Ύ Store in pandas DataFrame
πŸ’¬ Officer asks question
β†’
πŸ€– AI Agent picks tools
β†’
πŸ”§ Tools query DataFrames
β†’
πŸ“Š Answer + Visualization

πŸ—οΈ Technology Stack

LayerTechnologyPurpose
BackendFastAPI (Python)REST API server, file upload, chat endpoint, PDF export
ServerUvicornASGI server running the FastAPI app
AI ClientOpenAI SDKCommunicates with LLM via OpenAI-compatible API
Data ProcessingpandasAll filtering, grouping, anomaly detection on DataFrames
PDF Exportfpdf2Generates investigation reports as PDF
Excel SupportopenpyxlReads .xlsx/.xls uploads
FrontendHTML/CSS/JSSingle-page app with dark forensic theme
Network Graphvis.jsInteractive node-edge graph for call networks
ChartsChart.jsBar charts for activity visualization
Configpython-dotenvLoads API keys from .env file

🎯 Key Features

🧠 Multi-Step Reasoning

Agent chains up to 8 tool calls per query β€” cross-references, then checks anomalies, then builds timeline automatically.

πŸ“± Burner Phone Detection

Detects IMEI swaps across tower and CDR data β€” flags suspects using multiple devices.

πŸ—ΊοΈ Crime Scene Analysis

Deep analysis around a tower: finds who was there, checks if they called each other, cross-matches IMEIs.

πŸ“ˆ Interactive Visualizations

Network graphs showing call connections, bar charts for activity patterns, real-time stats.

πŸ“„ PDF Export

One-click export of investigation findings as a structured PDF report for court submission.

πŸ”„ Smart File Detection

Auto-classifies uploaded files as CDR, IPDR, or Tower by analyzing column names β€” no manual selection needed.

πŸ“ Project Structure

FileLinesRole
main.py~740FastAPI app β€” endpoints, visualization logic, PDF export
agent.py~170AI agent loop β€” LLM calls + tool execution + error recovery
tools.py~800All 9 forensic analysis tools (pandas-based)
tool_definitions.py~200OpenAI function-calling schemas for the 9 tools
templates/index.html~810Full frontend UI (HTML + CSS + JS)
templates/about.htmlβ€”This page β€” project documentation
test_tools.py~15043 automated tests for all 9 tools

πŸ§ͺ Testing

All 9 tools are covered by 43 automated tests that run against the demo dataset (5000 CDR + 5000 IPDR + 5000 Tower records). Tests verify filtering, cross-referencing, anomaly detection, timeline building, deep analysis, and error handling.

Run tests: python test_tools.py