Skip to main content

seclx

安全 LLM 网关,也是本机唯一的本地推理入口(:8500,OpenAI 兼容)。mtplx 已退役,引擎在 seclx/engine_core,由网关按池拉起 pod。

文档 内容
DESIGN.md 现在的分层、路由、槽位和会话
ACCELERATION.md 全部加速参数、原理、实测和建议值
COMPETITIVE-MULTIMODAL.md 图像 / 视频 / 音频执行面
../HARDWARE-BENCH.md 机器带宽和内存硬顶

安装与启动

cd llm/llmagentMAC/seclx
python3 -m pip install -e .
seclx serve          # 网关 :8500;引擎 pod 按需拉起

配置在 configs/seclx.yaml。会话绑定在 state/sessions.json,重启后续上,不丢会话键。引擎权重进程退出后要重新加载,第一次请求会重新 prefill。

调用方只打 http://127.0.0.1:8500/v1。不要直连 pod socket。

对照引擎 cmp-sglang(:8011)和 cmp-splash(:8010)是 pod 自己拉起的本机源码,不在默认路由里。模型名加 @sglang / @splash,或请求体 seclx.engine,才进入对应池。Apple/MLX 的默认仍是本机 engine pod。非 MLX 环境的平台默认是 SGLang;模型卡片绑定了 Splash 或 SGLang 时用绑定的那个。选择规则在 seclx/engine_policy.py。实测见 kcServer docs/ops/O-20261201-01-engine-and-posttrain-acceptance.md。

现在谁在跑

Cline / kcServer / kcclaw ──OpenAI──▶ seclx :8500
                                      ├▶ masterLLM   qwen3.8-27B 4bit        槽位 3 (22G)
                                      ├▶ sec         secllm 27B affine 8-bit 槽位 3 (32G)
                                      ├▶ aux         9B 4bit   ar_batch 3 路 (6G)
                                      ├▶ jevFast     2B 4bit + decision LoRA  ar_batch 8 路 (3G)
                                      ├▶ guard_*     快筛 / 0.6B / 8B
                                      └▶ omni / audio / diffusion / video

池数量 9 → 10(2026-11-27,v22;v23.1 线上为 9B v23 adapter,2B 优化中):新增 jevFast 决策专用池。 aux 只做业务便宜档、不再参与任何判定;检索决策链(/v1/retrieve 的 auto 判档、hybrid 重排、deep 多跳取证)与 /v1/decision 统一点名 model=jevFast(别名 jevfast)。

  • v22(2026-11-27 上午):qwen3.5-9b-4bit + decision_jev9b_lora, ar_batch 3 路;实测冷启 4.1s、热态 P50 0.73s(6 判定一批)、 3 路并发 wall 1.09s(≈2.77 requests/s,README 旧文误写成"判定/s", 换算成判定是 ≈16.6 判定/s)。
  • v25(2026-11-27,当前线上):Qwen3.5-2B-4bit + 协议 v2 蒸馏合批训练, 融合成 6bit(decision_jev2b_v25_fused6bit,1.4GB);no_mtp + ar_batch 8 路
    • batch_wait_ms 20 + max_tokens 96 + idle_exit_s 3600(常驻)+ budget_gib 4.0。 实测(bench_jevfast.py 网关口径):冷启 3.33s、6 判定 P50 0.186s(单流 32.5 判定/s)、8 路聚合 91.9 判定/s、RSS 2.33GB。 质量(60 条 clean eval):overall 88.3%(网关 v2 生产路径 93.3%), choice 90 / noul 93.3 / score 70(网关 score 100),超过社区 MiniCPM5-2B-Jev (86.7%)与 9B v23(86.7%)。协议见 ../docs/decision-protocol-v2.md。 融合注意:mlx_lm fuse 直接融 4bit 会退化(48%);正确路径是 dequantize→bf16 fuse→再量化(6bit 最优,8bit 86.7%,bf16 88.3%)。
  • v23.1(历史):9B v23(86.7%),保留权重可回滚。
  • 决策失败(异常)向上抛 DecisionError,调用方回落 fast 纯词法,没有 aux 回退。
  • 细节/复测脚本见 ../scripts/decision_finetune/README.md 与 bench_jevfast.py;3B 预研见 ../docs/decision-model-3b-preresearch.md。

