Aegis
Policy enforcement and observability for AI agent tool calls.
Aegis is a Python SDK and dashboard platform that provides infrastructure-level policy enforcement for AI agent tool calls. It wraps tool functions, evaluates each call against YAML-based policies, and produces a structured audit record for every action — allowed, denied, or escalated for human approval.
Features
- Infrastructure-enforced controls — enforcement happens at the tool-call layer, not the prompt layer.
- Configurable policies — YAML-based rules with 8 condition operators.
- Real-time observability — web dashboard for monitoring, alerts, and audit trails.
- Framework-agnostic — works with any Python function, LangChain, MCP, or raw OpenAI function calling.
- Human-in-the-loop escalation — high-risk actions pause for human approval.
- High performance — batched async ingestion with TimescaleDB time-series storage.
Repository Layout
aegis-core/
├── aegis/ # Python SDK
│ ├── audit/ # Audit records, schema, writer
│ ├── core/ # Policy engine, loader, wrapper, escalation
│ ├── integrations/ # LangChain and MCP adapters
│ ├── obs/ # Observability events
│ └── sinks/ # File, webhook, and dashboard sinks
├── tests/ # SDK test suite
├── examples/ # Runnable usage examples
│ └── policies/ # Example policy files used by the examples
├── aegis-dashboard/ # Full-stack observability dashboard
│ ├── backend/ # FastAPI + SQLAlchemy + TimescaleDB
│ └── frontend/ # Next.js + React + Tailwind
└── docs/ # Guides and reference
├── RUNNING_LOCALLY.md # Local setup for SDK + dashboard
├── QUICKSTART.md # Quick SDK + dashboard walkthrough
├── SDK_GUIDE.md # Full SDK developer reference
├── RELEASING.md # Release process
└── internal/ # Internal notes and specs
Documentation
- Running Locally — get the SDK and dashboard running on your machine.
- Quickstart — a fast walkthrough of the SDK and dashboard.
- SDK Developer Guide — complete API reference, patterns, and integrations.
- Contributing — how to set up a dev environment and submit changes.
- Releasing — how releases are cut and published.
Installation
SDK only (from PyPI):
pip install aegis-core-sdk
For local development, clone this repository and use pip install -e ".[dev]".
Full platform (SDK + dashboard): see Running Locally.
Quick Start
1. Create a policy
policy.yaml:
version: 1
rules:
- tool: "send_email"
escalate: always
- tool: "read_file"
allow:
- path: { regex: "^/safe/.*" }
- tool: "delete_file"
deny: always
defaults:
unmatched_tool: deny
unmatched_param: deny # non-matching read_file paths are denied by this default
2. Wrap your tools
import aegis
def send_email(to: str, subject: str, body: str):
return f"Email sent to {to}"
def read_file(path: str):
with open(path) as f:
return f.read()
def delete_file(path: str):
import os
os.remove(path)
return f"Deleted {path}"
wrapped_send, wrapped_read, wrapped_delete = aegis.wrap(
tools=[send_email, read_file, delete_file],
policy="policy.yaml",
agent_id="my-agent",
on_deny="raise",
)
wrapped_read(path="/safe/file.txt") # Allowed
wrapped_send(to="user@example.com", subject="Hi", body="Hello") # Escalates
wrapped_delete(path="/important.txt") # Denied
Prefer a dict of {name: function} (e.g. for OpenAI-style function calling)? Use
aegis.wrap_function_map() instead — see Raw OpenAI function calling below.
3. View in the dashboard
Send audit records to the dashboard for monitoring:
import requests
def send_to_dashboard(event):
requests.post(
"http://localhost:8000/api/v1/ingest/audit",
headers={"X-API-Key": "your_api_key"},
json=event.to_dict(),
)
The dashboard provides real-time tool-call monitoring, a policy editor with YAML validation, a filterable audit trail, escalation management, and a WebSocket live feed.
Policy Language
Condition operators
| Operator | Meaning | Example |
|---|---|---|
eq / neq |
Equality | status: { eq: draft } |
lt / lte |
Less than | amount: { lte: 500 } |
gt / gte |
Greater than | amount: { gt: 100 } |
in / not_in |
List membership | domain: { in: [acme.com] } |
regex |
Regex match | path: { regex: ^/tmp/ } |
always |
Unconditional | allow: always |
Evaluation order
- Check if the tool is in the policy (apply
defaults.unmatched_toolif not). - Evaluate
denyconditions (first match blocks immediately). - Evaluate
escalateconditions (first match pauses for human approval). - Evaluate
allowconditions (first match permits execution). - If no allow matches, apply
defaults.unmatched_param.
Framework Integrations
LangChain
from langchain.tools import Tool
import aegis
raw_tools = [
Tool(name='issue_refund', func=issue_refund, description='...'),
Tool(name='update_crm', func=update_crm, description='...'),
]
tools = aegis.wrap_langchain_tools(
tools=raw_tools,
policy='./policies/acme-corp.yaml',
agent_id='billing-agent',
customer_id='acme-corp',
)
MCP server
from mcp.server import Server
import aegis
server = Server('billing-agent')
@server.call_tool()
@aegis.mcp_enforce(
policy=lambda ctx: aegis.load_customer_policy(ctx.customer_id),
agent_id='billing-agent',
)
async def handle_tool_call(name: str, arguments: dict):
if name == 'issue_refund':
return await issue_refund(**arguments)
Raw OpenAI function calling
import aegis
function_map = {
'issue_refund': issue_refund,
'update_crm': update_crm,
}
wrapped = aegis.wrap_function_map(
function_map,
policy='./policies/acme-corp.yaml',
agent_id='billing-agent',
customer_id='acme-corp',
)
result = wrapped[tool_call.function.name](**arguments)
Audit Trail
Every tool call produces a structured audit record:
{
"record_id": "uuid-v4",
"timestamp": "2024-11-15T14:32:01.234Z",
"customer_id": "acme-corp",
"agent_id": "billing-agent",
"tool_name": "issue_refund",
"params": {"order_id": "ord_789", "amount_usd": 340.00},
"outcome": "allow",
"matched_rule": "issue_refund.allow[0]",
"reason": "Amount within limit",
"execution_result": {"refund_id": "ref_456"},
"latency_ms": 4
}
Audit sinks
from aegis.sinks import FileSink, WebhookSink
file_sink = FileSink(path='./audit/agent.jsonl', rotate='daily')
webhook_sink = WebhookSink(
url='https://ingest.acme.com/aegis',
headers={'Authorization': 'Bearer TOKEN'},
async_mode=True,
)
tools = aegis.wrap(
tools=raw_tools,
policy=policy,
agent_id='agent',
audit_sink=[file_sink, webhook_sink],
)
Escalation Flow
When a tool call matches an escalate condition, Aegis:
- Writes an audit record with
outcome: "escalate". - Fires a webhook notification to the configured URL.
- Blocks execution (default) or continues (
on_escalate="notify_and_proceed"). - Waits for a human to approve or deny via the resolution API.
- Updates the audit record with the resolution details.
tools = aegis.wrap(
tools=raw_tools,
policy=policy,
agent_id='billing-agent',
escalation_webhook='https://hooks.acme.com/escalations',
escalation_timeout_minutes=30,
on_escalate='block', # or 'notify_and_proceed'
)
Error Handling
on_deny behaviors
| Setting | Behavior | When to use |
|---|---|---|
raise (default) |
Raises AegisViolationError |
Production — fails loudly |
return_error |
Returns "AEGIS_DENIED: <reason>" |
Agent should adapt and retry |
silent |
Returns None |
Debugging only |
Development
# Install with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run with coverage
pytest --cov=aegis --cov-report=html
# Format and lint
black aegis tests
ruff check aegis tests
# Type check
mypy aegis
See CONTRIBUTING.md for the full contributor workflow and docs/RUNNING_LOCALLY.md for running the dashboard.
Examples
See examples/ for complete working examples:
basic_usage.py— simple policy enforcement.multi_tenant.py— per-customer policies.langchain_example.py— LangChain integration.dashboard_integration.py— sending audit records to the dashboard.
Contributing
Contributions are welcome. Please read CONTRIBUTING.md before opening an issue or pull request.
Metadata
Release files for aegis-core-sdk 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aegis_core_sdk-0.1.0.tar.gz | 30.5 kB | With provenance | Details for aegis_core_sdk-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aegis_core_sdk-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for aegis_core_sdk-0.1.0-py3-none-any.whl |
Total release size: 63.7 kB
Release files / aegis_core_sdk-0.1.0.tar.gz
| Download URL | aegis_core_sdk-0.1.0.tar.gz |
|---|---|
| Size | 30.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ca63c029cd015d8ae5d11bd2ef92d5a17d8a91e41efd726919f74c37643c18fa
|
|
BLAKE2b-256 checksum How to use checksums |
739b2a06c9555070040c6009f583c0ae7b53bfab6bbff0dbcd2944e01e993058
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logRelease files / aegis_core_sdk-0.1.0-py3-none-any.whl
| Download URL | aegis_core_sdk-0.1.0-py3-none-any.whl |
|---|---|
| Size | 33.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4825798bdbb8edc7f1eeef51a59f0344b01e7449e672eaaf8eab787652e92984
|
|
BLAKE2b-256 checksum How to use checksums |
a5e1c5cc0cb37e40b3586ef8a2f5de0d65184fdae8b765e56ac73b388591b1ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logSecurity for aegis-core-sdk 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for aegis_core_sdk-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.