Metadata-Version: 2.4
Name: agent-safeguards
Version: 0.1.2
Summary: Safeguards for custom agents.
Project-URL: Homepage, https://github.com/cirbuk/agent-safeguards
Project-URL: Documentation, https://github.com/cirbuk/agent-safeguards/tree/main/docs
Project-URL: Issues, https://github.com/cirbuk/agent-safeguards/issues
Project-URL: Changelog, https://github.com/cirbuk/agent-safeguards/blob/main/CHANGELOG.md
Author-email: "Dev Team @mason" <dev@getmason.io>
License: MIT License
        
        Copyright (c) 2024 Agent Safety Framework
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Requires-Dist: aiohttp>=3.8.0
Requires-Dist: asyncio>=3.4.3
Requires-Dist: fastapi>=0.109.0
Requires-Dist: jinja2>=3.1.0
Requires-Dist: numpy>=1.24.0
Requires-Dist: pandas>=2.0.0
Requires-Dist: plotly>=5.13.0
Requires-Dist: prometheus-client>=0.17.0
Requires-Dist: psutil>=5.9.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: python-dateutil>=2.8.0
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: pyyaml>=6.0.0
Requires-Dist: requests>=2.30.0
Requires-Dist: scikit-learn>=1.3.0
Requires-Dist: scipy>=1.10.0
Requires-Dist: tenacity>=8.2.0
Requires-Dist: typing-extensions>=4.0.0
Requires-Dist: uvicorn>=0.27.0
Requires-Dist: websockets>=10.4
Provides-Extra: dev
Requires-Dist: bandit>=1.7.0; extra == 'dev'
Requires-Dist: black>=23.0.0; extra == 'dev'
Requires-Dist: isort>=5.12.0; extra == 'dev'
Requires-Dist: mypy>=1.7.0; extra == 'dev'
Requires-Dist: pre-commit>=2.15.0; extra == 'dev'
Requires-Dist: pylint>=3.0.0; extra == 'dev'
Requires-Dist: setuptools>=65.5.1; extra == 'dev'
Requires-Dist: types-psutil>=5.9.0; extra == 'dev'
Requires-Dist: types-requests>=2.30.0; extra == 'dev'
Provides-Extra: docs
Requires-Dist: sphinx-autodoc-typehints>=1.23.0; extra == 'docs'
Requires-Dist: sphinx-rtd-theme>=1.2.0; extra == 'docs'
Requires-Dist: sphinx>=6.0.0; extra == 'docs'
Provides-Extra: test
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'test'
Requires-Dist: pytest-cov>=4.1.0; extra == 'test'
Requires-Dist: pytest>=7.0.0; extra == 'test'
Description-Content-Type: text/markdown

# Safeguards

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

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![Security: Bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/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

```bash
pip install agent-safeguards
```

### Basic Setup

```python
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

```python
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](docs/quickstart.md).

## Documentation

- [Core Concepts](docs/concepts.md) - Essential concepts and terminology
- [Installation Guide](docs/installation.md) - Detailed installation instructions
- [Quick Start Guide](docs/quickstart.md) - Get started with the framework
- [Component Status](COMPONENT_STATUS.md) - Current status of framework components
- [Budget Management](docs/guides/budget_management.md) - How to manage agent budgets
- [Safety Policies](docs/guides/safety_policies.md) - Implementing and enforcing safety policies
- [Safeguards](docs/guides/safeguards.md) - Safety features and guardrails
- [Monitoring](docs/guides/monitoring.md) - Metrics, visualization, and alerts
- [Agent Coordination](docs/guides/agent_coordination.md) - Multi-agent coordination
- [API Reference](docs/api/core.md) - Detailed API documentation
- [Architecture Overview](docs/development/architecture.md) - System design

For a complete documentation index, see the [Documentation README](docs/README.md).

## 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

```bash
# 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

```bash
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:
```bash
black .
isort .
```

Run type checking:
```bash
mypy src/
```

Run linters:
```bash
flake8 src/
pylint src/
```

## Contributing

Contributions are welcome! Please see our [Contributing Guide](CONTRIBUTING.md) 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](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