动态资源驱动的多模型并发调度(2026-11-20 升级):已取消"两个 19–20 GB pod 不能同时加载"的人为硬限制。在 Mac Studio(96 GiB 统一内存 / usable_gib=80 GiB)上,masterLLM(4-bit 22G)+ sec(affine 8-bit g64 + 8-bit MTP 32G)+ aux(6G)合计 ~60 GiB < 80 GiB,只要实时可用内存与预算满足即可按需并发加载。资源紧张时由 PoolRegistry.plan_load 按 LRU 驱逐空闲 lazy 池;无流量自动退出采用分级 TTL(aux 90s / masterLLM & sec 180s;当 OS 可用内存低于 24 GiB 时如独立训练 secLLM/guard,无在飞流量的空闲池加速至 45s 释放)。引擎防复读与缓存遥测(2026-11-20):engine_worker 默认开启 loop_guard=True + repetition_stop=True,并透传真实 cached_tokens 至 usage.prompt_tokens_details.cached_tokens。Guard 仍保持默认 runtime=false + cascade 懒加载多层机制,平时绝不预加载 40G guard 池。

OpenAI Responses API(长任务治理):支持 POST /v1/responses(含 store=true、previous_response_id、reasoning.effort=none|off|minimal、prompt_cache_key 会话粘滞、stream_reliable=false 可靠 SSE 合成)、GET/DELETE /v1/responses/{id} 与 POST /v1/responses/compact。远程池 native_responses: true(当前 deepseek-flash)时原生转发到 DeepSeek /v1/responses(流式/function tools/usage 原样,seclx 只补 cost),不再经过 Responses→Chat 翻译;远程 DeepSeek 未开该开关会直接 500,禁止降级。

流式保护(2026-11-25):pod 在排队(accepted)、prefill、重复检测冻结期间每 5s 发 progress 心跳;网关按静默计时(first_token_timeout_s 默认 120s),不再把 16k–38k token 的 prefill 当挂死。首字之后只做"完全无数据"兜底(stream_idle_timeout_s 300s),不限制总时长。HTTP 200 之后的上游异常会转成 OpenAI 错误帧 + [DONE],客户端看到的是带 message 的 APIError,不再是 APIConnectionError。细节见 ACCELERATION.md 的"计时与思考链"。

模型名是契约:masterLLM、secLLM、qwen3.5-9b-4bit 不随 checkpoint 改。secLLM-27b 不是目录条目,会 404。

槽位

每个池的 slots 是这一个 pod 的服务容量,按该模型的实测拐点配置。agent 自己用多少,写在 state/slots.json 的 consumers 里,网关只做超额 429。

单 pod 真并发只有 ar_batch 一条路(单线程跨请求合批,mlx-lm BatchGenerator,对齐 mtplx 的 _BatchedARGenerationService):一次 [B,·] 前向推进整批,每路独立 KV/采样器。aux(9B,no_mtp)现在就是 ar_batch 3 路;masterLLM / sec 带 MTP 头,合批车道只支持纯 AR,所以仍是 serial 1 槽。配置只需 plugin_options.pod_scheduler: ar_batch + pod_concurrency: N,并把 max_concurrency / slots 同步提到 N(否则准入处就被串行化,攒不出批)。细节与实测见 ACCELERATION.md。

概览里的「空闲 / 总槽位」只加当前已经加载的引擎池(kind 为 engine 或 vlm-pod)。没加载的模型不占数字,guard 快筛也不混进这张总表。各池自己的槽位条仍在模型列表里。

管理

