AgentPass Python SDK for identity and access management
Project description
AgentPass Python SDK
Enterprise-Grade Identity & Access Management for AI Agents
Secure your AI agents with JWT authentication, RBAC/ABAC policies, risk assessment, and comprehensive audit logging.
๐ Documentation | ๐ Quick Start | ๐ฌ Discussions | ๐ Issue Tracker
What is AgentPass?
AgentPass is a Python SDK designed specifically for securing AI agent applications. It provides a unified security layer with:
- JWT-based Authentication - Secure token issuance and validation
- Fine-grained Authorization - RBAC and ABAC policy engines
- Real-time Risk Assessment - Anomaly and fraud detection
- Comprehensive Audit Logging - Complete visibility into agent activities
- FastAPI Integration - Drop-in middleware for web applications
- YAML Policy Management - Human-readable security policies
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Your AI Application โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ Agent A โ โ Agent B โ โ Agent C โ โ
โ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โ
โ โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโผโโโโโโโโโ โ
โ โ AgentPass โ โ
โ โ SDK โ โ
โ โโโโโโโโโโโโโโโโโโโค โ
โ โ Auth (JWT) โ โ
โ โ Policy (RBAC) โ โ
โ โ Risk Engine โ โ
โ โ Audit Logger โ โ
โ โโโโโโโโโโฌโโโโโโโโโ โ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโผโโโโโโโโโโ
โ Protected โ
โ Resources โ
โโโโโโโโโโโโโโโโโโโโโโ
Why AgentPass?
As AI agents become more prevalent, security becomes critical:
| Challenge | AgentPass Solution |
|---|---|
| Token theft & spoofing | JWT with signature verification |
| Unauthorized resource access | RBAC + ABAC policy engine |
| Malicious prompt injection | Risk assessment with anomaly detection |
| Compliance & audit requirements | Complete audit trail with export |
| Complex permission management | YAML-based policy definitions |
Quick Start
Installation
pip install agentpass
For FastAPI integration:
pip install "agentpass[fastapi]"
Minimal Example
from agentpass import Guard
# Initialize Guard with your secret
guard = Guard(secret="your-secure-secret-key")
# Issue a token for an agent
token = guard.issue_token("agent_001", role="admin")
# Check permissions
result = guard.check(
token=token,
action="read_doc",
resource="internal_doc"
)
print(result)
# {
# "allowed": True,
# "reason": "Access granted",
# "risk_level": "low",
# "risk_score": 0.0,
# "agent_id": "agent_001",
# "role": "admin"
# }
Advanced Usage with Policies
from agentpass import Guard, Policy, PolicyRule, Priority
guard = Guard(secret="your-secure-secret-key")
# Add custom policy
guard.add_policy(Policy(
id="secure_zone",
name="Secure Zone Policy",
priority_strategy=Priority.DENY_OVERRIDE,
rules=[
PolicyRule(
resource="sensitive/*",
action="*",
effect="deny",
priority=100,
conditions={"role": {"require": ["admin"]}}
),
PolicyRule(
resource="sensitive/*",
action="read",
effect="allow",
priority=50,
conditions={
"ip": {"allow": "private"},
"time": {"hours": "9-18"}
}
)
]
))
# Risk-aware access decision
decision = guard.assess_and_protect(
user_id="agent_001",
resource="sensitive/data",
action="read",
context={"ip_address": "192.168.1.100"}
)
print(f"Decision: {decision['decision']}") # allow or block
print(f"Risk Level: {decision['risk_assessment']['risk_level']}")
Core Features
๐ JWT Authentication
- Secure token generation with configurable expiration
- Token validation with automatic refresh support
- Support for custom claims and metadata
๐ก๏ธ Policy Engine (RBAC/ABAC)
- Priority-based rule evaluation
- Multiple condition types: IP, time, role, resource tags
- YAML import/export for policy management
- Explainable decision paths
# Priority-based evaluation
policy = Policy(
id="access_control",
priority_strategy=Priority.DENY_OVERRIDE,
rules=[
PolicyRule(resource="admin:*", action="*", effect="allow", priority=100),
PolicyRule(resource="doc:*", action="read", effect="allow", priority=50),
PolicyRule(resource="*", action="*", effect="deny", priority=0),
]
)
๐ฏ Risk Engine
- Pluggable detector architecture
- Anomaly detection
- Fraud detection
- Configurable risk thresholds
๐ Audit Logging
- Structured event logging
- JSON/CSV export
- Integration with existing databases
from agentpass import Audit, AuditEvent
audit = Audit(storage_backend=None)
audit.log_event(AuditEvent(
event_type="access_attempt",
user_id="agent_001",
resource="doc:confidential",
action="read",
status="deny"
))
# Export audit trail
json_output = audit.export_to_json()
csv_output = audit.export_to_csv()
FastAPI Integration
from fastapi import FastAPI
from agentpass import GuardMiddleware
app = FastAPI()
app.add_middleware(
GuardMiddleware,
secret="your-secret",
exclude_paths=["/health", "/login"]
)
@app.get("/profile")
async def get_profile(request: Request):
# request.state.user contains the authenticated agent info
user = request.state.user
return {"agent_id": user["sub"], "role": user["role"]}
Project Structure
agentpass-sdk/
โโโ pyproject.toml # Package configuration
โโโ README.md # This file
โโโ LICENSE # MIT License
โโโ src/
โ โโโ agentpass/ # SDK source code
โ โโโ __init__.py # Package exports
โ โโโ auth.py # JWT authentication
โ โโโ policy.py # Policy engine
โ โโโ audit.py # Audit logging
โ โโโ detector.py # Risk detectors
โ โโโ risk.py # Risk assessment
โ โโโ guard.py # Unified facade
โ โโโ integrations/ # Framework integrations
โ โโโ fastapi.py # FastAPI middleware
โโโ tests/
โ โโโ test_demo.py # Basic demo tests
โ โโโ test_sdk_verification.py # SDK verification
โ โโโ test_api_verification.py # API tests
โ โโโ test_permissions_audit.py # Permission tests
โโโ examples/
โโโ app.py # FastAPI demo application
Testing
Run the complete test suite:
cd agentpass-sdk
python tests/test_sdk_verification.py
Test results: 24/24 passing (100%)
============================================================
Test Results: 24/24 Passing (100.0%)
============================================================
[1. SDK Installation Verification]
[PASS] from agentpass import Guard
[PASS] Version check
[PASS] Policy module import
[PASS] Audit module import
[PASS] Risk module import
[PASS] FastAPI integration import
[PASS] Dependency check
[2. Guard API Verification]
[PASS] Guard initialization
[PASS] Token issuance
[PASS] Token verification
[PASS] Permission check - allow
[PASS] Permission check - deny
[PASS] assess_and_protect
[3. Policy Module Verification]
[PASS] Policy creation
[PASS] DENY_OVERRIDE strategy
[PASS] ALLOW_OVERRIDE strategy
[PASS] IP condition matching
[PASS] Role condition matching
[PASS] explain() method
[PASS] YAML export
[PASS] YAML import
[4. Audit Module Verification]
[PASS] Audit initialization
[PASS] Event recording
[PASS] Event query
Roadmap
v0.1.0 (Current)
- JWT authentication
- RBAC policy engine
- Basic audit logging
- Simple risk assessment
- FastAPI middleware
- YAML policy support
v0.2.0 (Planned)
- ABAC attribute-based access control
- Pluggable detector plugins
- Advanced risk scoring algorithms
- Persistent audit storage backends
- Prompt injection detection
v1.0.0 (Future)
- Production stability guarantee
- Complete API documentation
- Enterprise security audit
- Official plugin ecosystem
- Long-term support commitment
Integration with Existing Systems
AgentPass is designed for gradual adoption. The SDK can be integrated alongside existing security infrastructure:
# Existing system continues to work
from app.adapters import get_adapter
# AgentPass provides additional security layer
agentpass = get_adapter(settings.JWT_SECRET)
# Existing policy remains primary decision maker
# AgentPass provides risk assessment and audit
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
This project is licensed under the MIT License.
ยฉ 2026 AgentPass Team
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
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 agentpass_identity-0.1.0.tar.gz.
File metadata
- Download URL: agentpass_identity-0.1.0.tar.gz
- Upload date:
- Size: 23.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62af86249c2499424b70a22a49e2a25987385883fe8c2ed2886f5f89aa36f798
|
|
| MD5 |
7f859629ba97edd5847880a9ba5511b0
|
|
| BLAKE2b-256 |
a07ca0cd5cd5e9feb8d5b68380e524d5c6e701cc5d13c9dc9adb943a3c04952f
|
File details
Details for the file agentpass_identity-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agentpass_identity-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c24818702dbb4f948ec8fb1580ea0ea36e5139abec03236a8663d49bf6a51a6b
|
|
| MD5 |
af2ff333bbf448d3ee491dd380aeef96
|
|
| BLAKE2b-256 |
cf5ba42f4c6258b24c522eb70f86035aa13d208614f92636c63cf60246ca02ce
|