Skip to main content

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

megent-0.1.1.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

megent-0.1.1-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file megent-0.1.1.tar.gz.

File metadata

  • Download URL: megent-0.1.1.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

Hashes for megent-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c41fe73df6fa472e94a23c937deb72ec1ec8d2e4a73a51bef541a4415e10da75
MD5 b8dba97df9ed8f5bbae3a1d974a15353
BLAKE2b-256 fe17f391f6d02db3ba75a276cbc02f7403cc5a9db24a7d52ced92efe5c623869

See more details on using hashes here.

File details

Details for the file megent-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: megent-0.1.1-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

Hashes for megent-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 85bfed407508b366929021f1fe61394922b7dd341779909659898fd3fdd46563
MD5 ee70d194806f4fc538aa3d656253f0e3
BLAKE2b-256 7d7618e0ad6a6828c2397daa20ac84142ec20b010691448a1095aabdfdc778bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page