CoolFace
Apppublic

tnshgarg/SentinelOps

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes
App README

<div align="center">

๐Ÿ›ก๏ธ SentinelOps

Interactive Incident Response Control Room โ€” OpenEnv Environment

A multi-step agentic reinforcement-learning environment where AI agents monitor surveillance camera feeds, detect anomalies, track suspects across cameras, classify threats, and escalate incidents.

![Python 3.11+](https://python.org) ![FastAPI](https://fastapi.tiangolo.com) ![OpenEnv](https://github.com/meta-pytorch/OpenEnv) ![License: MIT](LICENSE) ![Docker](Dockerfile)

</div>


๐ŸŽฏ Overview

SentinelOps simulates a real-world AI security analyst operating a multi-camera surveillance control room. Unlike static VQA benchmarks, SentinelOps creates multi-step agentic episodes where decisions have sequential consequences and rewards are accumulated across trajectories.

Real-World Applications

DomainUse Case
๐Ÿ™๏ธ Smart CitiesCitywide surveillance monitoring
๐Ÿฌ Mall SecurityRetail theft prevention & incident response
๐Ÿฅ Hospital SafetyEmergency room monitoring
๐Ÿญ Industrial PlantsSafety violation detection
๐Ÿšฆ Traffic ControlAutomated traffic incident management

๐Ÿ—๏ธ Architecture

Alert Trigger โ†’ Observation State โ†’ Agent Action โ†’ Environment Transition โ†’ Reward โ†’ Next State

Episode Flow (5โ€“10 steps)

  1. 1.Anomaly alert arrives on a camera feed
  2. 2.Agent inspects the current frame
  3. 3.Agent navigates temporal history (previous/next frames)
  4. 4.Agent switches cameras to track subjects
  5. 5.Agent classifies threat severity
  6. 6.Agent escalates or dismisses the alert

Design Patterns

PatternApplication
StrategyDifficulty-specific graders (Easy/Medium/Hard)
FactoryTask loading and caching
StateEpisode state machine transitions
SOLIDSingle responsibility, dependency inversion

๐Ÿ“ Project Structure

sentinelops/
โ”œโ”€โ”€ inference.py           # Root-level inference script (submission entry point)
โ”œโ”€โ”€ env.py                 # Core environment engine (reset/step/state)
โ”œโ”€โ”€ grader.py              # Deterministic rubric-based graders
โ”œโ”€โ”€ models.py              # Pydantic data models
โ”œโ”€โ”€ config.py              # Centralised configuration
โ”œโ”€โ”€ openenv.yaml           # OpenEnv manifest
โ”œโ”€โ”€ requirements.txt       # Python dependencies
โ”œโ”€โ”€ Dockerfile             # Production Docker image
โ”œโ”€โ”€ validate-submission.sh # Pre-submission validation
โ”œโ”€โ”€ .env.example           # Environment variable template
โ”‚
โ”œโ”€โ”€ server/
โ”‚   โ””โ”€โ”€ app.py             # FastAPI HTTP server
โ”‚
โ”œโ”€โ”€ tasks/
โ”‚   โ”œโ”€โ”€ easy/              # Single-camera anomaly detection
โ”‚   โ”œโ”€โ”€ medium/            # Multi-frame temporal reasoning
โ”‚   โ””โ”€โ”€ hard/              # Multi-camera coordinated incidents
โ”‚
โ”œโ”€โ”€ assets/
โ”‚   โ”œโ”€โ”€ frames/            # CCTV surveillance frame images
โ”‚   โ””โ”€โ”€ sequences/         # Multi-frame sequences
โ”‚
โ””โ”€โ”€ tests/
    โ”œโ”€โ”€ test_env.py        # Environment unit tests
    โ”œโ”€โ”€ test_grader.py     # Grader unit tests
    โ””โ”€โ”€ test_api.py        # API integration tests

๐ŸŽฎ Action Space

ActionDescription
inspect_current_frameExamine the current camera frame
request_previous_frameNavigate to the previous frame in timeline
request_next_frameNavigate to the next frame in timeline
switch_cameraSwitch to a different camera feed
zoom_regionZoom into a specific region of the frame
classify_riskClassify threat level (safe/suspicious/dangerous/critical)
escalate_incidentTrigger emergency response
dismiss_alertDismiss as false alarm

๐Ÿ† Reward Engineering

Rewards are accumulated across the trajectory (delayed reward), making this significantly stronger than one-shot scoring.

SignalReward
โœ… Correct anomaly detection+0.20
โœ… Correct temporal reasoning+0.20
โœ… Correct escalation+0.30
โšก Fast response (within optimal steps)+0.10
โŒ False positive-0.20
โŒ Missed anomaly-0.40
โš ๏ธ Random action spam-0.10
โ˜ ๏ธ Unsafe dismissal-0.30

๐Ÿ“Š Task Difficulty Ladder

๐ŸŸข Easy โ€” Single Camera Anomaly

  • โ€”Detect suspicious objects
  • โ€”Identify count mismatches
  • โ€”2 tasks, 3โ€“8 steps

๐ŸŸก Medium โ€” Multi-Frame Progression

  • โ€”Identify when events begin (temporal reasoning)
  • โ€”Classify movement patterns
  • โ€”2 tasks, 5โ€“10 steps

๐Ÿ”ด Hard โ€” Multi-Camera Coordinated Incidents

  • โ€”Switch between camera feeds
  • โ€”Track subject paths across areas
  • โ€”Predict threat escalation
  • โ€”Decide emergency response
  • โ€”2 tasks, 7โ€“15 steps

๐Ÿš€ Quick Start

Prerequisites

  • โ€”Python 3.11+
  • โ€”Docker (for deployment)
  • โ€”Hugging Face API token

Installation

bash
# Clone the repository
git clone <repo-url>
cd sentinelops

# Create virtual environment
python -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install -r requirements.txt

Running the Server

bash
# Start the environment server
uvicorn server.app:app --host 0.0.0.0 --port 7860 --reload

Running Inference

bash
# Set environment variables
export API_BASE_URL=https://router.huggingface.co/v1
export MODEL_NAME=meta-llama/Llama-3.1-8B-Instruct:cheapest
export HF_TOKEN=hf_your_token_here
export ENV_URL=http://localhost:7860

# Run inference
python inference.py

Running Tests

bash
# Run all tests
pytest tests/ -v

# Run with coverage
pytest tests/ -v --tb=short

Docker

bash
# Build
docker build -t sentinelops .

# Run
docker run -p 7860:7860 sentinelops

# Validate
./validate-submission.sh http://localhost:7860

๐Ÿ”Œ API Endpoints

MethodEndpointDescription
POST/resetStart/restart an episode
POST/stepSubmit an agent action
GET/stateGet current episode state
GET/tasksList available tasks
POST/gradeGrade a completed episode
GET/healthLiveness probe
GET/docsInteractive API documentation

Example: Reset

bash
curl -X POST http://localhost:7860/reset \
  -H "Content-Type: application/json" \
  -d '{"task_id": "easy-001-parking-intrusion"}'

Example: Step

bash
curl -X POST http://localhost:7860/step \
  -H "Content-Type: application/json" \
  -d '{"action_type": "inspect_current_frame"}'

๐Ÿ“ Grading

Scoring is fully deterministic โ€” no LLM-as-judge. Each difficulty tier has its own rubric:

Easy Rubric (max 1.0)

  • โ€”Frame inspection: 0.15
  • โ€”Anomaly detection: 0.25
  • โ€”Risk classification: 0.30
  • โ€”Escalation decision: 0.30

Medium Rubric (max 1.0)

  • โ€”Frame inspection: 0.10
  • โ€”Temporal navigation: 0.20
  • โ€”Anomaly onset identification: 0.20
  • โ€”Risk classification: 0.25
  • โ€”Escalation decision: 0.25

Hard Rubric (max 1.0)

  • โ€”Camera coverage: 0.15
  • โ€”Target camera identification: 0.15
  • โ€”Cross-camera temporal reasoning: 0.15
  • โ€”Anomaly frame inspection: 0.10
  • โ€”False-positive avoidance: 0.10
  • โ€”Risk classification: 0.15
  • โ€”Escalation decision: 0.20

๐Ÿ“‹ Structured Log Format

The inference script emits mandatory structured logs to stdout per hackathon spec:

[START] {"task_id": "easy-001-parking-intrusion", "difficulty": "easy", "title": "Parking Lot Vehicle Break-In"}
[STEP] {"step": 1, "action": "inspect_current_frame", "payload": null, "reward": 0.15, "cumulative_reward": 0.15, "done": false}
[STEP] {"step": 2, "action": "request_next_frame", "payload": null, "reward": 0.2, "cumulative_reward": 0.35, "done": false}
[STEP] {"step": 3, "action": "classify_risk", "payload": "dangerous", "reward": 0.15, "cumulative_reward": 0.5, "done": false}
[STEP] {"step": 4, "action": "escalate_incident", "payload": null, "reward": 0.3, "cumulative_reward": 0.8, "done": true}
[END] {"task_id": "easy-001-parking-intrusion", "score": 1.0, "steps": 4, "status": "success"}

The evaluator parses these lines to verify scores. flush=True ensures immediate output with no buffering.


โœ… Quality Gate Checklist

  • โ€”[x] openenv validate passes
  • โ€”[x] docker build succeeds
  • โ€”[x] docker run starts correctly
  • โ€”[x] HF Space /reset returns HTTP 200
  • โ€”[x] [START]/[STEP]/[END] structured stdout logs emitted
  • โ€”[x] MODEL_NAME env var used as primary inference model
  • โ€”[x] API_BASE_URL + HF_TOKEN wired through OpenAI client
  • โ€”[x] Inference completes under 20 minutes (โ‰ค 1s sleep per step)
  • โ€”[x] Runs on vcpu=2, memory=8GB (lightweight FastAPI + HTTP calls only)
  • โ€”[x] Reproducible score variance < 2%
  • โ€”[x] 65/65 unit tests pass
  • โ€”[x] No placeholder functions or TODOs
  • โ€”[x] All endpoints runnable
  • โ€”[x] Deterministic grading (no LLM-as-judge)
  • โ€”[x] Perfect score (1.0) achievable on all 6 tasks

๐Ÿ“œ License

This project is licensed under the MIT License.


<div align="center">

Built for the Meta ร— Scaler OpenEnv Hackathon by Team Adaptrix

SentinelOps โ€” Where AI meets real-world security surveillance

</div>