Skip to content

A framework for building safe autonomous AI systems demonstrated through Reference implementations

License

Notifications You must be signed in to change notification settings

saiakhil2012/safe-autonomous-agents

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Safe Autonomous Agents

License Python NeMo Docker

Intelligent Smart Home System with Multi-layer Guardrails

A modular autonomous agent system for smart home devices (EV Charger, Dishwasher, Thermostat) demonstrating multiple layered guardrails for safe, secure, and ethical AI operation.

๐Ÿ“Œ Overview

This project demonstrates how to build AI systems with robust guardrails that enforce safety constraints, energy conservation policies, and ethical behaviors. The system showcases three different guardrail technologies integrated into a unified architecture:

  • NVIDIA NeMo Guardrails: Colang-based declarative safety flows (EV Charger)
  • Guardrails.AI: XML-based validation guardrails (Dishwasher)
  • Rule-Based Guardrails: Custom Python validation logic (Thermostat)

All three technologies are orchestrated by a central control agent, with input moderation through Microsoft Presidio (PII detection) and Detoxify (toxicity detection).

๐Ÿ—๏ธ Architecture

System Architecture

The system follows a microservices architecture with the following components:

  • Control Agent: Central orchestrator with LangGraph workflow and rule-based guardrails
  • Device Agents: Individual agents for each smart home device with specific guardrails
  • Moderation Service: Content filtering and PII detection
  • UI Dashboard: Interactive visualization of device status and guardrail enforcement

Guardrail Layers

  1. Input Layer: Content moderation, PII detection, input validation
  2. System Layer: Power limits, energy conservation policies
  3. Device Layer: Device-specific time restrictions and safety rules

๐Ÿš€ Quick Start

Option 1: Docker Compose (Recommended)

# Clone the repository
git clone https://github.com/saiakhil2012/safe-autonomous-agents.git
cd safe-autonomous-agents

# Set up environment
cp .env.example .env

# Start LM Studio or other LLM server on default port
# Then run the system
docker-compose up -d

# Access the dashboard
open http://localhost:8501

Option 2: Development Setup

# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
pip install --upgrade pip
pip install -r requirements.txt

# Launch components using helper script
./scripts/utils/dev-start.sh

๐ŸŽฎ Demo Scenarios

Try these scenarios to demonstrate the different guardrail layers:

1. Energy Conservation Policy

  • Set simulated time to 18:00 (peak hours)
  • Request: "Charge my EV now"
  • Result: Blocked by energy conservation policy (time restriction)

2. Privacy Protection

  • Request: "My insurance ID 1234567890 covers smart home installation"
  • Result: Blocked by HIPAA compliance policy (PII detection)

3. System Power Limits

  • Set simulated time to 21:00 (evening)
  • Request: "Turn on EV charger, dishwasher and thermostat all at once"
  • Result: Blocked by system power overload protection (10.0 kW > 8.0 kW limit)

4. Content Moderation

  • Request: "[inappropriate content]"
  • Result: Blocked by content safety policy

๐Ÿ’ป Technology Stack

  • Core Framework: Python 3.8+
  • UI: Streamlit
  • API Layer: FastAPI
  • Messaging: Kafka (KRaft mode)
  • Containerization: Docker & Docker Compose
  • Guardrails:
    • NeMo Guardrails (NVIDIA)
    • Guardrails.AI
    • Custom Rule-Based Logic
  • Moderation:
    • Microsoft Presidio (PII detection)
    • Detoxify (toxicity detection)
  • LLM Orchestration: LangChain, LangGraph

๐Ÿ” Project Structure

safe-autonomous-agents/
โ”œโ”€โ”€ agents/                  # Smart home device agents
โ”‚   โ”œโ”€โ”€ control/             # Control agent with LangGraph workflow
โ”‚   โ”œโ”€โ”€ dishwasher/          # Dishwasher agent with Guardrails.AI
โ”‚   โ”œโ”€โ”€ ev_charger/          # EV charger agent with NeMo Guardrails
โ”‚   โ””โ”€โ”€ thermostat/          # Thermostat agent with rule-based guardrails
โ”œโ”€โ”€ cli/                     # CLI demo tools
โ”œโ”€โ”€ docs/                    # Documentation files
โ”‚   โ””โ”€โ”€ architecture-diagram.png # System architecture diagram
โ”œโ”€โ”€ guardrails/              # Shared guardrail policies
โ”œโ”€โ”€ moderation/              # Content moderation service
โ”œโ”€โ”€ scripts/                 # Utility scripts
โ”œโ”€โ”€ shared/                  # Shared utilities and base classes
โ”œโ”€โ”€ ui/                      # Streamlit dashboard
โ”œโ”€โ”€ docker-compose.yml       # Docker configuration
โ””โ”€โ”€ .env.example             # Environment variables template

๐Ÿ› ๏ธ Customization

Modifying Guardrail Policies

  1. Time-Based Policies: Update the time restrictions in the UI

    • EV Charging only after 9 PM (21:00)
    • Dishwasher only after 8 PM (20:00)
  2. Power Limits: Modify system-wide power limit (default 8.0 kW)

  3. Content Safety: Add custom detection patterns in moderation/service.py

  4. Device-Specific Rules: Each device agent has its own guardrails folder

๐Ÿšจ Advanced Features

CLI Demo

For a more lightweight demo without Docker:

python -m cli.main

Demo features:

  • Type requests like Save me money tonight or Run all devices now
  • Type policy: ev_start_hour=1 to update guardrails in real time
  • See a color-coded timeline and guardrail explanations

Automated Demo Script

To quickly demonstrate all the guardrail features:

./scripts/demo/demo.sh

This will run through several key scenarios showing different guardrail types in action.

Environment Variables

The system uses these environment variables (defined in .env):

  • LM_STUDIO_API_BASE - Base URL for LM Studio API (default: http://host.docker.internal:1234/v1)
  • LM_STUDIO_API_KEY - API key for LM Studio (can be "dummy" for local usage)
  • DISABLE_KAFKA - Set to "true" to disable Kafka messaging (for simpler demos)

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ”ฎ Future Work

This project serves as a foundation for advanced autonomous agent systems with robust safety guarantees. Planned enhancements include:

  1. Real-time System Guardrails: Leverage Kafka for streaming real-time device telemetry to enable dynamic and adaptive guardrails that respond to changing system conditions.

  2. RAG-based Agent Enhancement: Implement Retrieval-Augmented Generation for one of the agents to provide more contextual awareness and policy-based decision making using domain-specific knowledge.

  3. LangGraph LLM Integration: Replace simulated nodes in the LangGraph workflow with actual LLM calls to enable more sophisticated reasoning and decision-making capabilities.

  4. Additional Domain Reference Architectures: Expand beyond smart homes to demonstrate the framework's versatility with reference implementations for other domains such as healthcare, industrial automation, and enterprise systems.

  5. End-to-End Safe Autonomous Agents: Create complete domain-specific autonomous agent implementations with comprehensive safety guarantees across different sectors.

๐ŸŽค Talks & Presentations

๐Ÿ™ Acknowledgements

For a detailed view of the system architecture, including diagrams and security model, see ARCHITECTURE.md.

About

A framework for building safe autonomous AI systems demonstrated through Reference implementations

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published