LoopGauge

LoopGauge

MCP server that experiments with cheaper LLM policies (model, prompt, reasoning, retry, escalation) against project tasks to recommend the lowest-cost policy that meets quality constraints.

Category
访问服务器

README

LoopGauge

English | 한국어

CI Node.js 22+ License: MIT

Find the cheapest LLM policy that still passes your project's quality gate.

LoopGauge is a provider-neutral experiment harness. Unlike a request router, it runs cheaper model, prompt, reasoning, retry, and escalation policies against representative project tasks before recommending one.

It does not choose an AI company for you. You enter the provider and the model you currently use. That model becomes the teacher baseline; LoopGauge discovers cheaper coding-capable candidates only from the same provider and refuses every other company.

Status: experimental MVP. Run it on representative tasks in a disposable project before relying on its recommendations.

60-second API-free demo

git clone https://github.com/josephuk77/LoopGauge.git
cd LoopGauge
npm ci
npm run demo

The demo makes zero provider calls. It replays synthetic observations to show why LoopGauge rejects the cheapest policy below the quality gate and selects the cheapest eligible guarded policy.

PASS  sonnet-verify     quality  97.4  success 100%  $0.072/approved
FAIL  haiku-direct      quality  89.1  success  80%  $0.026/approved
PASS  haiku-guarded     quality  96.4  success 100%  $0.057/approved

Selected: Claude Haiku 4.5 + validation + Opus escalation

These values are explicitly synthetic and are not a model-performance or savings claim. See the benchmark methodology before publishing real results.

What it measures

Before optimization, LoopGauge reports a price-based savings range, candidate models, assumptions, and confidence. After real runs, it reports:

  • measured and amortized cost savings;
  • functional quality and quality relative to the teacher baseline;
  • behavioral/structural/text similarity and the inverse difference score;
  • success rate and cost per successful task;
  • optimization spend and break-even run count;
  • only improvement opportunities supported by observed experiments.

Quality is a constraint, not something that can be traded away invisibly:

  1. reject candidates that fail mandatory build or test checks;
  2. reject candidates below the configured baseline ratio (95% by default);
  3. among eligible candidates, choose the lowest cost per successful task.

Architecture

Codex / Claude
      │ MCP
      ▼
LoopGauge CLI + MCP server
      ├── provider policy gate
      ├── OpenAI Codex adapter
      ├── Anthropic Agent SDK adapter
      ├── isolated Git worktrees
      ├── validation + similarity scoring
      ├── budget-bounded search loop
      └── SQLite state + JSONL traces

The adapters normalize sessions, events, tool usage, tokens, cost, cancellation, and final results. The optimizer varies automatically discovered same-provider models, reasoning effort, prompt policy, tool policy, verification, retry, and escalation back to the user's current model.

Why this is not another router

Request router LoopGauge
Chooses a model for a live request Experiments before recommending a production policy
Often predicts task difficulty Measures actual project checks and results
Optimizes per-call routing Optimizes total cost per successful task
May omit failed and retry cost Includes retry, judge, failure, and escalation cost
Returns a routing decision Returns evidence, quality scores, savings, and break-even

Requirements

  • Node.js 22 or newer
  • Git
  • API keys for the providers you select
  • a committed, clean Git project to optimize
  • at least one representative task; three to five are recommended

Credentials are read from OPENAI_API_KEY/CODEX_API_KEY and ANTHROPIC_API_KEY. They are never written to loop.yaml, SQLite, or JSONL traces. Library consumers can supply another CredentialResolver, including an OS credential-store implementation.

Install and build

npm install
npm run build
npm test

Run the local CLI without a global install:

node dist/cli.js help

Configure a project

The company and current model are the only model choices the user must make:

# Current workflow uses OpenAI GPT-5.6
node dist/cli.js init --provider openai --model gpt-5.6 --name my-project

