feat: 初始化 sundynix-agentix 分层式 AI Agent 平台脚手架

5 层 + 1 条 NATS 零拷贝消息总线的 monorepo(Monolith First → Microservices Morph B)。
纵向主干(任务流 + Token 流回流)已真实跑通,横向各层能力为带注释的桩。

已贯通(real code):
- sundynix-shared: 共享契约 + JetStream/core NATS 真实收发(bus) + 内嵌 NATS(devnats) + e2e 测试
- sundynix-gateway: Gin 接入 + DSL 解析组装 + NATS Publish + SSE 流式输出
- sundynix-dispatcher: NATS 消费 + Eino Orchestrator 流式回流 + 熔断器 + LLM Pool 占位流式
- 链路: HTTP POST → DSL → sundynix.tasks.* → Dispatcher → Token 经 sundynix.streams.<id> 回流 → SSE
- 基础设施: docker-compose(nats/postgres/redis/neo4j/milvus) + Makefile(make demo/e2e)

待填(桩):
- Eino 图编排 compose.NewGraph、LLM Pool 接 vLLM/Ollama
- Gateway store 换真实 pgx/redis
- sundynix-mcp-go: Bleve+Milvus+Neo4j 混合检索 / UniOffice / 外部 API
- sundynix-mcp-py: gVisor 沙箱 / MinerU(PaddleOCR) / Docker 解释器
- sundynix-desktop: React Flow 画布 → DSL 导出 → SSE 展示
This commit is contained in:
Blizzard
2026-06-10 11:00:29 +08:00
commit c7a02c3905
74 changed files with 2570 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
nats:
url: "nats://localhost:4222"
tool_subject: "sundynix.tools.py.*"
sandbox:
runtime: "gvisor" # gvisor | kata
mem_limit: "512m"
timeout: "30s"
interpreter:
image: "python:3.11-slim"
network_disabled: true
+18
View File
@@ -0,0 +1,18 @@
[project]
name = "sundynix-mcp-py"
version = "0.1.0"
description = "sundynix-agentix · 第 5 层 Python 算法型 MCP 工具微服务"
requires-python = ">=3.11"
dependencies = [
"mcp>=1.2.0", # MCP 协议
"nats-py>=2.7.0", # 接入 NATS 骨干网
"docker>=7.1.0", # Docker 隔离沙箱 / Code Interpreter
# "magic-pdf", # MinerU 多模态解析 (PaddleOCR),按需安装
]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.build.targets.wheel]
packages = ["src/sundynix_mcp_py"]
@@ -0,0 +1,3 @@
"""sundynix_mcp_py — 第 5 层 Python 算法型 MCP 工具微服务。"""
__version__ = "0.1.0"
@@ -0,0 +1,12 @@
"""Docker 隔离沙箱:Code Interpreter 执行不可信代码并采集产物。"""
from __future__ import annotations
class CodeInterpreter:
"""Docker 隔离沙箱 · Code Interpreter。"""
async def execute(self, code: str, *, image: str = "python:3.11-slim") -> dict:
"""在一次性 Docker 容器中执行代码,返回 stdout/stderr/artifacts。"""
# TODO: docker.from_env().containers.run(..., network_disabled=True, mem_limit=...)
return {"stdout": "", "stderr": "", "artifacts": []}
@@ -0,0 +1,26 @@
"""入口:启动 MCP 协议网关,把算法型工具注册到 NATS。"""
from __future__ import annotations
import asyncio
import logging
from .mcp_gateway import McpGateway
logging.basicConfig(level=logging.INFO)
log = logging.getLogger("mcp_py")
async def _run() -> None:
gateway = McpGateway()
await gateway.register_tools() # secure_sandbox / parse_document / run_code
log.info("[mcp_py] serving MCP over sundynix.tools.py.*")
await gateway.serve()
def main() -> None:
asyncio.run(_run())
if __name__ == "__main__":
main()
@@ -0,0 +1,24 @@
"""MCP 协议网关:注册算法型工具并经 NATS 分发调用。"""
from __future__ import annotations
from .interpreter import CodeInterpreter
from .mineru import MultimodalParser
from .sandbox import SecureSandbox
class McpGateway:
def __init__(self) -> None:
self.sandbox = SecureSandbox() # gVisor / KataVM + Static Code Guard
self.parser = MultimodalParser() # MinerU / PaddleOCR
self.interpreter = CodeInterpreter() # Docker 隔离沙箱
async def register_tools(self) -> None:
# TODO: 向 MCP server 注册工具 schema
...
async def serve(self) -> None:
# TODO: 连接 NATS,订阅 sundynix.tools.py.*,按 MCP JSON-RPC 路由
import asyncio
await asyncio.Event().wait()
@@ -0,0 +1,12 @@
"""MinerU 多模态解析:PDF/图片 → 结构化文本(PaddleOCR)。"""
from __future__ import annotations
class MultimodalParser:
"""MinerU · Multimodal Parser (PaddleOCR)。"""
async def parse(self, file_path: str) -> dict:
"""解析文档,返回结构化内容(标题/段落/表格/公式)。"""
# TODO: 调 magic-pdf / PaddleOCR 流水线
return {"path": file_path, "blocks": []}
@@ -0,0 +1,19 @@
"""安全代码沙箱:gVisor / KataVM 强隔离 + 静态代码守卫。"""
from __future__ import annotations
class SecureSandbox:
"""Harness: Secure Code Sandbox。"""
def static_guard(self, code: str) -> bool:
"""静态代码守卫:危险调用/导入检测,返回是否放行。"""
# TODO: AST 扫描,拦截 os/subprocess/网络等高危调用
return True
async def run(self, code: str, *, runtime: str = "gvisor") -> str:
"""在 gVisor/KataVM 隔离环境中执行代码。"""
if not self.static_guard(code):
raise PermissionError("static code guard rejected")
# TODO: 调度到 gVisor(runsc) / Kata 容器执行并回收
return ""