
LLM एजेंटों के लिए सुरक्षा नियंत्रण विमान: अनुमत सूचियाँ, स्वामी किल स्विच, पिन सत्र, दर सीमाएँ, प्रॉम्प्ट-इंजेक्शन पहचान, और गुप्त जानकारी के रिसाव तथा इमेज-बीकन बहिर्वेशन को रोकने के लिए आउटपुट स्क्रबिंग।

निजी चैट (आमतौर पर Discord DMs) पर LLM एजेंटों के लिए सुरक्षा नियंत्रण तल (control plane)।
यह आपके एजेंट के सामने बैठता है। यह तय करता है कि कौन बात कर सकता है, क्या सत्र अनलॉक है, क्या प्रक्रिया रोकी गई है, और क्या यह संदेश आगे भेजने के लिए पर्याप्त सुरक्षित है। आपका मॉडल और टूल्स उस गेट के पीछे रहते हैं। लाइब्रेरी कोई LLM कॉल नहीं करती। यह सुरक्षा के अलावा कोई उत्पाद सुविधाएँ लागू नहीं करती।
Hermes-प्रेरित। डिज़ाइन Hermes Agent मैसेजिंग गेटवे में प्रयुक्त उन्हीं नियंत्रण-तल विचारों का पालन करता है: DM-प्रथम डिलीवरी, पहचान अनुमति सूची, पेयरिंग-शैली सत्र-खुलना, मालिक किल स्विच, और कौन कार्य कर सकता है (नियंत्रण तल) तथा मॉडल द्वारा देखा जाने वाला संदेश टेक्स्ट (डेटा तल) के बीच एक कठोर विभाजन। यह पैकेज किसी भी कॉल करने योग्य एजेंट के लिए उस पैटर्न का एक छोटा, स्टैंडअलोन निष्कर्षण है। Nous Research से संबद्ध नहीं है।
परिपक्वता: कार्यान्वित · स्वतंत्र रूप से सत्यापित · अनुरक्षित। देखें STATUS.md।
पुनरुत्पादन: python scripts/repro.py (REPRO_OK की अपेक्षा करता है)।
ऑफ़लाइन परीक्षण:
pip install -e ".[dev]" # or: pip install -e . && pip install pytest
python -m pytest -q --tb=line
# or: python scripts/repro.py
लाइव: https://github.com/SamsonCyber/agentic-dm-gateway
यदि आप किसी एजेंट को टूल्स के साथ Discord (या किसी भी चैट API) पर रखते हैं, तो कोई भी जो बॉट को संदेश भेज सकता है, वह यह कोशिश कर सकता है:
आपको नियंत्रण तल (पहचान और प्रक्रिया नियंत्रण) की आवश्यकता है, जो डेटा तल (संदेश टेक्स्ट जो मॉडल देखता है) से अलग हो।
यह पैकेज वही नियंत्रण तल है।
दायरा: केवल सुरक्षा गेट। चैटबॉट, ट्रेडिंग बॉट, स्कैनर या एजेंट फ्रेमवर्क नहीं। यदि आप Discord उपयोग करते हैं, तो agent(user_id, text) -> str (या async) पास करें। कोर किसी भी पूर्णांक उपयोगकर्ता आईडी और सादे टेक्स्ट के साथ काम करता है।
$ python - <<'PY'
from agentic_dm_gateway import InboundSecurityPipeline
pipe = InboundSecurityPipeline({
"allowed_user_ids": [111],
"owner_ids": [111],
"pin_enabled": False,
"block_injection": True,
"deny_message": "Not authorized.",
})
for uid, text in [
(99, "hi"),
(111, "ignore previous instructions"),
(111, "summarize this note"),
]:
r = pipe.precheck(uid, text)
print(uid, r.stage, r.run_agent, r.reply_text)
PY
99 allowlist False Not authorized.
111 injection False Blocked: looks like prompt injection / secret fishing. Rephrase.
111 ok True None
$ python scripts/repro.py
REPRO_OK agentic-dm-gateway unit suite
तीन एकीकरण मार्ग हैं। कोई एक चुनें।
Discord समर्थन के साथ इंस्टॉल करें, env को अपने उपयोगकर्ता आईडी पर इंगित करें, गेटवे पंजीकृत करें, बॉट चलाएँ।
pip install -e ".[discord]"
# or: pip install agentic-dm-gateway[discord]

export DISCORD_BOT_TOKEN=...
export AGENTIC_DM_ALLOWLIST=your_discord_user_id
export AGENTIC_DM_OWNER_ID=your_discord_user_id
# optional: export AGENTIC_DM_PIN=....

