多步LLM代理工具治理会话承诺系统

PlanGate是一个MCP兼容的网关,通过多步会话语义对齐准入决策,减少多步LLM代理工作负载中的治理引起的级联计算浪费。

  • by GaussGeorge
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 GaussGeorge/mcp_gateway

使用说明

# PlanGate:多步骤LLM代理工具治理的会话承诺

PlanGate是一个与MCP兼容的网关,可以减少 治理引发的级联计算浪费 在多步骤LLM代理工作负载中,通过将准入决策与多步骤会话对齐 语义——强制 会议承诺:原子准入、时间隔离和 延续价值。

对于计划准确的P&S会议,PlanGate可防止价格导致的会议中期拒绝 在申报的计划范围内。对于ReAct会话,它减少了执行过程中的放弃 通过沉没成本意识的持续定价。

代理类型 承诺 机制
计划和解决(P&S) 预留预算 飞行前DAG入场+锁定价格
ReAct 软延续激励 K^2沉没成本折扣定价

另外, PlanGate-R 是否评估了检查点感知恢复扩展 在受控的模拟运行时中(仅P&S;没有真正的LLM;没有ReAct语义 恢复)。这不是主要贡献。


仓库结构

cmd/gateway/          Go gateway entry point (main.go)
plangate/             Core Go package: admission, pricing, DAG validation,
                      checkpoint/recovery, reputation
baseline/             Baseline gateway implementations (NG, SRL, SBAC,
                      DAGOR, Rajomon, ProgressPriority)
mcp_server/           Python MCP backend + tool implementations
  server.py           ThreadPoolExecutor MCP server
  tools/              calculator, weather, web_fetch, mock_heavy,
                      llm_reasoner, deepseek_llm, ...
scripts/              Experiment runner, analysis, and plotting scripts
  run_all_experiments.py        Main mock experiment driver
  run_exp_real3_all.sh          Real-LLM (GLM/DeepSeek) experiment driver
  reproduce_mock_core.sh        Reproducibility: mock core experiments
  reproduce_main_paper_from_cache.sh  Re-generate figures from CSV cache
  gen_paper_figures.py         Paper figure generator
docs/                 Artifact documentation
  REPRODUCIBILITY.md  Full reproduction guide with expected runtimes
  RESULT_MAPPING.md   Maps paper items to data files
  experiment_code_mapping.md

需求

要求 版本 注释
前进 >=1.23 go version
Python >=3.10 python --version

安装Python依赖项:

pip install -r mcp_server/requirements.txt

构建网关二进制文件:

go build -o gateway ./cmd/gateway
# Cross-compile for Linux:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o gateway_linux ./cmd/gateway

快速启动:烟雾测试(无需API键)

所有单元测试和模拟实验都在没有任何真正的LLM提供者的情况下运行。

# Run full Go test suite
go test ./... -timeout 120s

# Run plangate package tests only
go test ./plangate/... -timeout 120s -v

预期产量: ok mcp-governance/plangate, ok mcp-governance/baseline, ok mcp-governance.

最小端到端模拟烟雾测试:

# 1. Start the Python mock backend
python mcp_server/server.py --host 127.0.0.1 --port 8080 --max-workers 10 &

# 2. Start the PlanGate gateway in mock mode
./gateway --mode mcpdp --backend http://127.0.0.1:8080 --port 9200 \
          --max-sessions 200 --base-price 10 --alpha 0.5 &

# 3. Smoke test (50 sessions, no API key needed)
python scripts/smoke_test_multitool.py \
    --gateway http://127.0.0.1:9200 --sessions 50

运行受控模拟实验(第1层)

# All 12 mock experiments, 5 repeats each
python scripts/run_all_experiments.py --exp all --repeats 5

# Single experiment
python scripts/run_all_experiments.py --exp Exp1_Core --repeats 5

# With CPU isolation (Linux/WSL2)
python scripts/run_all_experiments.py --exp all --repeats 5 \
    --gateway-binary ./gateway_linux \
    --cpu-backend 8-15 --cpu-gateway 4-7 --cpu-loadgen 0-3

结果已写入 results/exp1_core/, results/exp2_heavyratio/等等。 这 results/ 目录被排除在公共仓库之外(请参见 .gitignore).


再现关键结果

公共存储库包含源代码,没有密钥最小复制命令。 此公共分支中不会跟踪真实LLM实验的完整缓存跟踪; 它们通过会议工件提交机制单独分发, 不是公开的GitHub版本。

模拟核心实验可以从头开始重新运行:

# Re-run mock core experiments from scratch (no API key, ~30–45 min)
bash scripts/reproduce_mock_core.sh

# Re-generate paper figures from local CSV results (after re-running)
python scripts/gen_paper_figures.py

看 docs/可复制性.md 有关完整说明, 预期运行时间和故障排除。 看 docs/RESULT_MAPPING.md 用于纸张映射 将项目转换为特定的数据文件。


运行真实的LLM实验(第2/3级)

Real-LLM实验需要提供程序API密钥。复制 .env.example 到 .env 并填写 LLM_API_KEY:

