Skip to main content

Privacy-aware memory isolation for AI agents

Project description

MemGate

Privacy-Aware Memory Isolation Layer for AI Agents

Website CI PyPI

🛡️ Current Version: 0.4.0 (Provider Architecture)

📖 Documentation & Website →

MemGate acts as a firewall between your AI agent's long-term memory and its output channels. It ensures that private information (like calendar events, financial data, or family details) is never leaked into public contexts (like group chats), even if the LLM attempts to generate it.

Features

  • Context-Aware Privacy: Automatically distinguishes between Private (DM) and Public (Group) contexts.
  • Provider Architecture: Pluggable platform adapters (Lark/Feishu built-in, extensible to Telegram, Discord, Slack).
  • Paranoid Check: Detects hidden/invisible members by cross-referencing member count vs. member list — prevents privacy leaks from incomplete API data.
  • Pattern-Based Filtering: Regex-based interception for high-risk categories (Phone, Email, Finance, Calendar).
  • Semantic Detection: Embedding-based privacy detection (n-gram, OpenAI, or local models) catches rephrased leaks.
  • Knowledge Store: JSONL-based store with public/private tagging and always-private category enforcement.
  • Red Team Arena: Built-in adversarial testing with 8 attack strategies.
  • Strict Privacy Protocol: CI/CD pipeline with CodeRabbit review ensuring no privacy regressions.

Installation

pip install memgate

Or from source:

git clone https://github.com/carlnoah6/memgate.git
cd memgate
pip install -e .

Usage

CLI

# Check a message for privacy violations
memgate review \
  --message "My phone number is 13800138000" \
  --channel-type group \
  --participants "alice,bob"

Provider API (Platform-Specific Privacy Detection)

from memgate.providers.lark import LarkProvider

# Initialize with credentials
provider = LarkProvider(
    app_id="your_app_id",
    app_secret="your_app_secret",
    admin_open_id="ou_admin_user_id",
)

# Check if a chat is safe for private data
context = provider.fetch_context("oc_chat_id_here")
if provider.is_safe(context):
    print("Private chat — safe to share memory")
else:
    print(f"Unsafe: {context.reason}")
    if context.unsafe_reason:
        print(f"Integrity issue: {context.unsafe_reason}")

Privacy Review API

from memgate.privacy_review import PrivacyReviewer
from memgate.knowledge_store import KnowledgeStore

store = KnowledgeStore("path/to/knowledge")
reviewer = PrivacyReviewer(store=store)

result = reviewer.review(
    "Check out my salary: $50k",
    channel_id="group_chat_1",
    participants={"alice", "bob"},
)

if not result.passed:
    print(f"BLOCKED: {result.violations}")

Custom Provider

from memgate.providers.base import BaseProvider, ProviderContext

class TelegramProvider(BaseProvider):
    def fetch_context(self, chat_id: str) -> ProviderContext:
        # Your Telegram API logic here
        ...

    def is_safe(self, context: ProviderContext) -> bool:
        return context.is_private and context.unsafe_reason is None

Development

Running Tests

MemGate uses pytest for its test suite, including the "Red Team" mock scenarios.

pip install pytest
pytest

Pre-commit Hooks

Ensure code quality and security (prevent API key leaks) before committing:

pip install pre-commit
pre-commit install

License

MIT

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

memgate-0.4.2.tar.gz (50.1 kB view details)

Uploaded Source

Built Distribution

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

memgate-0.4.2-py3-none-any.whl (60.9 kB view details)

Uploaded Python 3

File details

Details for the file memgate-0.4.2.tar.gz.

File metadata

  • Download URL: memgate-0.4.2.tar.gz
  • Upload date:
  • Size: 50.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for memgate-0.4.2.tar.gz
Algorithm Hash digest
SHA256 53e08da03446160de6c476f7354489c083dfc3f6fa7ccb8c549f9ba92f765208
MD5 1ee665718680ddf2533c07c7960be921
BLAKE2b-256 563bf8e7fc1fd4bbaf4c99a74982d488ca61ab6488045f9f6a53eadae6c423be

See more details on using hashes here.

File details

Details for the file memgate-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: memgate-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 60.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for memgate-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6789ae0b116afbd163cb72c987911eb821030ebccd0ea07977f098f63c239a26
MD5 d53f21ffc5865b464d80932b2f4623e1
BLAKE2b-256 58cea01a7f18bf94c11513497e54ebdf0aeb01ae0a12ad7ad76387c77ba8e48a

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