# Current workflow uses Anthropic Claude Sonnet 5
node dist/cli.js init --provider anthropic --model claude-sonnet-5 --name my-project

Edit the generated loop.yaml before running anything:

  • verify setup/build/test/lint/typecheck commands;
  • replace the sample tasks with real recurring work;
  • optionally set baselinePatchPath to compare against an existing result.

On analyze, LoopGauge queries the selected provider's Models API when an API key is available, intersects that response with its dated coding-model price catalog, and selects up to maxCandidates models that are both lower-ranked and cheaper than the current model. It removes candidates dominated on both capability and price, while retaining close-quality choices and the cheapest endpoint. If the API cannot be reached, it falls back to the built-in catalog and reports that fact as a warning. It never discovers candidates from another provider.

The built-in catalog is dated 2026-07-16 and is based on the official OpenAI model catalog, OpenAI Models API, Anthropic model overview, and Anthropic Models API. Every optimization report records the catalog timestamp.

CLI workflow

# Read-only project detection plus preflight estimate
node dist/cli.js analyze --config loop.yaml

# Run teacher/candidate experiments in disposable worktrees
node dist/cli.js optimize --config loop.yaml

# Inspect a completed job
node dist/cli.js report --job JOB_ID --config loop.yaml
node dist/cli.js compare --job JOB_ID --config loop.yaml

# Run the selected policy; returns a patch without modifying the source checkout
node dist/cli.js run --job JOB_ID --prompt "Implement the next task" --config loop.yaml

# Continue a cancelled or interrupted job using persisted completed runs
node dist/cli.js optimize --resume JOB_ID --config loop.yaml

State lives under .loopgauge/:

  • loopgauge.db: jobs, evaluated runs, and reports;
  • events/*.jsonl: replayable agent and job events;
  • generated/: provider-specific instructions only for selected providers.

Temporary Git worktrees are created under the operating system temp directory and removed after every run.

MCP tools

Start the stdio server:

node dist/mcp/server.js

It exposes:

  • analyze_project
  • estimate_savings
  • optimize_harness
  • get_optimization_status
  • cancel_optimization
  • resume_optimization
  • run_optimized_task
  • compare_results
  • get_cost_report

Local MCP configuration shape for either client:

{
  "mcpServers": {
    "loopgauge": {
      "command": "node",
      "args": ["/absolute/path/to/LoopGauge/dist/mcp/server.js"]
    }
  }
}

Use the client-specific MCP configuration location documented by Codex or Claude Code.

Scoring and cost accounting

Default functional quality weights:

Component Weight
Build and tests 60
Requirement grader 20
Regression checks 10
Lint and type checks 10

Default result similarity weights:

Component Weight
Behavioral check outcomes 70
Public API / structural tokens 20
Normalized text diff 10

The difference score is 100 - similarity. A score is evidence for a defined test set, not proof that two models think alike or will behave identically on arbitrary future work.

Cost includes input, output, cache reads/writes, configured tool charges, retries, optional judge runs, and opt-in escalation. If an SDK reports authoritative run cost, LoopGauge uses it while retaining the token-level breakdown. Every report records its price-catalog timestamp.

Safety boundaries

  • Optimization requires a clean repository and at least one commit.
  • Experiments run with bounded iterations and budgets in detached worktrees.
  • Network access is off by default.
  • Provider/model policy is checked immediately before every agent call.
  • Automatic discovery never crosses the provider selected for the current model.
  • API/provider failures are persisted and scored as failures rather than silently ignored.
  • LoopGauge does not collect or imitate hidden chain-of-thought; it optimizes observable prompts, actions, checks, costs, and outcomes.

Development

npm run typecheck
npm test
npm run build

The test suite covers provider deny-by-default behavior, price accounting, quality gates, similarity scores, the API-free demo, and a real temporary Git-worktree optimization run.

Project resources:

The package is prepared for a public npm release but has not been published yet. Until then, use the local build shown above.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选