Back to MCP Servers

Aegis

Policy-based governance for AI agent tool calls. YAML policies, approval gates, risk assessment, and audit logging. Cross-platform: LangChain, OpenAI, Anthropic, MCP.

securitygoaiagent
By Acacian
154Updated 2 weeks agoPythonMIT

Installation

npx -y aegis

Configuration

{
  "mcpServers": {
    "aegis": {
      "command": "npx",
      "args": ["-y", "aegis"]
    }
  }
}

How to use

  1. Run the installation command above (if needed)
  2. Open your Claude Code settings file (~/.claude/settings.json)
  3. Add the configuration to the mcpServers section
  4. Restart Claude Code to apply changes
<!-- mcp-name: io.github.Acacian/aegis --> <p align="center"> <h1 align="center">Agent-Aegis</h1> <p align="center"> <strong>The governance layer for AI agents. One API, 12 frameworks, every governance primitive.</strong> </p> <p align="center"> Aegis is to agent governance what Redis is to data structures — one runtime that unifies prompt-injection blocking, PII masking, policy enforcement, trust delegation, and tamper-evident audit across every agent framework. No code changes.<br/> <code>pip install agent-aegis</code> → <code>aegis.auto_instrument()</code> → 12 frameworks are now governed. </p> </p> <p align="center"> <a href="https://www.bestpractices.dev/projects/12253"><img src="https://www.bestpractices.dev/projects/12253/badge" alt="OpenSSF Best Practices"></a> <a href="https://github.com/Acacian/aegis/actions/workflows/ci.yml"><img src="https://github.com/Acacian/aegis/actions/workflows/ci.yml/badge.svg" alt="CI"></a> <a href="https://pypi.org/project/agent-aegis/"><img src="https://img.shields.io/pypi/v/agent-aegis?color=blue&cacheSeconds=3600" alt="PyPI"></a> <a href="https://pypi.org/project/agent-aegis/"><img src="https://img.shields.io/pypi/pyversions/agent-aegis?cacheSeconds=3600" alt="Python"></a> <a href="https://github.com/Acacian/aegis/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License"></a> <br/> <a href="https://github.com/Acacian/aegis/actions/workflows/ci.yml"><img src="https://img.shields.io/badge/tests-6400%2B_passed-brightgreen" alt="Tests"></a> <a href="https://github.com/Acacian/aegis/actions/workflows/ci.yml"><img src="https://img.shields.io/badge/coverage-92%25-brightgreen" alt="Coverage"></a> <a href="https://acacian.github.io/aegis/playground/"><img src="https://img.shields.io/badge/playground-Try_it_Live-ff6b6b" alt="Playground"></a> </p> <p align="center"> <a href="#what-is-aegis"><strong>What is Aegis</strong></a> &bull; <a href="#primitives">Primitives</a> &bull; <a href="#frameworks">Frameworks</a> &bull; <a href="#use-cases">Use Cases</a> &bull; <a href="#30-second-start"><strong>30-Second Start</strong></a> &bull; <a href="#research">Research</a> &bull; <a href="https://acacian.github.io/aegis/">Docs</a> &bull; <a href="https://acacian.github.io/aegis/playground/"><strong>Playground</strong></a> </p> <p align="center"> <b>English</b> &bull; <a href="./README.ko.md">한국어</a> </p>
<p align="center"> <img src="docs/assets/demo.gif?v=2" alt="Aegis Demo" width="880"> </p>

What is Aegis

Every AI agent framework reinvents the same governance primitives — and each one does it slightly differently. Aegis is the abstraction layer that unifies them.

LayerWhat it doesExamples
1. PrimitivesA universal contract for every tool callAction, ActionClaim, Policy, Result, DelegationChain, AuditEvent
2. AdaptersAuto-instrument any framework through its own hooksLangChain callbacks, CrewAI BeforeToolCallHook, OpenAI Agents tracing, Google ADK BasePlugin, MCP transport, DSPy modules, httpx middleware, Playwright context
3. GovernanceDeclarative primitives you compose into policyPrompt injection / PII / leak / toxicity guardrails, RBAC, rate limit, cost budget, drift detection, anomaly scoring, trust delegation, justification gap, selection audit, Merkle audit chain
4. LifecycleOne runtime, every stage of agent opsScan → Instrument → Policy CI/CD → Runtime → Proxy → Audit
import aegis
aegis.auto_instrument()    # 12 frameworks governed. No other code changes.

You don't write a LangChain guardrail and a CrewAI guardrail and an OpenAI guardrail — you write one Policy and every framework inherits it.

How this differs from the guardrail libraries

They solve a different problem, and mostly a text-shaped one. Guardrails AI validates model output against a hub of validators; NeMo Guardrails scripts conversational and tool policy in the Colang DSL; Snyk Agent Scan — Invariant Labs' mcp-scan, since the Snyk acquisition — scans MCP servers and agent skills for known risk patterns and can proxy them at runtime; LLM Guard chained input/output scanners until it was archived in July 2026. Each one you wire in yourself, at a call site you choose. Aegis starts from the other end: auto_instrument() finds the frameworks already installed and instruments them in place, so one Policy covers all of them without a line of agent code changing. What it enforces is agent-shaped rather than prompt-shaped — delegation chains under a monotone trust constraint, audits of what an agent excluded rather than what it picked, the distance between an agent's declared intent and its measured impact, and a tamper-evident audit chain. All of it is deterministic, so there is no second model sitting in the request path. These are not exclusive choices: a semantic or model-based detector drops into GuardrailEngine.add() alongside the built-ins.


Primitives

The contract every adapter maps into. Framework-agnostic by design.