面 入口
用户 /v1/*,消费者 key sk-seclx-*
模型与缓存价 GET /v1/models、GET /v1/models/{id}、GET /v1/model/info
统一检索(2026-11-27) POST /v1/retrieve(fast/hybrid/deep/graph/auto,旁路 FTS5 + kcserver Chroma 向量代理 + 实体图 + SAG2 多跳 + 本地决策重排);POST /v1/knowledge/ingest、DELETE /v1/knowledge/entries/<id>、`GET /v1/knowledge/stats
决策池内存(2026-12-02) jevFast 实际 phys_footprint 约 2.33 GiB(权重 1.44 GiB),不是 6 GiB——/metrics pools.jevFast.held_gib 已从 budget 口径改为副本实际值;budget 6→3 GiB。会话银行上限 2 GiB / 256 条 / 空闲 900s 自动丢弃,MLX allocator 每 1024 token 清缓存;仍保留前缀缓存,auto p50≈136–219ms、p95≈221–324ms
决策池常驻(2026-12-02) jevFast 池 load_policy: resident + idle_exit_s: 0;启动期由 gateway.warm_resident_pools() 加载并做一次真实推理(SECLX_RESIDENT_WARM_POOLS 默认 jevFast),auto 判档首条请求不再吃 3.6–3.9s 冷启;实测 auto 首次 ~0.15–0.4s、命中缓存 ~1ms;auto 判档另有 900ms 硬超时,超时回 fast 并标 degraded
控制 /admin/*,头 X-Seclx-Admin
页面 kcServer finetune → seclx 服务管理(代理 /admin/overview)

聊天模型在这三条查询里带当前模板的价格。OpenAI 官方的模型列表没有价目;这里额外给出两套客户端已经在读的字段,数字都从 configs/pricing.yaml 现算,改模板后下一次查询就变(默认 60 秒热加载,?force=1 立刻重读):

  • pricing.prompt / pricing.completion / pricing.input_cache_read / pricing.input_cache_write:USD/token 字符串(OpenRouter 口径)
  • seclx_pricing:USD/1M tokens,和价目表同一单位。缓存写入不另加价,cache_write 等于未命中输入价
  • GET /v1/model/info:LiteLLM 形状(supports_prompt_caching、cache_read_input_token_cost、cache_creation_input_token_cost)。Cline 的 LiteLLM provider 读这个接口;它的 OpenAI Compatible 模式只取模型 id,不读价格

峰谷价(2026-12-02):configs/pricing.yaml 的模板价是 DeepSeek 官方高峰价; offpeak_multiplier: 0.5 在空闲时段自动生效。高峰为北京时间周一至周五 09:00–12:00、14:00–18:00(不含中国法定节假日),其余时段(含周末/节假日全天)空闲。 usage.cost_detail.tier 会标 peak / off_peak,GET /v1/seclx/pricing 额外返回 pricing_calendar(当前档位、5 折倍率、高峰窗口)。节假日内置 2026 年国办通知, 可用 DEEPSEEK_CN_HOLIDAYS=YYYY-MM-DD,... 追加。实现:seclx/offpeak.py。

生图、视频、语音模型不声明 prompt cache。Cline 用 LiteLLM provider 时,API key 可以放在 Authorization: Bearer 或 x-litellm-api-key。

seclx admin guard show|on|off
seclx admin limits show
seclx admin models list --all

Guard 出口

请求带 guard_mode:detect(默认,返回检测行)、mask(证据打成 **)、rewrite(词库替换)。模型不学后两种。函数在 seclx/guard_modes.py,训练侧说明在 ../docs/guard-training.md。

目录

configs/seclx.yaml          池、槽位、MTP、路由
seclx/app.py                OpenAI 入口与请求生命周期
seclx/router.py             档位 → 池,会话粘滞
seclx/replicas.py           pod 拉起、槽位准入、空闲卸载
seclx/sessions.py           会话键落盘
seclx/workers/engine_worker.py
seclx/engine_core/          内化后的推理内核

Metadata

Release files for seclx 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for seclx 0.2.0
File Size Uploaded Provenance Actions
seclx-0.2.0.tar.gz 2.6 MB Without provenance Details for seclx-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for seclx 0.2.0
File Interpreter ABI Platform Actions
seclx-0.2.0-py3-none-any.whl Python 3 none any Details for seclx-0.2.0-py3-none-any.whl

Total release size: 5.4 MB

Release files / seclx-0.2.0.tar.gz

Download URL seclx-0.2.0.tar.gz
Size 2.6 MB
Tags Source
SHA-256 checksum
How to use checksums
7bb59ab5d7806e67c506de1062d32fe500d4014d7739229220134d68e9b272a4
BLAKE2b-256 checksum
How to use checksums
f64f95692a4803fc63eafc16093de2840b25a04495977bc3ef43806c27ac3594
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Release files / seclx-0.2.0-py3-none-any.whl

Download URL seclx-0.2.0-py3-none-any.whl
Size 2.8 MB
Tags Python 3
SHA-256 checksum
How to use checksums
62ca8452f0ff1be3a77d472c344d73337d2fa4fef6e0c3386a1961525fc9d751
BLAKE2b-256 checksum
How to use checksums
c15bf0a3999c85bb3aa1dd88d0823197f9625f4fb7e9ca1d49be0e2b339f3643
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Security for seclx 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page