HaramGuard / backend /README.md
adeem6's picture
Update backend/README.md (#17)
d6dde3f
# HaramGuard β€” Agentic AI Crowd Management System
## πŸ“ Folder Structure
```
HaramGuard/
β”‚
β”œβ”€β”€ config.py ← All thresholds & API keys (edit here only)
β”œβ”€β”€ pipeline.py ← RealTimePipeline β€” orchestrates all agents
β”œβ”€β”€ dashboard.py ← Streamlit dashboard entry point
β”œβ”€β”€ requirements.txt
β”‚
β”œβ”€β”€ core/ ← Shared infrastructure (no agent logic here)
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ models.py ← FrameResult, RiskResult, Decision dataclasses
β”‚ └── database.py ← HajjFlowDB β€” SQLite (4 tables)
β”‚
β”œβ”€β”€ agents/ ← One file per agent
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ perception_agent.py ← YOLO tracking + Guardrails GR1/GR2
β”‚ β”œβ”€β”€ risk_agent.py ← Clip segmentation + sliding K-window density scoring
β”‚ β”œβ”€β”€ reflection_agent.py ← Self-critique design pattern (Bias detection)
β”‚ β”œβ”€β”€ operations_agent.py ← Event-driven playbook + rate-limit guardrail
β”‚ └── coordinator_agent.py ← openai/gpt-oss-120b + output validation guardrails GR-C1..5
β”‚
└── outputs/ ← Auto-created at runtime
β”œβ”€β”€ hajjflow_rt.db ← Main SQLite database
└── plots/ ← Saved charts
```
## πŸ€– Agent Pipeline
```
Frame
β”‚
β–Ό
PerceptionAgent β†’ FrameResult (YOLO detect + track)
β”‚
β–Ό
RiskAgent β†’ RiskResult (clip segmentation + K-window density score)
β”‚
β–Ό
ReflectionAgent β†’ reflection{} (bias check + correction)
β”‚
β–Ό
OperationsAgent β†’ Decision (event-driven, P0/P1/P2)
β”‚
β–Ό
CoordinatorAgent β†’ plan{} (openai/gpt-oss-120b action plan, all priorities)
β”‚
β–Ό
pipeline.state β†’ Dashboard
```
## πŸ›‘οΈ Guardrails
| ID | Agent | Description |
|----|-------|-------------|
| GR1 | PerceptionAgent | Person count capped at 500 |
| GR2 | PerceptionAgent | Density score capped at 50 |
| GR3 | RiskAgent | Risk score clamped to [0, 1] (density_pct / 100) |
| GR3b | RiskAgent | level_changed suppressed during K-window warmup (first 17 frames per clip) |
| GR4 | OperationsAgent | P0 rate-limited (1 per 5 min per zone); resets on pipeline restart |
| GR-C1..5 | CoordinatorAgent | LLM output validation (fields, threat_level, confidence, score-level consistency, Arabic fallback) |
| RF1..3 | ReflectionAgent | Chronic LOW bias, rising trend ignored, count-risk mismatch |
## πŸ“Š Run Evaluation
```bash
python evaluation.py
```
Outputs:
- `outputs/plots/eval_perception.png` β€” PerceptionAgent charts
- `outputs/plots/eval_risk.png` β€” RiskAgent score trajectories
- `outputs/plots/eval_e2e.png` β€” End-to-end accuracy + throughput
- `outputs/eval/summary.json` β€” Final metrics summary
Rubric coverage:
- βœ… End-to-end performance metrics (Section 5)
- βœ… Component-level evaluation (Sections 1–4)
- βœ… Error analysis methodology (Section 6)
- βœ… Evidence of iterative improvement (Section 7)
## πŸš€ Run Backend API
```bash
pip install -r requirements.txt
python api.py
```