Skip to main content
Glama

Lingua Universale

一种用于验证 AI 代理协议的语言。

PyPI Tests License: Apache 2.0 Zero Dependencies VS Code Discord

在浏览器中尝试 -- 无需安装。 观看 AI 代理实时运行 -- 3 个代理在已验证的协议上运行。


问题所在

你的 AI 代理之间会进行交流,但没有任何机制能保证它们遵循规则。错误的发送者、错误的消息顺序、缺失的步骤——你往往只在生产环境中才会发现这些问题。

Lingua Universale (LU) 是 AI 代理对话的类型检查器。你定义协议,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

协议规定接下来由审核员操作。运行时环境会阻止其他操作。这并非因为你信任代码,而是因为会话类型使得违规操作成为不可能。


Related MCP server: correctover-mcp-server

安装

pip install cervellaswarm-lingua-universale

或者先尝试一下:Playground(通过 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、业务、通信、数据、安全——开箱即用

Linter + 格式化工具

lu lint(10 条规则)+ lu fmt(零配置,类似 gofmt)

LSP 服务器

诊断、悬停提示、补全、跳转到定义、格式化

VS Code 扩展

从市场安装

交互式聊天

lu chat -- 通过对话构建协议(英语、意大利语、葡萄牙语)

浏览器 Playground

立即尝试 -- 检查、Lint、运行、聊天

Lean 4 桥接

生成并验证数学证明

REPL

lu repl 用于交互式探索

项目脚手架

lu init --template rag_pipeline 基于 20 个已验证模板

37 个模块。3979 个测试。零外部依赖。纯 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 代理框架。它让框架变得安全。就像 TypeScript 之于 JavaScript——你保留了你的工具,但增加了保证。


示例

LU Debugger -- 实时 Web 应用:3 个 AI 代理(客户、仓库、支付)在已验证的 OrderProcessing 协议上进行通信。点击 "Break" 查看实时拦截的协议违规。 源代码。

查看 examples/ 目录:

  • 代理编排 -- 3 个具有嵌套选择的 AI 代理,证明了 8/8 个属性

  • 实时运行器 -- 在已验证协议上运行的真实 Claude API 代理

  • 标准库 -- 涵盖 5 个类别的 20 个已验证协议

或者尝试 交互式 Colab 笔记本 -- 2 分钟,零配置。


更多来自 CervellaSwarm 的项目

Lingua Universale 是 CervellaSwarm 的核心项目。我们还发布了以下 Python 包:

包

功能

code-intelligence

基于 AST 的代码理解(tree-sitter, PageRank)

agent-hooks

Claude Code 代理的生命周期钩子

agent-templates

代理定义模板和团队配置

task-orchestration

确定性任务路由与验证

spawn-workers

多代理进程管理

session-memory

跨对话的持久会话上下文

event-store

不可变事件日志与审计追踪

quality-gates

自动化质量检查与评分

全部采用 Apache 2.0 协议,支持 Python 3.10+,经过测试并有文档记录。


贡献

我们欢迎贡献!请参阅 CONTRIBUTING.md 获取指南。


许可证

Apache License 2.0 -- 请参阅 LICENSE。

版权所有 2025-2026 CervellaSwarm 贡献者。


Lingua Universale -- AI 代理的已验证协议。

Playground | LU Debugger | PyPI | VS Code | 博客 | Colab 演示

Available Tools

4 tools
lu_check_propertiesA

Verify the formal safety properties declared in a .lu protocol.

Runs the static property checker (Layer 1) on all protocols found in
the source. Optionally, if Lean 4 is installed, also runs formal
verification (Layer 2).

Args:
    protocol_text: Full .lu protocol definition text including a
        "properties:" block, e.g.:
        "    properties:\n"
        "        always terminates\n"
        "        no deadlock\n"
        "        all roles participate\n"

Returns:
    JSON string with:
      ok (bool), protocols (list of protocol results), summary (dict).
      Each protocol result has: protocol_name, all_passed, results (list).
      Each result has: kind, verdict, evidence, params.

Inputs: protocol_text (required). Returns: result

lu_list_templatesA

List available Lingua Universale standard library protocol templates.

The standard library contains 20 verified protocols across 5 categories:
communication, data, business, ai_ml, security.

Args:
    category: Optional filter. One of: communication, data, business,
        ai_ml, security. Leave empty to list all templates.

Returns:
    JSON string with:
      ok (bool), templates (list), category_filter (str), total (int).
      Each template has: name, category, description.

Inputs: category. Returns: result

lu_load_protocolA

Parse a Lingua Universale (.lu) protocol definition.

Accepts the full text of a .lu file and returns the parsed protocol
structure: name, roles, steps, choices, and declared properties.

Args:
    protocol_text: Content of a .lu file, e.g.:
        "protocol RequestResponse:\n"
        "    roles: client, server\n"
        "    client asks server to process request\n"
        "    server returns response to client\n"
        "    properties:\n"
        "        always terminates\n"
        "        no deadlock\n"

Returns:
    JSON string with keys:
      ok (bool), protocol_name (str), roles (list[str]),
      steps (list), properties (list), error (str on failure).

Inputs: protocol_text (required). Returns: result

lu_verify_messageA

Verify whether a message is valid in the context of an ongoing session.

Replays the existing message history against the protocol, then checks
whether next_message is the expected next step.

Args:
    protocol_text: Full .lu protocol definition text.
    messages: List of already-sent messages, each a dict with keys:
        sender (str), receiver (str), action (str).
        Actions are LU action names: "asks", "returns", "sends",
        "proposes", "tells". These match the verbs in .lu source files.
    next_message: The message to validate, same format as above.

Returns:
    JSON string:
      On success: {"valid": true, "step": N, "next_expected": "..."}
      On violation: {"valid": false, "violation": "...", "expected": "...", "got": "..."}
      On error: {"valid": false, "error": "..."}

Example:
    protocol_text = "protocol Ping:\n    roles: a, b\n    a asks b to ping\n    b returns pong to a\n    properties:\n        always terminates\n"
    messages = [{"sender": "a", "receiver": "b", "action": "asks"}]
    next_message = {"sender": "b", "receiver": "a", "action": "returns"}
    # Returns: {"valid": true, ...}

Inputs: protocol_text (required), messages (required), next_message (required). Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.4/5.0

    Scored across 4 tools

    Disambiguation5/5

    Each tool has a distinct purpose: parsing, message verification, property checking, and template listing. No overlap in functionality; agents can easily select the right tool for their task.

    Naming Consistency4/5

    Names follow a consistent 'lu_' prefix and verb_noun pattern (load_protocol, verify_message, check_properties, list_templates). Minor deviation: 'load_protocol' could be 'parse_protocol' but still clear and consistent.

    Tool Count4/5

    With only 4 tools, the server is slightly under the typical 3-15 range, but this is appropriate for a niche protocol validation domain. The tools cover the core needs without bloat.

    Completeness3/5

    The server covers parsing, verification, property checking, and template listing, but misses a 'simulate' or 'validate full session' tool. Gaps exist for agents needing end-to-end protocol simulation or editing, but core workflows are supported.

    Maintenance

    ActivityInactive
    ResponsivenessLimited data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      C
      maintenance
      Integrates the Quint formal specification language into LLM workflows for accessible formal verification. It provides tools for type-checking, random simulation, exhaustive model checking, and syntax documentation.
      6
      2
      PolyForm Noncommercial 1.0.0
    • -
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to safely run Pact 5 REPL tests, scan modules for critical language traps, estimate gas, generate contracts, and invoke formal verification via a standalone prover plugin.
      -
    • A
      license
      C
      quality
      B
      maintenance
      Enables AI assistants and autonomous agents to intercept arithmetic and algebraic hallucinations via exact rational verification, seal multi-step reasoning chains with SHA-256 Merkle commitments, and optionally bridge deep verification to a remote sovereign enclave. It also supports BFT epistemic consensus across multi-agent proposals and tamper-evident session sealing.
      15
      MIT