
AnnealBridge
io.github.TheTsungYing由 GitHub 帳號 TheTsungYing 發布v0.4.0更新於 Oct 24, 2026
Optimization middleware for AI agents: JSON problem in, verified and ranked solutions out.
概覽
本機 MCP 伺服器,把結構化 JSON 最佳化問題轉成經驗證與排序的解,供 AI 助理使用。
- 可以做什麼
- 求解組合最佳化問題:支援二元或有界整數變數、線性或二次目標、硬性約束或軟性約束,回傳依原始問題重新驗證並排序的解,並標示是否已證明最佳。在求解前驗證問題文件,一次列出所有錯誤與修正建議。查詢後端清單與能力,並取得針對某問題的後端建議(僅供參考)。以資源形式讀取內建範例問題文件與完整問題 schema。透過提示詞引導助理把常見情境(子集挑選、指派、排班)寫成問題文件。
- 適用情境
- 適合助理需要回答背包、指派、排班、考試時間表等離散最佳化問題,並希望給出經驗證的數字而非猜測時使用。也適合在執行前驗證或草擬最佳化問題 JSON。
- 執行需求
- 透過 uvx(或 pipx、絕對路徑的 pip 安裝)以 stdio 在本機執行;首次執行會下載 numpy、dimod 等相依套件,建議先預熱快取以免主機啟動逾時。使用遠端廠商後端還需廠商憑證並將 ANNEALBRIDGE_ALLOW_REMOTE 設為 true。伺服器本身未宣告驗證。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 AnnealBridge,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
AnnealBridge
[CI] [PyPI] [Python 3.11+] [License: MIT]
English | 繁體中文
Combinatorial optimization middleware for AI agents. An agent describes what to optimize as structured JSON; AnnealBridge decides how to encode and solve it, checks every answer against the original problem, and returns ranked, verified solutions over MCP, a CLI, or plain Python.
Quick start
A 0/1 knapsack: four items, capacity 10, maximize value. No file needed.
Domain failures come back as results, never as exceptions: result.status
is one of success, infeasible, invalid_problem,
resource_limit_exceeded, backend_unavailable, configuration_error or
solver_error. See docs/output-format.md.
Optional extras:
[gpu] is deliberately not part of [all]: PyTorch is a large download,
and on Windows the wheel PyPI serves is the CPU-only build, so a CUDA run needs
torch installed from PyTorch's own index first — see
docs/backends.md.
Use it from an AI agent (MCP)
With uv installed, add the server to
claude_desktop_config.json (or your host's equivalent) and restart the
host; where Claude Desktop, Claude Code and Codex keep that configuration is
listed in docs/mcp.md.
The first run fetches the package into uvx's own cached environment; that
download — numpy, dimod, dwave-samplers and the rest — can take tens of
seconds, long enough for a host's start-up timeout to show the server as
disconnected. Warm the cache once in a terminal first:
It resolves the environment and prints the version; from then on the host starts from that cache.
Claude Code registers it in one line:
Optimizing is then an ordinary chat:
You: I can carry 10 kg. Item A is worth 10 and weighs 6, B is worth 8 and weighs 5, C is worth 7 and weighs 4, D is worth 6 and weighs 3. Which ones should I take?
Behind the reply, the agent writes the request as problem JSON and calls
solve_optimization. Every solution comes back re-validated against the
original constraints, with optimality_proven: true on the exhaustive
exact backend; a document the server rejects comes back as
invalid_problem with every error and a fix for each, which the agent
applies before sending it again. Before solving on a remote backend, or on
a large problem, it calls validate_optimization_problem first, so a mistake
costs nothing; it calls get_optimization_capabilities when it needs the
backend list or the full schema.
Agent: Take A and C: value 17 at exactly 10 kg. The runners-up are A and D (16, at 9 kg) and B and C (15, at 9 kg). This is the proven optimum.
The wording is the agent's; the numbers are the tool result. Another tool,
recommend_backend, ranks the backends for a problem and is advisory only;
when you did not name a backend and more than one local backend fits, the
server instructions tell the agent to show the top entries and ask which to
run rather than to decide for you.
If your host lists prompts in its input menu, three of them — pick_subset,
assign and schedule_shifts — walk the agent from your own sentence to a
problem document of that everyday shape, which it then solves. The server
also serves resources: the seven
example documents under annealbridge://examples/ and the full problem
schema at annealbridge://schema, so an agent can read a complete example or
the schema itself instead of guessing.
What it is not for. AnnealBridge does not handle continuous
(real-valued) variables, non-linear objectives or non-linear constraints.
Only exact proves that an answer is optimal or that no feasible one
exists, and by default it takes at most 24 compiled variables (slack bits
included); the other local backends (simulated_annealing, tabu,
simulated_bifurcation) are heuristics whose best answer may not be the
optimum. See the
Backends table below and
docs/limitations.md.
Any stdio-capable MCP host works the same way, a streamable-http transport
exists, and pipx or a pip-installed server behind an absolute path work in
place of uvx. uvx reuses the environment it resolved on its first run, so
a new release reaches an existing install only after uv cache clean annealbridge and a host restart; see docs/mcp.md.
Use it from the command line
Save the problem JSON below as knapsack.json, then:
Elapsed is the service's own wall clock and varies from run to run. Add
--json for the full SolveResult, --backend simulated_annealing to
override the backend, or try validate, recommend, capabilities,
example and export-schema. See docs/cli.md.
The problem JSON
The document behind the MCP and CLI examples above, the reduced form of examples/knapsack.json:
Integer variables ("type": "integer" with bounds, "version": "1.1"),
cardinality constraints — exactly, at most or at least k of a set of binary
variables, a hard at-most-one compiling without slack variables
("cardinality_constraints", "version": "1.2") — templates that write a
large, regular model once over index sets and let the server expand it
("index_sets", "parameters", "variable_families" and the *_templates
lists, "version": "1.3"), quadratic objective terms, soft constraints with
weights and per-backend solver preferences are described in
docs/problem-format.md.
annealbridge export-schema prints the JSON Schema an agent can use for
structured output.
Seven ready-to-run examples live in the repository —
knapsack,
assignment,
TSP,
integer knapsack,
shift scheduling,
exam timetabling
(cardinality constraints) and
TSP with templates
(the TSP written once over index sets; annealbridge expand prints what it
expands to).
The installed package carries the same files: annealbridge example lists
them and annealbridge example knapsack > knapsack.json saves one (or pipe it
straight in with annealbridge example knapsack | annealbridge solve -); the
MCP server serves the same seven documents as the resources under
annealbridge://examples/.
How it works
The agent produces an OptimizationProblem: binary or bounded-integer
variables, a linear or quadratic objective, and hard or soft linear and
cardinality constraints. Nothing else. AnnealBridge then, deterministically:
- validates the problem and collects every error in one pass, after expanding any templates into explicit entries;
- compiles it into a BQM or a CQM, computing penalties, slack and integer encodings itself;
- solves it on a local or remote backend;
- re-validates every candidate against the original JSON, never trusting solver energy;
- ranks the feasible solutions and returns the top K with per-constraint evaluations.
An opt-in solver.postprocess step can also repair and locally improve the
best samples in the original variables before ranking; what it produces is
re-validated like any other candidate and marked by each solution's source.
An optional solver.wall_clock_limit_seconds caps how long a solve on a local
heuristic backend may take: when it runs out, the result holds what was
completed, still re-validated and ranked, and says so
(wall_clock_limit_reached). An MCP client that cancels a solve stops it
rather than leaving it to run on.
The agent never writes a QUBO matrix, a penalty weight, a slack variable or an integer encoding, and every step is testable without an AI, a network or a vendor account.
Backends
Eight backends sit behind one protocol.
Remote backends need their vendor credential and
ANNEALBRIDGE_ALLOW_REMOTE=true; without both they report
backend_unavailable. annealbridge recommend ranks the backends for a
problem without solving it and never changes the one you asked for. Setup
and per-backend behaviour: docs/backends.md.
Design guarantees
- Business-level contract in both directions. Variables, objective and constraints in; ranked solutions with per-constraint evaluations out. No solver internals leak either way.
- Two compiler paths. BQM (automatic penalties, binary slack, encoded integers) for annealers; CQM (native constraints and integers) for the Leap hybrid CQM solver. The backend chooses by declaring what it supports.
- Bounded integers without exposure.
"version": "1.1"adds integer variables with the encoding hidden;1.0behaviour is pinned by a golden test. - Counting rules said as such.
"version": "1.2"adds cardinality constraints — one-hot, at most k, at least k over binary variables — and a hard at-most-one compiles to a pairwise penalty without slack variables;1.0and1.1behaviour is pinned by a compatibility golden. - Large models written once.
"version": "1.3"adds index sets, parameter tables, variable families and templates, which the server expands into ordinary variables, terms and constraints before anything else; errors point back at the template, and a size ceiling refuses an oversized expansion whole instead of truncating it.1.0–1.2behaviour is pinned by the existing goldens. - Structured failures, never exceptions. Every outcome is a
SolveResultwith astatus; every failure carries a stable error code with arecommended_action.infeasibleis an answer, not a failure. - No silent decisions. An unavailable backend is reported, never swapped. An over-limit parameter is rejected, never clamped. An undeclared field is rejected, never ignored. Validator warnings travel with every solve result.
- Safe by default. Remote execution and remote retries are off until enabled; every limit is an environment variable enforced as an error; vendor credentials are redacted from results, logs and error messages. The streamable-http transport has no authentication; keep it on a private network. See docs/security.md and SECURITY.md.
- Enforced architecture. Import boundaries, "no backend names in the orchestration, validation or interface layers", and "a new backend plugs in without touching the pipeline" are tests, not conventions.
Documentation
The pages below live under docs/.
Development
pytest runs the full suite with no skip and no xfail and never touches the
network; the live vendor tests are opt-in (pytest -m remote). To install the
development version without a checkout:
pip install "annealbridge[all] @ git+https://github.com/TheTsungYing/AnnealBridge.git".
Architecture rules, design principles and the pull-request checklist are in
CONTRIBUTING.md.
Version 0.4.0: the problem contract (1.0 / 1.1 / 1.2 / 1.3), the eight
backends, the CLI and the MCP tools are complete and covered by tests. What is
not supported, by design for now, is listed in
docs/limitations.md;
changes are in CHANGELOG.md.
License
來源:README.md,提交 b6fffd0
工具
0版本歷史
3- v0.4.0最新Sep 29, 2026
- v0.3.0Sep 22, 2026
- v0.2.1Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分