furuse-kazufumi/llmesh

GitHub: furuse-kazufumi/llmesh

安全优先的本地 LLM 集群编排框架,融合工业协议网关、多层隐私防护与防篡改审计,为关键基础设施场景提供统一的大模型调度与智能分析方案。

Stars: 0 | Forks: 0

# LLMesh **基于 MCP 的安全 LLM Mesh** — **v3.1.0** 涵盖工业 IoT、关键基础设施、尖端 AI/量子、RTOS 微控制器的统一框架 Python 集成平台。 **本地 LLM**(Ollama / llama.cpp)与**云端 LLM**(OpenAI / Azure / Anthropic / OpenRouter / Groq / Together / Mistral / DeepSeek)通过统一的 ABC 实现透明 运维。117 章 / 500+ 需求项,Rust 扩展实现 6× 性能提升,2300+ 测试全部通过。 **整体 OWASP 静态审计无漏洞**(`shell=True` / `pickle` / `eval` / SQL 注入 / 弱加密 均为零,所有 HTTP 客户端均设有响应大小上限), **自 v3.0.0 起正式适用 SemVer**(`docs/API_STABILITY.md` 中的公开符号列表即为契约)。 ## 架构 / 全局概览 ``` flowchart LR subgraph Field["Field / 現場"] M[Modbus / OPC-UA / MQTT / Serial / EtherCAT / BACnet] H[HTTP / HTTPS / WebSocket / gRPC] E[Email / SSH / FTP / SNMP / NTP] R[ROS 1 / ROS 2] V[Camera / Mic / VLM] end subgraph Core["llmesh core (multi-protocol gateway)"] PA[Protocol Adapters] PF[PromptFirewall
L0/L1/L1.5/L2/L3/L4] AU[AuditTrail
HMAC chain] RA[RAG
numpy/sqlite/LSH] SP[SPC / MT-method
Hotelling T² / CUSUM] end subgraph LLM["LLM backends (ABC)"] O[Ollama / llama.cpp] C[OpenAI / Anthropic / Azure /
OpenRouter / Groq / Together / Mistral / DeepSeek] end subgraph UI["UI / dashboard (separate package)"] L[💗 llove TUI
llmesh dashboard] HX[HTML export] end M & H & E & R & V --> PA --> PF --> RA & SP PF --> O & C PF --> AU SP & AU & RA -. stream .-> L L --> HX ``` ## 快速开始 ``` # PyPI からのインストール(配布名は llmesh-mcp、import 名は llmesh) pip install llmesh-mcp # 産業用フル機能 pip install "llmesh-mcp[industrial,vision,presidio,rag]" # 可視化込み一括(メタパッケージ、準備中) pip install llmesh-suite # ローカル開発 git clone git@github.com:furuse-kazufumi/llmesh.git cd llmesh pip install -e ".[dev,industrial]" pytest ``` ``` # import 路径保持 llmesh 不变 from llmesh import PromptFirewall, SensorEvent from llmesh.rag import Retriever, MockEmbedder, NumpyVectorStore from llmesh.llm import openai_backend, OllamaBackend ``` 主要可选附加组件: ``` pip install -e ".[industrial]" # MTEngine / SPC / Modbus / OPC-UA / MQTT pip install -e ".[vision]" # ImageFirewall / VLM 経路 pip install -e ".[presidio]" # Layer 1.5 PII 検出(v2.13.0+) pip install -e ".[rag]" # RAG(ベクトル検索)(v2.13.0+) pip install -e ".[email,udp,ssh,ftp,mgmt,can,bacnet]" ``` ## 截图 — `llmesh dashboard`(由 llove 提供支持) llmesh 的数据可通过姊妹仓库 **[llove](https://github.com/furuse-kazufumi/llove)** 的 TUI 在一个界面内查看。使用 `pip install llmesh-llove && llmesh dashboard` 即可启动。原始尺寸的截图可在 llove 仓库中找到。 | 界面 | 目标 | |------|------------| | ![SCADA](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/a1335af7b0080723.svg) | 工业 IoT / SCADA | | ![PromptFirewall](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/816e41a8ed080724.svg) | PromptFirewall / 隐私管道 | | ![RAG](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/ef7166e5fd080724.svg) | RAG 检索 | | ![AuditTrail](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/552d348df1080725.svg) | HMAC 链审计 | | ![Backends](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/aa1c558f82080725.svg) | LLM 后端切换 | | ![Reliability](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/1c08c8cff5080726.svg) | Reliability Protocol | | ![Multimodal](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/232d4b79fc080727.svg) | 图像 + 音频 + LLM | llove 不仅仅是仪表盘,还可以通过相同的抽象机制启动 shogi(带有 Ed25519 签名的逐行日志) / chess / 打字等**对局与学习演示**。详情请参阅 [llove README](https://github.com/furuse-kazufumi/llove)。 ## 组件 ### 核心 | 模块 | 描述 | |---|---| | `llmesh.classifier` | DataLevel (L0–L4) + ClassifiedPayload | | `llmesh.privacy.firewall` | 4 层 Prompt Firewall(L0 注入检测 / L1 密钥 / **L1.5 Presidio PII** / L2 结构) | | `llmesh.privacy.summarizer` | PrivacySummarizer(L3 摘要管道) | | `llmesh.privacy.image_firewall` | ImageFirewall(L4 图像 BLOCK / L3 摘要) | | `llmesh.privacy.presidio_detector` | **NEW v2.13** Microsoft Presidio 集成(PII 检测,可选) | | `llmesh.identity` | Ed25519 Node ID + `did:llmesh:1:` + Capability Manifest + X25519 ECDH | | `llmesh.rendezvous` | 签名节点发现服务(明文 / AES-256-GCM) | | `llmesh.mcp` | MCP tool schemas + OutputValidator | | `llmesh.audit` | 防篡改 HMAC 链审计日志 | | `llmesh.fairness` | 防搭便车机制(ServiceReceipt / ContributionLedger / FairnessPolicy) | ### RAG (v2.13.0+) | 模块 | 描述 | |---|---| | `llmesh.rag.embedder` | Embedder ABC + MockEmbedder(确定性哈希)+ OllamaEmbedder(仅使用 urllib) | | `llmesh.rag.store` | VectorStore ABC + Document / RetrievedDocument | | `llmesh.rag.numpy_store` | 纯 numpy 内存存储(余弦相似度,`.npz` 原子持久化) | | `llmesh.rag.sqlite_store` | **NEW v2.14** 纯 sqlite3 持久存储(WAL、UPSERT、在 ≤10⁶ 条目下实用) | | `llmesh.rag.lsh_store` | **NEW v2.15** LSH ANN 向量存储(≥10⁶ 条目,recall@10 ≥ 0.92) | | `llmesh.rag.retriever` | 结合 Embedder + VectorStore + Firewall 的 Retriever | ### 协议(多协议网关) | 模块 | 描述 | |---|---| | `llmesh.protocol.{http,tcp,udp,ssh,sftp,smtp,imap,pop3,ftp,snmp,telnet,ros2,ros1}_adapter` | 协议适配器集 | | `llmesh.protocol.adapter` | ProtocolAdapter ABC + TransportError | | `llmesh.protocol.registry` | AdapterRegistry(名称生成、自定义注册、entry-points) | | `llmesh.protocol.message` | UnifiedMessage + MessageType(包括 STREAM_ACK / RETRANSMIT) | | `llmesh.protocol.assembler` | MessageAssembler(顺序重组 + 超时 + 看门狗) | | `llmesh.protocol.chunk_sender` | ChunkSender(发送缓冲 + 重传 + ACK + TTL 过期) | | `llmesh.protocol.watchdog` | WatchdogTimer | | `llmesh.security.clock` | NTP 时钟同步检查 | | `llmesh.discovery.dns_sd` | DNS-SD v2 mDNS 广播器 | ### 工业 (v1.3.0+) | 模块 | 描述 | |---|---| | `llmesh.industrial.sensor_event` | SensorEvent 统一模型 | | `llmesh.industrial.{modbus,serial,opcua,mqtt,ethercat,can,bacnet,websocket}_adapter` | 工业协议 | | `llmesh.industrial.mt_engine` | Mahalanobis-Taguchi 方法(离线训练 + 实时推理) | | `llmesh.industrial.mt_online` | **NEW v2.13** OnlineMTEngine(批量 Mahalanobis、einsum、内存上限控制) | | `llmesh.industrial.spc_engine` | XbarRChart / CUSUMChart(Shewhart / 累积和控制图) | | `llmesh.industrial.hotelling_t2` | **NEW v2.13** HotellingT2Chart(多变量控制图,Tikhonov 正则化) | | `llmesh.industrial.event_density_map` | **NEW v2.13** EventDensityMap(DVS 事件 → 网格特征) | | `llmesh.industrial.multimodal_spc` | **NEW v2.13** UnifiedSPC(传感器 × VLM 文本双通道 SPC) | | `llmesh.industrial.explainer` | **NEW v2.13** LLMExplainer(SCADA 异常 → Markdown/JSON 报告) | | `llmesh.industrial.explained_cusum` | **NEW v2.14** ExplainedCUSUM(自解释 CUSUM,CUSUMChart + LLMExplainer 集成) | | `llmesh.industrial.video_cusum` | **NEW v2.14** VideoCUSUM(视频 + 传感器时间同步 CUSUM,配对缓冲) | | `llmesh.industrial.vlm_feature_extractor` | **NEW v2.14** VLMFeatureExtractor(图像 → ImageFirewall → caption → 数值向量) | | `llmesh.industrial.dnp3_adapter` | **NEW v2.14** DNP3Adapter(v3-N7 / K-1.1,SCADA outstation client,pydnp3 可选) | | `llmesh.industrial.goose_adapter` | **NEW v2.14** GOOSEAdapter(IEC 61850 GOOSE subscriber,带重放防御) | | `llmesh.industrial.sensor_3d` | AOI / 深度 / DVS(兼容 mcp-3d SDK) | | `llmesh.industrial.c_abi` | RTOS C ABI / EdgeProfile(Volume L) | | `llmesh.industrial.metrics` / `tracing` / `tenant` | OpenTelemetry / 多租户 | ## 可靠性协议 通过组合使用 `MessageAssembler` 和 `ChunkSender` 来保证 流式通信的可靠性。 ``` [正常完了] 受信: pop_completed() → STREAM_ACK 送信 送信: handle_ack() → 送信バッファ破棄 [欠落検出] 受信: check_timeouts() → RETRANSMIT 送信(1 回のみ) 送信: handle_retransmit() → 欠落チャンクのみ再送 [切断検出] 受信: check_watchdog() → True で切断シグナル 送信: expire_old() → TTL 超過バッファ自動破棄 ``` ## 隐私管道 ``` prompt → PromptFirewall (L0/L1/L1.5/L2) → PrivacySummarizer → LLM Backend (Ollama / LlamaCpp) → OutputValidator → caller ``` | 层级 | 作用 | 输出 | |------:|------|------| | L0 | Prompt 注入 / jailbreak / Unicode 控制字符 | BLOCK | | L1 | 密钥(API 密钥、JWT、PEM、AWS、GitHub、Anthropic、OpenAI) | BLOCK | | **L1.5** | **Presidio PII(信用卡 / SSN / IBAN / 医疗执照 / 个人姓名 / Email / 电话 …)** | **BLOCK or SUMMARIZE** | | L2 | 绝对路径 / 内部 import / 超大 payload | SUMMARIZE or BLOCK | ## 安全护栏 - 完全不使用 `shell=True`、`pickle`、`yaml.load(unsafe)`、`eval`、`exec` - Firewall 为 **fail-closed** 模式(异常 → L4/BLOCK) - OutputValidator 会拒绝 non-JSON / schema 不匹配 / nonce 重放 - subprocess 调用仅限 list 形式 - 所有可选依赖均作为 extras 提供(保持本体轻量) ## 性能 | 操作 | Pure Python | Rust | 倍率 | |------|-----------:|-----:|----:| | PointCloud encode (1M) | 4.0M pts/s | **24.1M pts/s** | **6.0×** | | PointCloud decode (1M) | 3.7M pts/s | 5.9M pts/s | 1.6× | | DVS encode (1M) | 3.4M evt/s | 5.5M evt/s | 1.6× | | Pipeline + CUSUM | 190K events/s | – | – | ## CLI ``` python -m llmesh.cli.doctor # 環境健全性チェック python -m llmesh.cli.status # ランタイム状態 python -m llmesh.cli.sbom # CycloneDX SBOM 自動生成 ``` ## 文档 ### 概述 / 计划 - `docs/ROADMAP.md` — 发布计划 / 版本历史 - `docs/REQUIREMENTS.md` — 117 章 / 500+ 需求,Volume A〜N - `docs/CHANGELOG.md` — 详细变更日志 ### 架构 / 规范 - `docs/ARCHITECTURE.md` — 架构 - `docs/SPECIFICATION.md` — API 规范 - `docs/SECURITY.md` — STRIDE 威胁模型 + 安全不变量 - `docs/API_STABILITY.md` — Public/Internal API 边界 + SemVer 策略(v2.15+) - `docs/PERFORMANCE.md` — 各模块复杂度 + 内存 + 推荐参数(v2.15+) ### 使用指南 - `docs/SETUP.md` / `docs/SETUP_GUIDE.md` — 设置 - `docs/USAGE.md` — 使用示例(包含 v2.13/2.14 增强功能部分) - `docs/INDUSTRIAL_GUIDE.md` — 工业 IoT 使用指南(包含 Phase A〜v3) - `docs/PEERING.md` / `docs/PLATFORMS.md` — 对等连接 / 平台 ### 运维 / 故障排除(v2.18+) - `docs/DEPLOYMENT.md` — Docker / systemd / k8s / 密钥管理 - `docs/OBSERVABILITY.md` — Prometheus / OTel / AuditTrace / SLO - `docs/TROUBLESHOOTING.md` — 错误处理集 + FAQ - `docs/MIGRATION.md` — 跨版本迁移指南 ### 开发者指南(v2.18+) - [`CONTRIBUTING.md`](CONTRIBUTING.md) — 贡献指南(提交约定 / PR 检查清单) - `docs/DEVELOPMENT.md` — 开发环境 / 内部结构 / 新模块添加步骤 -docs/TESTING.md` — 测试策略 / Hypothesis / 覆盖率目标 - `docs/GLOSSARY.md` — 术语表(LLM / 安全 / 工业) - `docs/SETUP.md` / `docs/SETUP_GUIDE.md` — 设置 - `docs/USAGE.md` — 使用示例 - `docs/PEERING.md` / `docs/PLATFORMS.md` — 对等连接 / 平台 - `docs/papers/` — RAD(21 领域语料库)+ 论文资料
标签:AI安全, AI风险缓解, Anthropic, API密钥扫描, Azure, BACnet, Chat Copilot, CISA项目, CIS基准, DeepSeek, Docker节点, EtherCAT, gRPC, IP 地址批量处理, llama.cpp, LLM评估, LLM集群, MCP协议, Mistral, Ollama, OPC-UA, OpenAI, OpenRouter, OWASP静态审计, Petitpotam, PE 加载器, Prompt注入防御, Python, RAG, ROS, RTOS微控制器, Rust扩展, SemVer, SSH, Together, TUI仪表盘, WebSocket, 串口通信, 云LLM, 依赖分析, 关键基础设施, 内存规避, 可视化界面, 多协议网关, 安全优先, 安全通信, 审计追踪, 工业物联网, 恶意代码防护, 提示词防火墙, 故障关闭验证, 无后门, 本地LLM, 本地大语言模型, 机器视觉, 模型网关, 混合云AI, 熵值分析, 用户代理, 签名对等节点发现, 统一框架, 统计过程控制, 网络安全, 请求拦截, 跨平台AI, 边缘计算, 逆向工具, 量子计算, 防护验证, 隐私保护, 零信任网络