AI Agent Action Firewall core SDK
Project description
agsec
AI Agent Action Firewall - A minimal, control layer for agent actions.
Overview
agsec provides a simple yet powerful way to add safety controls to AI agents. It acts as a "firewall" between agents and real-world actions, allowing you to define policies that approve, block, or review actions before execution.
Why agsec?
- Agent-neutral: Works with any agent framework (LangChain, custom, etc.)
- Declarative policies: Define rules in YAML or code
- Extensible: Plugin system for custom actions and policies
- Production-ready: Lightweight, fast, and secure
Features
- ✅ Action Registry: Register and manage agent actions
- ✅ Policy Engine: Flexible rule-based decision making
- ✅ YAML Policies: Human-readable policy definitions
- ✅ Context Awareness: Rules can access parameters and context
- ✅ Priority & Matching: Advanced rule evaluation (priority, all/any matching)
- ✅ Audit Logging: Built-in logging for all decisions
- ✅ Python Package: Easy installation via PyPI
Installation
Runtime (for users)
pip install agsec
Development (for contributors)
git clone https://github.com/yourusername/agsec.git
cd agsec
pip install -e .[dev]
pre-commit install
Quick Start
Basic Usage
from agsec import ControlLayer
# Create control layer
control = ControlLayer()
# Register an action
@control.register_action("send_email")
def send_email(to, subject, body):
return {"sent_to": to, "status": "success"}
# Execute with default allow policy
result = control.execute("send_email", {"to": "user@example.com", "subject": "Hello", "body": "Hi!"})
print(result.result) # {"sent_to": "user@example.com", "status": "success"}
With YAML Policies
from agsec import ControlLayer
policy_yaml = """
rules:
- action: payment
status: block
reason: "High-value payment blocked"
conditions:
amount:
op: ">"
value: 10000
"""
control = ControlLayer(policy_yaml=policy_yaml)
@control.register_action("payment")
def payment(amount):
return {"charged": amount}
try:
control.execute("payment", {"amount": 15000})
except Exception as e:
print(e) # PolicyViolationError: High-value payment blocked
API Reference
ControlLayer
Main class for managing agent actions and policies.
ControlLayer(
policy_engine=None, # PolicyEngine instance
action_registry=None, # ActionRegistry instance
logger=None, # Custom logger
policy_yaml=None, # YAML policy string
policy_yaml_path=None # Path to YAML policy file
)
Methods
register_action(name): Decorator to register an action functionexecute(action, params, context=None): Execute an action with policy check
PolicyEngine
Handles policy evaluation.
Methods
add_rule(rule): Add a programmatic rule functionload_rules_from_yaml(yaml_text): Load rules from YAML stringload_rules_from_yaml_file(path): Load rules from YAML fileevaluate(action, params, context=None): Evaluate policy for action
Policy Status
PolicyStatus.ALLOW: Allow action executionPolicyStatus.BLOCK: Block action executionPolicyStatus.REVIEW: Mark for manual review
YAML Policy Schema
rules:
- action: "action_name" # Action to match (* for all)
status: "allow|block|review" # Decision
reason: "Optional reason" # Human-readable explanation
priority: 0 # Higher = evaluated first
match: "all|any" # Condition matching mode
conditions: # Parameter/context checks
param_name:
op: "==|!=|>|<|>=|<=|in|not_in"
value: "expected_value"
context.user_role:
op: "=="
value: "admin"
Development
Setup
pip install -e .[dev]
pre-commit install
Testing
pytest
Building
python -m build
Releasing
./release.sh # Requires PYPI_API_TOKEN env var
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Run
pre-commit run --all-files - Submit a pull request
Code Style
- Black for formatting
- isort for import sorting
- flake8 for linting
- pytest for testing
License
MIT License - see LICENSE file for details.
Roadmap
- Web dashboard for policy management
- Advanced risk scoring
- Multi-agent coordination
- Enterprise integrations
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agsec-0.1.0.tar.gz.
File metadata
- Download URL: agsec-0.1.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33a32d317c2f058b1240b1c5072b34e3d777d17237686f859086b053a75ff443
|
|
| MD5 |
3c13f818f5c6c10ddfc8004cfed2741e
|
|
| BLAKE2b-256 |
f1cc186e8fd2d55ce5c1d44769a7a5a15577b3c8a5bae63d85521b6aecb6f0d2
|
File details
Details for the file agsec-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agsec-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6b43d8c2362dbef385aae9315415d2e06ba5f7d288465c957d2deed70713ee8
|
|
| MD5 |
6eb730b40921ad663dab9c1f0596324d
|
|
| BLAKE2b-256 |
77a7c7ca2097ad9c07b7518ea9bdaf184b958193d7e9d102ceaeed3e32885489
|