Skip to main content

Safeguards for custom agents.

Project description

Safeguards

A comprehensive framework for implementing safety measures in multi-agent systems, focusing on budget coordination, monitoring, and guardrails.

License: MIT Python 3.10+ Security: Bandit

Overview

The Safeguards framework provides tools and infrastructure for ensuring safe and controlled operation of AI agent systems. It addresses key challenges in multi-agent environments:

  • Resource management and budget enforcement
  • Agent coordination and priority-based allocation
  • Safety monitoring and violation detection
  • Health assessment and alerting
  • Dynamic resource adjustment based on operational needs

This framework is ideal for organizations deploying multiple AI agents that need to:

  • Ensure predictable resource usage
  • Prioritize critical operations
  • Prevent runaway resource consumption
  • Implement safe failure modes
  • Monitor agent health and behavior

Features

  • Budget Coordination System

    • Direct transfer functionality between agents
    • Dynamic pool selection and priority-based allocation
    • Automatic pool scaling and load balancing
    • Emergency allocation handling
    • Priority levels (1-10) for agents and operations
  • Advanced Metrics Analysis

    • Resource trend analysis
    • Usage pattern detection
    • Budget efficiency tracking
    • Anomaly detection
    • Health monitoring and recommendations
  • Safety Rules System

    • Customizable rule definitions
    • Priority-based execution
    • Rule chain dependencies
    • Context-aware evaluation
    • Violation detection and reporting
  • API Contracts

    • Versioned API interfaces
    • Budget management
    • Metrics tracking
    • Agent coordination
    • Configuration management

Quick Start

Installation

pip install agent-safeguards

Basic Setup

from decimal import Decimal
from safeguards.core.budget_coordination import BudgetCoordinator
from safeguards.core.notification_manager import NotificationManager
from safeguards.api import APIFactory, APIVersion
from safeguards.types.agent import Agent

# Create core components
notification_manager = NotificationManager()
budget_coordinator = BudgetCoordinator(notification_manager)
api_factory = APIFactory()

# Create APIs
budget_api = api_factory.create_budget_api(APIVersion.V1, budget_coordinator)
agent_api = api_factory.create_agent_api(APIVersion.V1, budget_coordinator)

# Create a budget pool
pool = budget_api.create_budget_pool(
    name="main_pool",
    initial_budget=Decimal("100.0"),
    priority=5
)

# Create an agent
agent = agent_api.create_agent(
    name="example_agent",
    initial_budget=Decimal("10.0"),
    priority=3
)

# Check agent budget
budget = budget_api.get_budget(agent.id)
print(f"Agent {agent.name} has budget: {budget}")

Creating a Custom Agent

from decimal import Decimal
from typing import Dict, Any
from safeguards.types.agent import Agent

class MyAgent(Agent):
    def __init__(self, name: str, cost_per_action: Decimal = Decimal("0.1")):
        super().__init__(name)
        self.cost_per_action = cost_per_action
        self.action_count = 0

    def run(self, **kwargs: Any) -> Dict[str, Any]:
        """Execute agent logic with cost tracking."""
        self.action_count += 1
        # Your agent implementation here
        return {
            "result": "Task completed",
            "action_count": self.action_count,
            "cost": self.cost_per_action,
        }

# Create and register agent
my_agent = MyAgent("custom_agent")
registered_agent = agent_api.create_agent(
    name=my_agent.name,
    initial_budget=Decimal("20.0"),
    priority=5
)

# Run agent and update budget
for _ in range(3):
    result = my_agent.run(input="Example task")
    current_budget = budget_api.get_budget(registered_agent.id)
    budget_api.update_budget(
        registered_agent.id,
        current_budget - result["cost"]
    )

For more detailed examples, see the Quick Start Guide.

Documentation

For a complete documentation index, see the Documentation README.

Use Cases

The Safeguards framework is designed for a variety of use cases:

  • Enterprise AI Systems: Manage resource allocation across multiple AI services
  • Autonomous Systems: Ensure safety constraints in autonomous operations
  • Research Environments: Control experiment resource usage and monitor behavior
  • Agent Orchestration: Coordinate multiple specialized agents working together
  • LLM Application Deployment: Manage token budgets and processing resources

Development

Prerequisites

  • Python 3.10 or higher
  • pip package manager

Setting Up Development Environment

# Clone the repository
git clone https://github.com/cirbuk/agent-safeguards.git
cd agent-safeguards

# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install development dependencies
pip install -r requirements-dev.txt

# Install package in development mode
pip install -e .

Running Tests

pytest tests/

Code Style

The project uses:

  • Black for code formatting
  • isort for import sorting
  • mypy for type checking
  • flake8 and pylint for linting

Run formatters:

black .
isort .

Run type checking:

mypy src/

Run linters:

flake8 src/
pylint src/

Contributing

Contributions are welcome! Please see our Contributing Guide for details on how to contribute to the project.

Security

This framework implements several security measures:

  • Pre-commit hooks for security scanning
  • Automated security checks in CI/CD
  • Regular dependency updates
  • Code analysis tools

If you discover a security vulnerability, please report it to dev@getmason.io.

License

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

Support

For support, please open an issue on the GitHub repository or contact the Mason team at dev@getmason.io

Acknowledgments

  • Contributors and maintainers
  • Security research community
  • Open source projects that inspired this framework

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agent_safeguards-0.1.3.tar.gz (10.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agent_safeguards-0.1.3-py3-none-any.whl (140.1 kB view details)

Uploaded Python 3

File details

Details for the file agent_safeguards-0.1.3.tar.gz.

File metadata

  • Download URL: agent_safeguards-0.1.3.tar.gz
  • Upload date:
  • Size: 10.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.24

File hashes

Hashes for agent_safeguards-0.1.3.tar.gz
Algorithm Hash digest
SHA256 056872f43a00e34068a6acfbaf093f2e89d8158d45c4c76cb0e937de4fa0e24f
MD5 4cdfadaa2845d3412719c8ae81a3b6f5
BLAKE2b-256 5b6d9ab7c295ffd95c49332161768f61f017b095e04c4442ed60620ed7c37270

See more details on using hashes here.

File details

Details for the file agent_safeguards-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for agent_safeguards-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 99d860246303a28e352e9c6eee28c46b0848ee55f9041b3a690e6049b4f19753
MD5 5a9ffc5914362b3b914c5b7ac4e197ed
BLAKE2b-256 03574cb2091d6f216b3d4ff6aedbc799f805e18181634a7e0336c151ab17fb82

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page