AI Sentinel consists of two independent modules:
- Gateway (security gateway): intercepts malicious traffic between user input and high-risk agent actions
- Analyst (intelligence analyst): multi-alert security analysis, causal decision trees, emergent behavior detection
The two modules work together to form a complete security loop: "detect → report → analyze → block".
Click HERE to see our demo video
- System Architecture
- Quick Start — One-Click Launch
- Gateway Security Gateway
- Analyst Intelligence Platform
- CMS Agent Demo
- Configuration (Environment Variables)
- API Reference
- Integration Tests
- Project Structure
┌──────────────────────────┐
User Input ──────▶ │ AI Sentinel Gateway │
│ (FastAPI :3001) │
│ ├─ /chat input guard │
│ ├─ /confirm-action │
│ ├─ /scan skill scan │
│ ├─ /v1/chat/completions │
│ ├─ /bans IP bans │
│ ├─ /rules rule mgmt │
│ └─ /policy policy cfg │
└──────────┬───────────────┘
│ SecurityEvent JSON
▼
┌──────────────────────────┐
│ Splunk HEC / sim store │
│ (:8088 or :8000) │
└──────────┬───────────────┘
│ query events
▼
┌──────────────────────────┐
│ AI Sentinel Analyst │
│ (Flask :5000) │
│ ├─ SecurityAgent │
│ ├─ Splunk Query MCP │
│ ├─ Rule Engine MCP │
│ ├─ Gateway Control MCP │
│ ├─ Decision Tree Engine │
│ └─ Web UI Dashboard │
└──────────┬───────────────┘
│ block command
▼
┌──────────────────────────┐
│ Gateway /bans API │
│ (ban IP / target) │
└──────────────────────────┘
Data flow: Gateway detects malicious input → reports SecurityEvent → Splunk stores it → Analyst pulls events → rule matching → auto/manual block → generates decision-tree report
cd d:\Programs\AI_Sentinel
pip install -r requirements.txtMain dependencies: fastapi uvicorn httpx flask mcp pyyaml pydantic (Presidio and splunk-sdk are optional).
# PowerShell — start Gateway + Analyst UI + CMS Agent (web mode)
.\start_all.ps1
# Or start individually:
.\start_all.ps1 -Gateway # start only the Gateway :3001
.\start_all.ps1 -Analyst # start only the Analyst UI :5000
.\start_all.ps1 -CmsAgent # start only the CMS Agent :6001
.\start_all.ps1 -Web # CMS Agent web mode:: CMD — double-click to run
start_all.batTerminal 1 — Gateway (port 3001):
python -m gateway.mainTerminal 2 — Analyst UI (port 5000):
python -m analyst.ui.appCopy .env.example to .env and fill in real values:
cp .env.example .envKey variables (simulated data is used by default, so it runs without Splunk):
SPLUNK_HEC_URL/SPLUNK_HEC_TOKEN— Gateway reports events to SplunkSPLUNK_HOST/SPLUNK_PORT— Analyst queries events from SplunkSPLUNK_USE_REAL=false— set totrueto connect to real Splunk
# Gateway health check
curl http://localhost:3001/health
# → {"status":"ok","detector_count":5}
# Analyst stats
curl http://localhost:5000/api/stats
# → {"mode":"observe","total_alerts":...,"total_events":...}
# Analyst command center UI
# Open http://localhost:5000 in a browserA FastAPI-based security gateway, deployed "in front of" agent / LLM applications.
Core capabilities:
- Pluggable detectors (auto-scans
gateway/middlewares/) - Block on hit (403 + hit details)
- Hard block on high-risk keywords (delete / drop / rm -rf, etc.)
- Structured JSON logging + async Splunk HEC reporting
- Automatic IP bans (sliding-window threshold exceeded)
- OpenAI-compatible proxy (
/v1/chat/completions) - Rule management API (
/rules), policy API (/policy)
Built-in detectors:
| Module | Capability |
|---|---|
rule_engine.py |
Data-driven multi-engine (regex/sensitive/keyword/entropy) |
injection.py |
Prompt injection/jailbreak (10 major categories) |
prompt_injection.py |
Injection/jailbreak (keyword regex, incl. Chinese) |
sensitive.py |
Sensitive information (regex + Presidio) |
pii_leak.py |
PII (Presidio preferred) |
command_exec.py |
Command execution detection |
entropy.py |
High-entropy obfuscation detection |
API entry points: POST /chat, POST /confirm-action, POST /scan, POST /v1/chat/completions, GET/POST /bans, GET/POST /rules, GET/PUT /policy
A Flask-based Web UI + SecurityAgent providing multi-alert security analysis.
Core capabilities:
- Dual mode: AUTO (automatic blocking) / OBSERVE (manual confirmation)
- NL command parsing (natural-language queries/actions/rule configuration)
- 3 MCP servers (Splunk Query / Gateway Control / Rule Engine)
- Causal decision-tree construction and visualization
- Emergent behavior detection (collusion / privilege escalation / reasoning errors, etc.)
- Disposition record tracking (auto block / admin confirmation)
API endpoints:
| Method | Path | Description |
|---|---|---|
| GET | / |
Command center dashboard |
| GET | /api/stats |
Stats overview |
| GET | /api/alerts |
Alert list |
| POST | /api/query |
NL query/command |
| POST | /api/block/:id |
Confirm block (OBSERVE) |
| GET/POST | /api/mode |
Mode switch |
| GET | /api/rules |
Rule list |
| GET | /api/dispositions |
Disposition records |
cms_agent/ contains a lightweight CRM Agent and its security-guard wrapper:
| File | Purpose |
|---|---|
crm_agent.py |
Original CRM Agent (SQLite data, natural-language interaction) |
crm_secure.py |
Security-guard wrapper (monkey-patches into the Gateway) |
start_secure_crm.bat |
CMD launch script |
start_secure_crm.ps1 |
One-click PowerShell launch (includes the Gateway) |
Usage:
cd cms_agent
# Original CRM (does not go through the security gateway)
python crm_agent.py
# Secure CRM (goes through Gateway detection)
python crm_secure.py # command-line mode
python crm_secure.py web 6001 # web mode (http://127.0.0.1:6001)Guard policy:
- Input guard: only intercepts "prompt injection/jailbreak" types (PII/sensitive types are allowed through, since CRM legitimately enters such fields)
- Action guard: delete operations are reported with the neutral action name
remove_recordto avoid English hard-block keywords
See .env.example for the full configuration. Key variables:
| Variable | Default | Description |
|---|---|---|
GATEWAY_ID |
gateway-01 |
Gateway instance identifier |
LLM_PROVIDER |
anthropic |
Downstream LLM provider |
SPLUNK_HEC_URL |
- | Splunk HEC endpoint |
SPLUNK_HEC_TOKEN |
- | Splunk HEC token |
| Variable | Default | Description |
|---|---|---|
SPLUNK_HOST |
splunk.example.com |
Splunk search host |
SPLUNK_PORT |
8089 |
Splunk management port |
SPLUNK_USE_REAL |
false |
Connect to real Splunk |
GATEWAY_HOST |
gateway.example.com |
Gateway host |
GATEWAY_PORT |
8443 |
Gateway port |
RULES_PATH |
- | Path to rules.yaml |
See the original README §3-4 for details. Core endpoints:
POST /chat— user input detection (200 allow / 403 block)POST /confirm-action— high-risk action confirmation (allowedfield)POST /scan— skill content scan (returns multiple findings)GET /health— health checkGET/POST /bans— IP ban managementGET/POST /rules— rule CRUDGET/PUT /policy— policy configuration
| Method | Path | Description |
|---|---|---|
| GET | /api/stats |
Stats overview |
| GET | /api/alerts |
Alert list |
| GET | /api/alerts/<id> |
Alert detail |
| POST | /api/query |
NL query |
| POST | /api/block/<id> |
Confirm block |
| GET/POST | /api/mode |
Mode query/switch |
| GET | /api/rules |
Rule list |
| POST | /api/rules/search |
Rule search |
| GET | /api/dispositions |
Disposition records |
| GET | /api/mcp/status |
MCP status |
# Full test (start the Gateway first)
python tests/integration_test.py
# Quick test (no subprocess; Gateway already running)
python tests/integration_test.py --quickTest coverage:
- Gateway detection logic (injection / normal / high-risk command / masking)
- Data format alignment (Gateway → Analyst)
- Rule Engine rule matching
- Causal decision-tree construction
- MCP Bridge three-server connection
- Full Agent cycle (event → rule → block → record)
- CSV data pipeline
- rules.yaml validation
AI_Sentinel/
├── gateway/ # Module A: security gateway
│ ├── main.py # FastAPI entry, routes, detector loading
│ ├── mcp_sender.py # Splunk HEC async sender + reliable delivery pipeline
│ ├── disposition.py # IP ban/policy management (SQLite)
│ ├── llm_proxy.py # OpenAI-compatible proxy
│ ├── preprocess.py # Input preprocessor (de-obfuscation)
│ ├── rule_store.py # Rule store (SQLite + version history)
│ ├── rules_api.py # Rule management REST API
│ └── middlewares/ # Pluggable detectors (auto-registered)
├── analyst/ # Module B: intelligence analysis platform
│ ├── agent.py # SecurityAgent (dual mode, NL commands)
│ ├── config.py # Unified config (env vars > defaults)
│ ├── mcp_client.py # MCP Bridge (subprocess stdio connection)
│ ├── models.py # Data models (Span/CausalNode/GatewayEvent/...)
│ ├── rule_engine.py # Rule engine (matches events to rules)
│ ├── causal_analyzer.py # Causal decision-tree construction and analysis
│ ├── nl_engine.py # NL intent classification / command parsing / rule search
│ ├── report_engine.py # Report generation (Mermaid.js + emergence detection)
│ ├── servers/ # MCP servers (run as subprocesses)
│ │ ├── splunk_mcp.py # Splunk query (real/simulated)
│ │ ├── gateway_mcp.py # Gateway control (real API / simulated)
│ │ └── rule_mcp.py # Rule engine (YAML hot-reload)
│ └── ui/ # Web UI
│ ├── app.py # Flask app (API + dashboard)
│ └── templates/dashboard.html
├── cms_agent/ # Demo: CRM Agent + security guard
│ ├── crm_agent.py # Original CRM Agent
│ ├── crm_secure.py # Security-guard wrapper
│ └── start_secure_crm.ps1 # One-click launch script
├── data/ # Gateway event CSV data
├── tests/ # Integration tests
│ └── integration_test.py
├── legacy/ # Old files (deprecated)
├── rules.yaml # Shared rules file
├── .env.example # Environment variable template
├── requirements.txt # Unified dependencies
├── start_all.ps1 # One-click launch script
├── start_all.bat # CMD one-click launch
├── README.md # This file
└── CLAUDE.md # Claude Code instructions
Quick lookup of key entry points:
| If you want to… | Look here |
|---|---|
| Change Gateway routes/responses | gateway/main.py |
| Change the high-risk keyword list | gateway/main.py HIGH_RISK_KEYWORDS |
| Add/change detection rules | gateway/middlewares/ |
| Change Analyst mode logic | analyst/agent.py |
| Change natural-language parsing | analyst/nl_engine.py |
| Change MCP tool definitions | analyst/servers/ |
| Change the dashboard UI | analyst/ui/templates/dashboard.html |
| Change shared rules | rules.yaml |