cp .env.example .env
# Edit .env and set LLM_API_KEY, LLM_API_BASE, LLM_MODEL
# Tier 2: Steady real-LLM (GLM-4-Flash or DeepSeek-V3)
bash scripts/run_exp_real3_all.sh                    # default: GLM-4-Flash
bash scripts/run_exp_real3_all.sh --deepseek         # DeepSeek-V3

# Tier 3: Bursty real-LLM
python scripts/run_real_llm_bursty.py --repeats 3 --burst-size 30

网关策略

策略 模式标志 描述 来源
无政府(NG) ng 传递,无治理 baseline/ng_gateway.go
SRL srl 静态速率限制器(令牌桶) baseline/srl_gateway.go
SBAC sbac 基于会话计数的录取 baseline/sbac_gateway.go
达戈尔。 dagor RTT阈值过载检测 baseline/dagor_gateway.go
拉乔蒙 rajomon 排队延迟动态定价 baseline/rajomon_gateway.go
进度优先级 pp 步骤进度优先级 baseline/progress_priority_gateway.go
PlanGate mcpdp 会议承诺(这项工作) plangate/, cmd/gateway/

PlanGate-R:检查点感知恢复扩展

PlanGate-R处理公认P&S内可恢复的瞬态后端故障 通过检查点完成步骤并从上次验证的步骤恢复会话 步骤,而不是从头开始。

范围: 仅在受控模拟运行时进行评估(P&S会话、模拟 处理程序,注入可恢复故障,没有真正的LLM)。不是ReAct语义 恢复实验。结果不会转移到真正的LLM或生产中 工作负载,无需进一步评估。

failure_rate=0.3时的关键结果:PlanGate-R与初始重试的最终结果相匹配 成功率(1.000),同时减少66.7%的浪费步骤和总工具调用 每次运行增加10.1%。


最小复现

模拟复制确实如此 不 需要API密钥。 PlanGate-R复制品仅为P&S控制的模拟。 精确的纸质表格需要完整运行;最小烟雾验证了定性趋势。 看 docs/minimalreproduction.md 和 docs/paper_mapping.md 了解全部细节。

1.单元测试(无服务器,无API密钥,<1分钟):

go test ./... -timeout 120s

2.PlanGate核心模拟烟雾-验证PlanGate减少级联与NG/SBAC(无API密钥,约1-5分钟,在Windows上验证1.2分钟):

# Linux / macOS / WSL2
go build -o gateway ./cmd/gateway
python scripts/run_all_experiments.py --exp Exp1_Core --repeats 1 --gateway-binary ./gateway

# Windows PowerShell
go build -o gateway.exe ./cmd/gateway
python scripts/run_all_experiments.py --exp Exp1_Core --repeats 1 --gateway-binary gateway.exe

网关二进制文件在本地构建,并从git中排除。省略 --gateway-binary 让脚本自动构建。

卫生检查: plangate_full.cascade_failed == 0, plangate_full.effective_goodput 最高。

3.PlanGate机构消融烟雾-验证预算锁定事项(无API密钥,约1-3分钟,在Windows上验证0.8分钟):

# Linux / macOS / WSL2
python scripts/run_all_experiments.py --exp Exp4_Ablation --repeats 1 --gateway-binary ./gateway

# Windows PowerShell
python scripts/run_all_experiments.py --exp Exp4_Ablation --repeats 1 --gateway-binary gateway.exe

卫生检查: wo_budgetlock.effective_goodput 低于83% plangate_full.

4.PlanGate-R恢复烟雾-验证检查点恢复/无回放(无API密钥,<2分钟,仅进行Go测试):

go test ./plangate/... -run "TestRuntime" -v -timeout 120s

未包含的内容:

  • paper/ --未发表的草稿,完全排除在外。
  • results/ --大型实验CSV,排除在外(见 .gitignore).
  • 真正的LLM证书——模拟或单元测试不需要。
  • 大型代币化资产(scripts/deepseek_v3_tokenizer/tokenizer.json)--看 scripts/deepseek_v3_tokenizer/README.md.
  • 真实的LLM/vLLM实验(表6-8)是可选的,需要外部设置。

工件注释

  • paper/ 已从该公共存储库中排除。
  • results/ (大型实验CSV)被排除在此公共存储库之外。
  • API密钥:副本 .env.example 到 .env 并填写数值。 模拟实验和所有单元测试都可以 不 需要任何API密钥。
  • 大型外部代币化资产未被跟踪;看见 scripts/deepseek_v3_tokenizer/README.md 如何获得 tokenizer.json 如果令牌会计脚本需要。
  • 用于实际LLM实验的预先计算的缓存CSV跟踪是 不 包含在 这个公共存储库。对于双盲提交,它们是通过以下方式提供的 会议补充伪影机制。

许可证

此存储库在Apache License 2.0下发布。看 许可证 了解详情。


引用

@inproceedings{plangate2026,
  title     = {PlanGate: Session Commitment for Multi-Step LLM Agent Tool Governance},
  author    = {Anonymous},
  booktitle = {Anonymous Submission},
  year      = {2026}
}