关于 Lingua Universale MCP Server
Lingua Universale 是用于定义和验证 AI Agent 通信协议的类型检查器,面向构建多 Agent 工作流的开发者。它通过会话类型和形式化证明检查协议属性,并在运行时阻止违规通信。
主要功能
- 01定义 Agent 通信协议
- 02验证终止、死锁等属性
- 03运行时阻止协议违规
- 04协议语言编译器与 Python 代码生成
- 05命令行检查、格式化和验证
适用场景
- 01验证多 Agent 协作流程
- 02在 CI 中检查协议文件
- 03用标准协议模板搭建项目
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
问题
你的 AI Agent 彼此通信,但没有任何机制能保证它们遵守规则。发送方错误、消息顺序错误、步骤缺失——而你只有在生产环境中才会发现。
Lingua Universale(LU)是一款用于 AI Agent 对话的类型检查器。你定义协议,LU 证明它正确,运行时则强制执行协议。
from cervellaswarm_lingua_universale import Protocol, ProtocolStep, MessageKind, SessionChecker, TaskRequest
# Define: who sends what, to whom, in what order
review = Protocol(name="Review", roles=("dev", "reviewer"), elements=(
ProtocolStep(sender="dev", receiver="reviewer", message_kind=MessageKind.TASK_REQUEST),
ProtocolStep(sender="reviewer", receiver="dev", message_kind=MessageKind.TASK_RESULT),
))
checker = SessionChecker(review)
checker.send("dev", "reviewer", TaskRequest(task_id="1", description="Review auth")) # OK
checker.send("dev", "reviewer", TaskRequest(task_id="2", description="Oops")) # ProtocolViolation!
# ^^^ wrong turn: reviewer must send next
协议规定接下来由审查者发言。运行时会阻止它。这并非因为你信任代码,而是因为会话类型使这种情况不可能发生。
安装
pip install cervellaswarm-lingua-universale
或者先试用:游乐场(通过 Pyodide 在浏览器中运行)。
编写协议
protocol DelegateTask:
roles: supervisor, worker, validator
supervisor asks worker to execute analysis
worker returns result to supervisor
supervisor asks validator to verify result
when validator decides:
pass:
validator returns approval to supervisor
fail:
validator sends feedback to supervisor
properties:
always terminates
no deadlock
no deletion
all roles participate
然后验证:
lu verify delegate_task.lu
[1/4] always_terminates ... PROVED
[2/4] no_deadlock ... PROVED
[3/4] no_deletion ... PROVED
[4/4] all_roles_participate ... PROVED
All 4 properties PASSED.
数学证明,而不是今天通过、明天失败的测试。
你将获得什么
| 功能 | 描述 |
|---|---|
| 完整编译器 | 词法分析器、解析器(64 条规则)、AST、契约检查器、Python 代码生成 |
| 9 项经过验证的属性 | always_terminates、no_deadlock、no_deletion、role_exclusive 等 |
| 20 个标准库协议 | AI/ML、商业、通信、数据、安全——开箱即用 |
| 代码检查器 + 格式化工具 | lu lint(10 条规则)+ lu fmt(零配置,类似 gofmt) |
| LSP 服务 | 诊断、悬停提示、补全、转到定义、格式化 |
| VS Code 扩展 | 从 Marketplace 安装 |
| 交互式聊天 | lu chat —— 通过对话构建协议(英语、意大利语、葡萄牙语) |
| 浏览器游乐场 | 立即试用 —— 检查、代码检查、运行、聊天 |
| Lean 4 桥接 | 生成并验证数学证明 |
| REPL | 使用 lu repl 进行交互式探索 |
| 项目脚手架 | 使用 20 个经过验证的模板,通过 lu init --template rag_pipeline 创建项目 |
零外部依赖。纯 Python 标准库。
CLI
lu check file.lu # Parse and compile
lu verify file.lu # Formal property verification
lu run file.lu # Execute
lu lint file.lu # 10 style and correctness rules
lu fmt file.lu # Zero-config auto-formatter
lu chat --lang en # Build a protocol conversationally
lu demo --lang it # See the La Nonna demo
lu init --template NAME # Scaffold from stdlib templates
lu visualize file.lu # Generate Mermaid sequence diagram
lu mcp-audit --manifest t.json # Audit MCP server protocols
lu repl # Interactive REPL
lu lsp # Start LSP server
CI 集成
将协议验证添加到你的 GitHub Actions 工作流中:
# .github/workflows/lu-check.yml
on:
push:
paths: ["**/*.lu"]
jobs:
lu-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v6
with:
python-version: "3.11"
- run: pip install cervellaswarm-lingua-universale
- run: lu lint protocols/
- run: lu verify protocols/
如果存在违规项,退出代码将为非零——可用于任何 CI 系统。
工作原理
LU 基于多方会话类型构建(Honda、Yoshida、Carbone——POPL 2008)。会话类型将通信协议描述为类型:如果两个进程遵循相同的会话类型,它们就不会发生死锁,消息不会以错误顺序到达,对话也总会终止。
处理流程:
.lu source → Tokenizer → Parser → AST → Spec Checker → Lean 4 Proofs → Python Codegen
↓
PROVED or VIOLATED
LU 不会取代你的 AI Agent 框架,而是让它更安全。就像 TypeScript 之于 JavaScript——保留你的工具,同时增加保证。
示例
LU Debugger —— 在线 Web 应用:3 个 AI Agent(Customer、Warehouse、Payment)基于经过验证的 OrderProcessing 协议进行通信。点击 “Break” 即可实时查看被阻止的协议违规。源代码。
请参阅 examples/ 目录:
- Agent 编排 —— 3 个 AI Agent,包含嵌套选择,8/8 项属性均已证明
- 实时运行器 —— 使用真实 Claude API 的 Agent,运行于经过验证的协议上
- 标准库 —— 5 个类别中的 20 个经过验证的协议
也可以试试交互式 Colab 笔记本——2 分钟即可开始,无需任何设置。
更多来自 CervellaSwarm 的项目
Lingua Universale 是 CervellaSwarm 的核心项目。我们还发布了以下 Python 包:
| 包 | 功能 |
|---|---|
| code-intelligence | 由 AST 驱动的代码理解(tree-sitter、PageRank) |
| agent-hooks | Claude Code Agent 的生命周期钩子 |
| agent-templates | Agent 定义模板和团队配置 |
| task-orchestration | 确定性的任务路由与验证 |
| spawn-workers | 多 Agent 进程管理 |
| session-memory | 跨对话持久化会话上下文 |
| event-store | 不可变事件日志与审计跟踪 |
| quality-gates | 自动化质量检查与评分 |
全部采用 Apache 2.0 许可证,要求 Python 3.11+,均经过测试并提供文档。
参与贡献
欢迎贡献!请参阅 CONTRIBUTING.md 了解指南。
- 错误报告:GitHub Issues
- **安全:**请参阅 SECURITY.md,了解负责任的漏洞披露方式
许可证
Apache License 2.0 —— 详见 LICENSE。
版权所有 2025-2026 CervellaSwarm 贡献者。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。