PrimitivePurposeModule
ActionUnified representation of any tool / LLM / HTTP / MCP call across all frameworksaegis.core.action
ActionClaimTripartite structure — Declared (agent-authored) / Assessed (Aegis-computed) / Chain (delegation)aegis.core.action_claim
PolicyDeclarative YAML rules: match → risk → approval (auto / approve / block)aegis.core.policy
ClaimPolicyPolicy layer that evaluates 6-dimensional impact vectors, not just tool namesaegis.core.claim_policy
GuardrailsDeterministic regex checks for injection, PII, prompt leak, toxicity — 2.65ms cold / <1µs warmaegis.guardrails
DelegationChainMulti-agent hand-off tracking with monotone trust constraint (non-increasing)aegis.core.agent_identity
AuditEventTamper-evident append-only log, Merkle-chained, SQLite + JSONL + webhook sinksaegis.core.merkle_audit
SelectionAuditAudits what an agent excludes, not just what it picks — detects cosmetic alignmentaegis.core.selection_audit
JustificationGap6D asymmetric scoring: agents declare impact, Aegis independently assesses, gap triggers escalationaegis.core.justification_gap
CryptoAuditChainEd25519-signed chain for long-term compliance evidenceaegis.core.crypto_audit

Every governance feature in Aegis — anomaly detection, cost budgets, drift, cascade guards, kill switches — is a composition of these primitives. Read the Concepts guide to see how they fit together.


Frameworks

One API. 12 agent frameworks + 3 protocol-level adapters.

FrameworkHookIntegration
Google ADKBasePlugin lifecycle (tool calls, agent routing, sessions)Native — the patch only installs the plugin
CrewAIglobal BeforeToolCallHook, Crew.kickoff/kickoff_asyncHybrid — native hook for tool calls, patch for crew entry
Pydantic AIAbstractCapability · Agent.run/run_syncNative (opt-in) · Patch (auto)
OpenAI Agents SDKtool_input_guardrail/tool_output_guardrail · Runner.run/run_syncNative (opt-in) · Patch (auto)
LangChainBaseChatModel.invoke/ainvoke, BaseTool.invoke/ainvokePatch
OpenAI APICompletions.create (chat & completions)Patch
Anthropic APIMessages.createPatch
LiteLLMcompletion, acompletionPatch
Google GenAIModels.generate_content (new + legacy)Patch
LlamaIndexLLM.chat/achat/complete/acomplete on every concrete subclass, BaseQueryEngine.query/aqueryPatch
InstructorInstructor.create, AsyncInstructor.createPatch
DSPyModule.__call__, LM.forward/aforwardPatch
MCPTransport-layer proxy for any MCP server (stdio / HTTP)Proxy — no patching
httpxHttpxExecutor for raw HTTP egress (REST agents, webhooks)Wrapper — no patching
PlaywrightPlaywrightExecutor for browsing agentsWrapper — no patching

auto_instrument() detects what's installed and patches only those — no hard dependencies. Custom adapters use the same BaseAdapter interface. Every adapter above is exercised against the current upstream release daily by the integration workflow, which drives each framework's real entrypoint and asserts a guardrail fires — the unit suite fakes these frameworks, so it cannot see upstream drift on its own.

Integration policy. Native extension points win wherever one exists that can actually block — Google ADK's BasePlugin and CrewAI's BeforeToolCallHook both do, and there auto_instrument() patches only enough to install the native object. Pydantic AI and the OpenAI Agents SDK ship native implementations you opt into (AbstractCapability, tool_input_guardrail) alongside a patch-based path for the zero-code case. Everything else is patched because no blocking hook exists: the raw OpenAI/Anthropic SDKs and DSPy expose none, and LlamaIndex's instrumentation dispatcher emits events but swallows handler exceptions, so it can observe and not enforce.

The Pydantic AI integration is the reason this policy is written down. It was monkey-patched until core maintainer DouweM reviewed it — "It doesn't look like those features are actually exposed as Pydantic AI capabilities?" — and was rebuilt on the native extension API in response (src/aegis/contrib/pydantic_ai.py; the review is pydantic-ai#4888).

Patching is the fallback, not the preference — it is the part most exposed to upstream change, which is why the integration workflow exists.

Default Guardrails

GuardrailDefaultWhat it catches
Prompt injectionBlock13 attack categories, 101 patterns, multi-language (EN/KO/ZH/JA)
PII detectionWarn13 categories (email, credit card, SSN, IBAN, API keys, etc.)
Prompt leakWarnSystem prompt extraction attempts
ToxicityWarnHarmful, violent, or abusive content
MCP STDIO injectionBlockJSON-RPC injection, frame concatenation, unicode escape bypass (OX Security advisory)

Deterministic regex — no LLM calls, no network. 2.65ms cold / <1µs warm per check.


Use Cases

The same primitives, five different entry points. Pick whichever matches your workflow.

1. Runtime protection (most common)

One line. Any framework.

import aegis
aegis.auto_instrument()

Or zero code changes — AEGIS_INSTRUMENT=1 python my_agent.py. Injection blocking, PII masking, prompt-leak warnings, audit trail, and policy enforcement become active for every LangChain / CrewAI / OpenAI / Anthropic / LiteLLM / ADK / DSPy / LlamaIndex / Pydantic AI call.

Pydantic AI native capability — no monkey-patching, explicit per-agent control:

from pydantic_ai import Agent
from aegis.contrib.pydantic_ai import AegisCapability

agent = Agent(
    "openai:gpt-4o-mini",
    capabilities=[AegisCapability.default()],  # injection, PII, toxicity, prompt-leak, hallucination
)
result = await agent.run("What is AI governance?")

[Full Pydantic AI integration guide →](https://acacian.github.io/aegis/cookbook/pydantic-ai-governance/

View source on GitHub