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.2.tar.gz (257.8 kB 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.2-py3-none-any.whl (145.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for agent_safeguards-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9ee5e5eb418976169f38fb0c475e42138b15e961a9f5775222eb62fc62f009cd
MD5 ab00788977dc86cf933c90d81da96716
BLAKE2b-256 4206222d6424e96af520487653dee29bb46ef2a12a097f253b8e996ec09d064c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agent_safeguards-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7fbed8ec06f77519f91b4e758d3b6d44c8c42a1a9b98189fce3909167ccf61bc
MD5 4e46c63f1ae3bec33c17c6372ff7738e
BLAKE2b-256 9eeb080b001da7d3cb060398edfc22bdf266d0b04ba88bc047f7974401a533cb

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