AI agent security middleware — policy-enforced tool call interception
Project description
Megent
Policy-based security middleware for AI agents.
Megent sits between your orchestration layer and your AI agents, intercepting every tool call before it executes — enforcing rules, masking sensitive data, and logging everything.
Agent → [tool call] → Megent policy engine → [allow / deny / redact] → Tool
Why Megent
AI agents execute tool calls autonomously. Without a control layer, a single compromised prompt can exfiltrate data, delete records, or call APIs it was never supposed to touch.
Megent gives you deny-by-default security for agent tool calls — without rewriting your agents.
Features
- Deny-by-default — nothing executes unless explicitly allowed by policy
- YAML policy language — define rules in plain text, version them in git
- JWT agent identity — every agent has a passport; every action is authorized against it
- PII masking — redact sensitive data before it reaches tools or logs
- Structured audit logs — full trace of every tool call, decision, and outcome
- Zero agent rewrite — wrap existing agents in one line
Quickstart
pip install megent
Decorate your agent
import megent as mgnt
@mgnt.guard(policy="policies/agent.yaml") def my_agent(task: str): # your existing agent code ...
Or wrap a third-party agent
secured_agent = mgnt.wrap(agent, policy="policies/agent.yaml") result = secured_agent.run("summarize the sales report")
Define a policy
policies/agent.yaml
version: 1 agent: sales-assistant
rules:
-
tool: read_file allow: true conditions: path_prefix: "/reports/"
-
tool: send_email allow: true conditions: recipient_domain: "@company.com"
-
tool: delete_record allow: false
-
tool: "*" allow: false # deny-by-default
How It Works
┌─────────────────────────────────────────────┐ │ Orchestration Layer │ │ (LangChain / CrewAI / etc.) │ └────────────────────┬────────────────────────┘ │ tool call ▼ ┌─────────────────────────────────────────────┐ │ Megent Policy Engine │ │ • Verify agent identity (JWT) │ │ • Evaluate policy rules │ │ • Mask PII │ │ • Emit audit log │ └────────────────────┬────────────────────────┘ │ allow / deny ▼ ┌─────────────────────────────────────────────┐ │ Tool Layer │ │ (APIs, databases, file system) │ └─────────────────────────────────────────────┘
Agent Identity
Each agent is issued a passport — a signed JWT that defines its identity and permitted scope. Megent validates this on every tool call.
passport = mgnt.issue_passport( agent_id="sales-assistant-v1", scopes=["read_file", "send_email"], expires_in="1h" ) Agents without a valid passport are blocked before any tool executes.
Audit Logs
Every tool call produces a structured log entry:
{
"timestamp": "2026-03-31T10:22:01Z",
"agent_id": "sales-assistant-v1",
"tool": "read_file",
"decision": "allow",
"args": { "path": "/reports/q1.pdf" },
"policy": "policies/agent.yaml",
"rule_matched": "read_file/path_prefix"
}``
---
## Contributing
Contributions are welcome. Please open an issue before submitting large PRs.
git clone https://github.com/getmagent/megent
cd megent
pip install -e ".[dev]"
pytest
---
## License
<!-- [3/30/2026 11:19 PM] miki: -->
Apache 2.0 — see [LICENSE](./LICENSE).
---
<p align="center">
<a href="https://megent.dev">megent.dev</a> ·
<a href="https://twitter.com/megents">@megents</a>
</p>
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 megent-0.1.2.tar.gz.
File metadata
- Download URL: megent-0.1.2.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53dab1986f91e3306baddee28ce31b00115def0984bd0131b0ef4f50cfd7c343
|
|
| MD5 |
ae4919e39fa1a1b5f1df7f923642afc4
|
|
| BLAKE2b-256 |
03dd7b82d82abe3fa56cc0c45427e8b7f734b6c06955897a49dee4a38ada36c0
|
File details
Details for the file megent-0.1.2-py3-none-any.whl.
File metadata
- Download URL: megent-0.1.2-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8774cdfc8bf5b64b1ed317145580a1c0c4174bfb1b9af56dcfb914921291c6d3
|
|
| MD5 |
eb493ec4ac6a29ae31c245b9dca4ba21
|
|
| BLAKE2b-256 |
4ed019c9edfcd7929139d694c366d1b8582953fe770cd9b46c364f7ce4d85ec7
|