Skip to main content

Encrypted chatbot framework over Noise_IK (Curve25519 + ChaCha20-Poly1305 + BLAKE2b). Python reimplementation of TRUGS-LLC/noise-chatbot (Go), regenerated from noise_chatbot.super.trug.json per the TRUG-driven rewrite methodology.

Project description

noise-chatbot (Python)

Encrypted chatbot framework over Noise_IK (Curve25519 + ChaCha20-Poly1305 + BLAKE2b).

Python reimplementation of TRUGS-LLC/noise-chatbot (Go), generated from noise_chatbot.super.trug.json per the TRUG-driven rewrite methodology.

Status: Phase B scaffold. Function bodies are NotImplementedError stubs. Phase C fills them from the super-TRUG without reading Go source.

Quickstart (future — after Phase C)

from noise_chatbot.server import Server

s = Server(":9090")
s.on_chat(lambda text: "You said: " + text)
print("Public key:", s.public_key())
s.listen_and_serve()

Why Python

Same reasons as the Go original — encrypted end-to-end chatbot with no TLS certificates, no DNS, no MITM window — plus:

  • Drop-in replacement for Python teams already on the Python-AI ecosystem.
  • Pluggable stores. Guardrails, responses, banned keys, and the TRUG knowledge base each live behind a tiny Protocol. Ship with the zero-dependency in-memory / JSON-file defaults, or opt in to the graph-backed trugs-store adapter for persistent state. See Stores below.
  • Apache 2.0 (matching the Go original's license pre-#1550-relicense).

Install

pip install noise-chatbot          # standalone — in-memory + JSON-file stores
pip install noise-chatbot[trugs]   # + trugs-store graph adapter

From source during development:

git clone https://github.com/TRUGS-LLC/noise-chatbot
cd noise-chatbot
pip install -e ".[dev]"            # includes trugs-store for the full test suite

Stores

The Server holds four kinds of swappable persistent-state:

Protocol What it does In-memory default JSON-file [trugs] extra
GuardrailStore Pre-authored boundary responses compiled-in 15 nodes TrugsGuardrailStore
ResponseStore Classifier match targets empty list JsonFileResponseStore(path) TrugsResponseStore
BannedKeyStore TTL-bounded bans (slowdown, not prevention) InMemoryBannedKeyStore(ttl=72h) JsonFileBannedKeyStore(path, ttl) TrugsBannedKeyStore
KnowledgeBaseStore TRUG context injection empty JsonFileKnowledgeBaseStore(path) TrugsKnowledgeBaseStore

Wire one in via the builder API:

from datetime import timedelta
from noise_chatbot.server import Server
from noise_chatbot.stores import JsonFileBannedKeyStore, JsonFileResponseStore

s = (
    Server(":9090")
    .with_response_store(JsonFileResponseStore("responses.trug.json"))
    .with_banned_keys(JsonFileBannedKeyStore("bans.json", ttl=timedelta(hours=72)))
)

Or the legacy path-based shortcuts (preserved — they now wrap the stores internally):

s = Server(":9090").with_responses_from_trug("responses.trug.json")

Opting in to trugs-store

# pip install noise-chatbot[trugs]
from trugs_store import JsonFilePersistence
from noise_chatbot.stores.trugs import TrugsBannedKeyStore

graph = JsonFilePersistence().load("chatbot.trug.json")
s = Server(":9090").with_banned_keys(TrugsBannedKeyStore(graph))
# The graph is mutated in place — caller is responsible for persisting via
# JsonFilePersistence.save() or the postgres backend before shutdown.

Every BannedKeyStore implementation is required (by the Protocol's type signature) to enforce ttl: timedelta expiry. No permanent-ban implementation is possible — bans are a slowdown mechanism, not prevention.

Architecture

noise_chatbot/
  noise/       Noise_IK transport (Curve25519 + ChaCha20-Poly1305)
  protocol/    Message type (JSON wire format)
  server/      Server, SafetyConfig, ResponseNode, DEFAULT_GUARDRAILS
  client/      Client, connect, chat, send, close
  helper/      noise-helper stdin/stdout bridge
  examples/    echo, faq, llm, graph

The Python API mirrors the Go API with idiomatic Python naming (snake_case instead of PascalCase for methods; Python dataclasses instead of Go structs). Behavioural parity is enforced by the parity corpus under tests/parity/.

Testing

pytest                    # unit + integration
pytest -m parity          # Go-golden parity corpus (needs Go binaries)
ruff check . && ruff format --check . && mypy src tests

Parity

Phase A of issue #1555 in TRUGS-DEVELOPMENT produced a 21-fixture YAML corpus that the Go implementation passes. This Python implementation is validated against the same corpus — Phase C is complete when all 17 runnable fixtures pass.

License

Apache License 2.0. See LICENSE and NOTICE.

Built on:

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

noise_chatbot-0.1.0.tar.gz (37.1 kB view details)

Uploaded Source

Built Distribution

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

noise_chatbot-0.1.0-py3-none-any.whl (44.8 kB view details)

Uploaded Python 3

File details

Details for the file noise_chatbot-0.1.0.tar.gz.

File metadata

  • Download URL: noise_chatbot-0.1.0.tar.gz
  • Upload date:
  • Size: 37.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for noise_chatbot-0.1.0.tar.gz
Algorithm Hash digest
SHA256 45ec16f85056484c844c598c1c549a43a14034c7fd622a20b496c95ae3f82aa7
MD5 314488a370970abe1afaa82bda1382fe
BLAKE2b-256 bc3dc46e9f6863cc672249b9c8283eddce5f9dcd95044aab0da07b2f04c0a708

See more details on using hashes here.

File details

Details for the file noise_chatbot-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: noise_chatbot-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 44.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for noise_chatbot-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b4b6ba247eeea07ba7c433f652f065e19af5086a13af45b4a8c6bcb336efb809
MD5 9818f775a45c862b3ca8f351d50d01ed
BLAKE2b-256 77c2d6d142fde292caf6257385199adc030bf23886a4e962ecfbea1d496b9a86

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