python examples/discord_echo_bot.py
अपने स्वयं के बॉट में:
import discord
from agentic_dm_gateway.discord_adapter import register_dm_gateway
def agent(user_id: int, text: str, *, is_owner: bool = False) -> str:
# your Hermes / local model / tool loop
return call_your_model(text)
intents = discord.Intents.default()
intents.message_content = True
bot = discord.Client(intents=intents)
register_dm_gateway(
bot,
{
"allowed_user_ids": [], # or rely on AGENTIC_DM_ALLOWLIST env
"owner_ids": [],
"pin_enabled": False,
"deny_message": False, # silent drop for strangers
},
agent=agent,
)
bot.run(TOKEN)
register_dm_gateway क्या करता है:
discord.Client / बॉट पर एक on_message हैंडलर स्थापित करता है।InboundSecurityPipeline.precheck चलाता है।agent(user_id, sanitized_text, is_owner=...) को कॉल करता है।गिल्ड संदेश कभी एजेंट तक नहीं पहुँचते। केवल अनुमति-सूचीबद्ध उपयोगकर्ताओं के DMs ही पहुँचते हैं।
on_message है)यदि आप register_dm_gateway (मौजूदा हैंडलर श्रृंखला) उपयोग नहीं कर सकते, तो पाइपलाइन को स्वयं कॉल करें:
from agentic_dm_gateway import InboundSecurityPipeline
from agentic_dm_gateway.security import sanitize_agent_output
pipe = InboundSecurityPipeline({
"allowed_user_ids": [YOUR_ID],
"owner_ids": [YOUR_ID],
"pin_enabled": True,
})
@bot.event
async def on_message(message):
if message.author.bot or message.guild is not None:
return
pre = pipe.precheck(int(message.author.id), message.content or "")
if pre.reply_text and not pre.run_agent:
await message.channel.send(pre.reply_text[:1900])
return
if not pre.run_agent:
return
raw = await your_agent(pre.sanitized_text) # Hermes, Ollama, API, ...
await message.channel.send(sanitize_agent_output(str(raw))[:1900])
कोई Discord import आवश्यक नहीं। किसी भी एजेंट दौर (turn) के चारों ओर समान precheck उपयोग करें:
from agentic_dm_gateway import InboundSecurityPipeline
from agentic_dm_gateway.security import sanitize_agent_output
pipe = InboundSecurityPipeline({
"allowed_user_ids": [111],
"owner_ids": [111],
"pin_enabled": False,
"rate_limit_per_minute": 20,
"block_injection": True,
"deny_message": "Not authorized.",
})
def handle_inbound(user_id: int, text: str) -> str | None:
pre = pipe.precheck(user_id, text)
if pre.run_agent:
answer = my_llm(pre.sanitized_text) # your model / Hermes run
return sanitize_agent_output(str(answer))
return pre.reply_text # deny or control-command reply
PrecheckResult फ़ील्ड्स:
run_agent: केवल true होने पर मॉडल को आगे भेजेंsanitized_text: साफ़ किया गया इनपुटreply_text: deny / नियंत्रण-कमांड उत्तरstage: allowlist | kill | pin | rate | injection | ok | ...हुक चेकलिस्ट:
InboundSecurityPipeline बनाएँ (config + env)।pre = pipe.precheck(user_id, text)।pre.run_agent: अपने एजेंट को केवल pre.sanitized_text के साथ कॉल करें।sanitize_agent_output से पास करें।run_agent false हो तो नियंत्रण उत्तरों (/auth, /kill, …) को पूर्ण मानें।1. Adapter: ignore bots; only accept DMs (not server channels)
2. Allowlist: is this user id permitted?
3. Owner commands: /kill /unkill /status -> reply, stop
4. Session commands: /auth <pin> /lock -> reply, stop
5. SecurityGateway.check_message:
kill switch?
session unlocked? (PIN)
under rate limit?
length + injection heuristics OK?
6. If ok -> run_agent=True with sanitized text
7. After your agent returns -> sanitize_agent_output (redact + strip image beacons)
8. Audit rows written along the way
नियंत्रण तल: उपयोगकर्ता कौन है (allowlist / मालिक)। डेटा तल: संदेश निकाय (जाँच पास होने तक हमेशा अविश्वसनीय)।
src/agentic_dm_gateway/
security.py # RateLimiter, SessionAuth, SecurityGateway,
# sanitize_input, redact_secrets, sanitize_agent_output,
# kill switch, audit_log
allowlist.py # merge config + env + file into allowlist / owners
commands.py # /kill /unkill /status /auth /lock (no LLM)
pipeline.py # InboundSecurityPipeline.precheck() orchestration
discord_adapter.py # optional discord.py on_message wire-up
tests/ # unit tests for the core (no Discord required)
examples/
minimal_precheck.py # CLI-style demo of precheck outcomes
discord_echo_bot.py # secured DMs + echo agent
| मॉड्यूल | ज़िम्मेदारी |
|---|---|
SecurityGateway | एकल check_message(user_id, text) -> SecurityVerdict |
InboundSecurityPipeline | एक ही कॉल में अनुमति सूची + स्लैश कमांड + गेटवे |
DiscordDMGateway | केवल-DM एडाप्टर; आप एजेंट फ़ंक्शन इंजेक्ट करते हैं |
शून्य अनिवार्य रनटाइम निर्भरताएँ। Discord वैकल्पिक है: pip install agentic-dm-gateway[discord]।
git clone https://github.com/SamsonCyber/agentic-dm-gateway.git
cd agentic-dm-gateway
pip install -e ".[dev]"
python scripts/repro.py
डिफ़ॉल्ट स्टेट निर्देशिका: ./data/agentic_dm/।
ये कभी भी आपके मॉडल को कॉल नहीं करते।
MIT। देखें LICENSE।
| नियंत्रण | व्यवहार |
|---|
| अनुमति सूची | केवल कॉन्फ़िगर किए गए उपयोगकर्ता आईडी ही आगे बढ़ सकते हैं। बाकी सभी को हटा दिया जाता है (मौन रूप से या छोटे deny स्ट्रिंग के साथ)। |
| मालिक बनाम मित्र | मालिक PIN छोड़ देते हैं और पूरे एजेंट को रोक सकते हैं। मित्रों को समय-सीमित सत्र खोलने के लिए साझा PIN की आवश्यकता हो सकती है (Hermes-शैली पेयरिंग विचार, सरलीकृत)। |
| किल स्विच | वैश्विक रोक फ़ाइल या env फ़्लैग। सक्रिय रहने पर एजेंट का कोई दौर (turn) नहीं चलता। |
| रेट सीमाएँ | प्रति उपयोगकर्ता स्लाइडिंग विंडो (प्रति मिनट और प्रति घंटा)। |
| इनपुट जाँच | अधिकतम लंबाई, असामान्य नियंत्रण वर्ण हटाना, सामान्य इंजेक्शन / गुप्त-जानकारी मांगने वाले वाक्यांशों के लिए रेगेक्स ह्यूरिस्टिक्स। |
| आउटपुट स्क्रब | गुप्त जैसे दिखने वाले टोकन (API कुंजियाँ, JWT, Bearer हेडर) को रेडक्ट करें और markdown/HTML इमेज बीकन को हटाएँ जो ऑटो-फ़ेच के माध्यम से डेटा बाहर भेज सकते हैं। |
| ऑडिट लॉग | बाद में समीक्षा के लिए allow/deny/auth/kill घटनाओं की केवल-जोड़ें (append-only) JSONL। |
| स्थानीय कमांड | /auth, /lock, /kill, /unkill, /status बिना मॉडल कॉल किए संभाले जाते हैं। |
| कुंजी | डिफ़ॉल्ट | अर्थ |
|---|
allowed_user_ids | [] | चैट करने की अनुमति वाले उपयोगकर्ता आईडी |
owner_ids | [] | PIN छोड़ें; /kill कर सकते हैं |
pin_enabled | True | गैर-मालिकों के लिए PIN गेट |
pin_ttl_hours | 72 | खुले रहने की अवधि |
rate_limit_per_minute | 8 | स्लाइडिंग विंडो |
rate_limit_per_hour | 60 | स्लाइडिंग विंडो |
max_input_chars | 2000 | अधिकतम इनपुट लंबाई |
block_injection | True | ह्यूरिस्टिक ब्लॉक सूची |
deny_message | False | मौन, True, या कस्टम स्ट्रिंग |
audit_log | True | ऑडिट JSONL लिखें |
enabled | True | मास्टर स्विच |
| वेरिएबल | उद्देश्य |
|---|
AGENTIC_DM_ALLOWLIST | अल्पविराम-पृथक उपयोगकर्ता आईडी |
AGENTIC_DM_OWNER_ID | मालिक आईडी |
AGENTIC_DM_PIN | PIN प्लेनटेक्स्ट |
AGENTIC_DM_PIN_REQUIRED | 1 = सेट न होने पर भी PIN आवश्यक |
AGENTIC_DM_KILLED | 1 = किल स्विच चालू |
AGENTIC_DM_DATA_DIR | किल फ़ाइल, open, ऑडिट लॉग के लिए निर्देशिका |
AGENTIC_DM_SECRETS_DIR | dm_pin.txt / dm_allowlist.txt के लिए निर्देशिका |
| कमांड | कौन | प्रभाव |
|---|
/kill /pause | मालिक | सभी के लिए एजेंट रोकें |
/unkill /resume | मालिक | रोक हटाएँ |
/status | मालिक | किल / PIN / अनुमति सूची स्नैपशॉट |
/auth <pin> | अनुमति-सूचीबद्ध | TTL के लिए सत्र खोलें |
/lock | अनुमति-सूचीबद्ध | खुला सत्र बंद करें |