Skip to content

GTR1998/autoguard-ai

Repository files navigation

AutoGuard AI

A comprehensive AI agent monitoring and safety system that tracks agent behaviors, assesses risks in real-time, and provides alerts when agents cross safety thresholds.

Features

  • Agent Registration: Register AI agents with unique API keys for monitoring
  • Behavior Logging: Track and log agent actions with risk scores
  • Risk Assessment: Real-time risk evaluation with multiple factors
  • Alert System: Automatic alerts when risk levels reach high/critical thresholds
  • Real-time Dashboard: Live monitoring with WebSocket updates
  • Data Visualization: Interactive charts for risk trends and behavior analysis
  • Settings Management: Configurable risk thresholds and notification preferences

Architecture

autoguard-ai/
├── apps/
│   ├── api/          # Express.js backend API
│   └── web/          # React frontend dashboard
└── packages/
    └── shared/       # Shared TypeScript types and utilities

Tech Stack

  • Backend: Node.js, Express, TypeScript, WebSocket (ws)
  • Frontend: React, TypeScript, TailwindCSS, Recharts
  • Build: pnpm workspaces, Vite

Getting Started

Prerequisites

  • Node.js 18+
  • pnpm 8+

Installation

# Clone the repository
git clone <repository-url>
cd autoguard-ai

# Install dependencies
pnpm install

# Build shared package
pnpm --filter @autoguard-ai/shared build

Development

# Start API server (from root)
pnpm --filter @autoguard-ai/api dev

# Start web dev server (in another terminal)
pnpm --filter @autoguard-ai/web dev

The API server runs on http://localhost:3000 and WebSocket on ws://localhost:3001.

The web app runs on http://localhost:5173.

Production Build

# Build all packages
pnpm build

# Or build individually
pnpm --filter @autoguard-ai/api build
pnpm --filter @autoguard-ai/web build

API Documentation

Authentication

Most endpoints require an API key in the X-API-Key header. Get your API key when registering an agent.

Endpoints

Agents

Method Endpoint Description
GET /api/agents List all agents
GET /api/agents/:id Get agent by ID
POST /api/agents Create new agent
PUT /api/agents/:id Update agent
DELETE /api/agents/:id Delete agent

Behavior Logs

Method Endpoint Description
POST /api/logs Submit behavior log (auth required)
GET /api/agents/:id/logs Get agent's behavior logs

Risk Assessment

Method Endpoint Description
GET /api/agents/:id/risk Get agent's risk assessment

Alerts

Method Endpoint Description
GET /api/alerts List all alerts
GET /api/alerts/recent Get recent alerts
GET /api/alerts/:id Get alert by ID
POST /api/alerts Create alert
POST /api/alerts/:id/acknowledge Acknowledge alert
POST /api/alerts/:id/resolve Resolve alert

Settings

Method Endpoint Description
GET /api/settings Get all settings
PUT /api/settings Update settings
GET /api/settings/thresholds Get risk thresholds
PUT /api/settings/thresholds Update thresholds

Example: Register an Agent

curl -X POST http://localhost:3000/api/agents \
  -H "Content-Type: application/json" \
  -d '{"name": "My Agent", "description": "A helpful AI assistant"}'

Response:

{
  "success": true,
  "data": {
    "id": "1234567890-abc123",
    "name": "My Agent",
    "description": "A helpful AI assistant",
    "apiKey": "ag-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "status": "active",
    "riskLevel": "low",
    "createdAt": "2024-01-01T00:00:00.000Z",
    "updatedAt": "2024-01-01T00:00:00.000Z"
  }
}

Example: Submit a Behavior Log

curl -X POST http://localhost:3000/api/logs \
  -H "Content-Type: application/json" \
  -H "X-API-Key: ag-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -d '{
    "agentId": "agent-id",
    "action": "data_access",
    "description": "Accessed user profile data",
    "riskScore": 25
  }'

Risk Levels

Level Score Range Description
Low 0-24 Normal, safe behavior
Medium 25-49 Minor concerns, monitor closely
High 50-74 Significant risk, review recommended
Critical 75-100 Severe risk, immediate action required

Risk Factors

The system evaluates risk based on multiple factors:

  1. Activity Frequency: Number of recent actions
  2. High-Risk Actions: Count of actions with high risk scores
  3. Behavior Consistency: Variance in behavior patterns
  4. Risk Trend: Direction of risk level changes

WebSocket Events

Connect to ws://localhost:3001 for real-time updates:

const ws = new WebSocket('ws://localhost:3001');

ws.onmessage = (event) => {
  const message = JSON.parse(event.data);
  console.log('Event:', message.type, message.payload);
};

Event Types

  • agent:created - New agent registered
  • agent:updated - Agent details changed
  • agent:deleted - Agent removed
  • behavior:logged - New behavior log submitted
  • risk:updated - Agent risk level changed
  • alert:created - New alert triggered
  • alert:acknowledged - Alert acknowledged
  • alert:resolved - Alert resolved

Configuration

Environment Variables

# API Server
PORT=3000

# WebSocket Server (runs on port + 1)
WS_PORT=3001

Settings

Access the Settings page in the dashboard to configure:

  • Risk Thresholds: Customize score boundaries for each risk level
  • Alert Rules: Enable/disable automatic alert triggers
  • Notifications: Configure email and webhook notifications

Project Structure

/apps/api

Express.js backend with:

  • RESTful API routes
  • WebSocket server for real-time updates
  • In-memory storage (can be extended to use databases)
  • Risk calculation algorithms

/apps/web

React frontend with:

  • Dashboard with real-time charts
  • Agent registration and management
  • Detailed agent view with risk assessment
  • Settings configuration
  • Responsive design with TailwindCSS

/packages/shared

Shared TypeScript types and utilities:

  • Type definitions for all data models
  • API request/response types
  • Risk calculation functions
  • ID and API key generation

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages