AGENT SKILL

minions-llm-proxy-ops

Use when operating or debugging the .minions LLM proxies.

License 许可
MIT
所属仓库
gitricko/.minions
最近更新
2026-11-13
Stars
★ 2
Forks
2

01 前言 Front Matter

name
minions-llm-proxy-ops
author
.minions maintainers
license
MIT
version
0.1.0
metadata
{ "hermes": { "tags": [ "9router", "omniroute", "opencode", "llm-proxy", "free-tier", "combos" ], "related_skills": [ "docker-test-shell", "version-single-source" ] } }
description
Use when operating or debugging the .minions LLM proxies.

02 资源文件 3

03 SKILL.md 正文

.minions LLM proxy stack ops

When to Use

  • A model or combo through 9Router (:7352) or OmniRoute (:20128) errors, 403s, rate-limits, or returns empty content.
  • opencode.ai free tier (oc/ models) breaks — FreeTierError, "Model is unavailable", or silent empty responses.
  • The auto-fastest combo needs its model list refreshed or reordered.
  • You need to change 9Router provider headers, combos, or settings so they survive reboots (i.e. via lib/9router.sh).

The stack (boot.sh) runs OmniRoute (:20128) and 9Router (:7352). 9Router routes auto-fastest (a combo) to free OpenCode (oc/) models; OmniRoute is the upstream LLM proxy for Hermes. lib/9router.sh (ninerouter_preconfigure) re-applies 9Router config idempotently on every boot — edit it there so config survives restarts, and use its API calls as the reference for ad-hoc changes.

Always-on rules

  • Verify a proxy change with real completions, never HTTP status alone. 9Router's combo fallback counts an empty finish_reason:"in_progress" (or finish_length with 0 visible tokens) response as SUCCESS, so a combo whose first model is silently broken returns empty content forever without ever falling back. Pass signal = non-empty choices[0].message.content; empty content is a failure regardless of finish_reason (free models sometimes return correct content with finish_reason:"length", so don't require stop). A 2xx with empty content is a failure.

  • Lead a combo with the known-good model. Since fallback only fires on hard errors, put the model that actually produces content FIRST in the combo model list; put flaky/unverified models after.

  • Free-tier model lists rotate. Query the live list before trusting any hardcoded model id: curl -s https://opencode.ai/zen/v1/models (only ids ending -free / -contributor-free are actually free). A stale id either hard-errors or silently returns empty — both degrade the combo.

  • 9Router dashboard login: default password 123456; cookie session via POST /api/auth/login. All admin APIs need the cookie (-b "$COOKIE"). requireLogin/requireApiKey are disabled by preconfig.

  • 9Router combo model list lives in etc/9router-models.json (single source). 9Router only — lib/omniroute.sh is NOT wired to it. lib/9router.sh reads that file at boot — never duplicate the list inline in a shell script. tests/test_9router_models.sh (blocking CI) is an OFFLINE structural guard; scripts/sync-9router-models.sh owns upstream drift (--check/--write) and live probing (--probe, --probe-write need a running 9Router on :7352: keep 200/429, drop 400/410).

  • Config lives in 9Router's own DB, keyed by canonical provider id. PUT /api/providers/<id>/overrides REPLACES the whole header map for that provider (idempotent; send the full map each time). POST /api/combos + DELETE-by-id is how combos are recreated (there is no PUT on combos).

Standard procedure: audit/fix a provider's routing

  1. Log in and save a cookie: curl -s -c /tmp/nr.txt -X POST $BASE/api/auth/login -H 'Content-Type: application/json' -d '{"password":"123456"}'
  2. Inspect current state: GET /api/combos, GET /api/settings, GET /api/providers/<id>/overrides (shows headers + builtinHeaders).
  3. If upstream 403s / rejects: set header overrides (see references/opencode-free-tier.md for the OpenCode-specific header set and session-id generator).
  4. Fix the combo model list against the LIVE free list (step above), known-good model first.
  5. Test with a real prompt at >=128 max_tokens (small budgets get eaten by reasoning tokens and look like empty failures): POST /v1/chat/completions {"model":"auto-fastest","messages":[...],"stream":false,"max_tokens":128} Assert non-empty content. To validate a combo's model list, test each member individually the same way — bare ids route directly (model=oc/<id>), so you can run them in parallel and prune dead ids before recreating the combo. If a model errors, read ~/.minions/var/log/9router.log — it logs the upstream URL, status, and provider-side error body.
  6. Any change must land in lib/9router.sh or it is lost: the boot preconfig deletes and recreates combos (and re-puts overrides) every boot, so live-only edits — dashboard or ad-hoc API — silently revert on next boot. Edit the script, then let boot apply it, or apply + edit together.

Add an OpenAI-compatible provider (OmniRoute :20128), wire a model into auto-fastest

Two prepared helpers in scripts/ (this repo: skills/minions-llm-proxy-ops/scripts/; standalone install: ~/.minions/skills/minions-llm-proxy-ops/scripts/). Both idempotent, both --dry-run capable, same 5 REST steps. Pick by the upstream's shape:

Upstream shape Script Key env
Local keyless OpenAI-compatible peer (Ollama etc.), single known model add-tailscale-provider.sh <host[:port]> TSC_PORT, MODEL_NAME, PROVIDER_NAME (defaults: 11434, qwen3.8:27b, tailscale)
Auth'd hosted OpenAI-compatible API (GitHub Copilot), discover models, context-window filter (≥128k), probe + wire all keepers add-ghcodespace-provider.sh (or --renew to just rotate the token) GHPILOT_BASEURL, GITHUB_TOKEN (auto via codespace-gh-auth), PROVIDER_NAME (default ghcodespace), MIN_CONTEXT_K (default 128; 0 = off)

Choosing the baseUrl shape — the most common mistake: check the upstream first, not a template. baseUrl is appended with the chat/models path. Tailscale peer uses /v1/chat/completions; a hosted endpoint like https://api.individual.githubcopilot.com uses /chat/completions (bare, no /v1). Register the wrong one and every completion 404s through the proxy with no local trace. Verify both shapes with a 2-line curl before writing the node body:

curl -sI $BASE/chat/completions        # expect 405 (method) or 401, NOT 404
curl -sI $BASE/v1/chat/completions     # the other one

Whichever is the real one sets baseUrl shape. add-tailscale-provider.sh forces …/v1; add-ghcodespace-provider.sh uses the bare domain. For a new upstream with a different path shape, override the base URL by env and set chatPath on the node to the bare path (e.g. "/chat/completions") — never a string starting with /v1/. The server generates the concrete id openai-compatible-chat-<uuid>; that uuid is the provider id stored on the combo entries.

Dummy vs real credential: the tailscale helper stores a dummy apiKey — OK because the local peer ignores auth. For an endpoint that enforces Bearer (like api.individual.githubcopilot.com), the connection apiKey must be the real token — a dummy still registers but every completion 401s. add-ghcodespace-provider.sh sources codespace-gh-auth skill (or an inline fallback) to obtain the ghu_ token and redacts it in human-visible output (ghu_****(len=N)); pass GITHUB_TOKEN=… to skip extraction.

Token rotation (--renew) — the Codespace reboot case. The OmniRoute config (node, connection, imported models, auto-fastest combo) survives a Codespace reboot, but the ghu_ PAT is re-issued on every restart — so the existing ghcodespace connection holds a stale (dead) token after a reboot, and requests 401. --renew handles exactly this case (2026-11-01, live-verified):

skills/minions-llm-proxy-ops/scripts/add-ghcodespace-provider.sh --renew
  • Finds the existing ghcodespace node/connection, then DELETE /api/providers/<cid> then POST /api/providers with the freshly-extracted ghu_ then PUT isActive. Node / imported models / auto-fastest combo are left untouched — no re-discovery, no re-probing. Idempotent: safe to run after every restart.
  • The fresh PAT is re-extracted via the same codespace-gh-auth skill path; if no node or connection is found, it falls through to the full wire.
  • The "auth expired" latch (401 "All credentials authentication expired") is the classic symptom: updating the key in-place does not clear it — a real completion test must pass first. Recreate + activate + a live /models gate (the last step of --renew) clears the latch as a side effect.
  • Dry-run: DRY_RUN=1 … --renew prints the planned delete + recreate without touching OmniRoute.

Model auto-discovery + probe (add-ghcodespace-provider.sh):

  • GET <base>/models with Bearer → ids plus each model's capabilities.limits.max_context_window_tokens. Context-window floor: MIN_CONTEXT_K (default 128) drops models below the floor before probing (embeddings report no context → dropped with a positive floor; set MIN_CONTEXT_K=0 to accept everything). Fallback roster if no parsable ids above the floor.
  • For each candidate, one real completion (max_tokens=8, polite delay). Classification (mirrors lib/9router.sh + the minions-9router-models pass/fail rule): 200 + non-empty content or 429 → keep; 400/404/410/403/401 → drop; 5xx → retry ×3 with backoff then drop. GitHub Copilot 400 codes all mean drop — model_not_supported and no model endpoints available given user constraints are server-side entitlement gates, not misconfigurations (2026-11-01: all 4 mai-* ids return these from every lane; the GPT-4o family is the kept set). Catalog policy.state=enabled is not entitlement — the dispatch table decides per credential; an enabled id can still 400.
  • Exclude non-chat auxiliaries before the probe: text-embedding-* and copilot-search-* entries respond to a ping but aren't chat LLMs — including them in a chat-completions combo pollutes routing.
  • Never register a router alias (e.g. auto) as a model. auto is not in the /models roster — it's a server-resolved alias. On the free-tier Codespace PAT it resolves to MAI (A/B bucket autov2_mai_prod), which then 400s (2026-11-01: 81/81 auto probes across 3 lanes × 27 integration ids were model_not_supported). Registering auto would add a 100%-fail entry that rots auto-fastest fallbacks. Register only real model ids the credential actually serves — here, the GPT-4o family.
  • Import the keepers and append to the existing auto-fastest combo (never duplicated, existing entry shapes preserved verbatim).

The five REST steps below are the verified sequence (OmniRoute 3.8.53) and how the scripts work — use them as the manual/API reference for any new upstream that only needs a base URL:

  1. Create the NODE — POST /api/provider-nodes with {name, type:"openai-compatible", baseUrl:"http://<host:port>/v1", prefix:name, apiType:"chat"}. baseUrl MUST end in /v1 (the base for the OpenAI-compatible endpoints) and OMIT chatPath/modelsPath entirely — the server stores them null (its own default), which is the correct shape. The server generates the concrete id openai-compatible-chat-<uuid> — that uuid IS the provider id used by /api/providers and combos. Pitfalls (verified against OmniRoute 3.8.53): explicit null → 400 Invalid input (so omit the keys, don't null them); non-null strings like "/v1/chat/completions" → 201 but wrong — they double the /v1 baseUrl already carries, producing .../v1/v1/.... If you ever DO set them, use bare "/chat/completions" or "/models" (no /v1).
  2. Create the CONNECTION — POST /api/providers with {provider:"<node-id>", name, apiKey:"<any non-empty string>", priority, providerSpecificData:{prefix, apiType:"chat", baseUrl, nodeName:name}}. Pitfall: a keyless connection is rejected ("API key is required" / "does not allow a connection without a credential"). The key value is ignored by the upstream; a dummy credential is fine. omniroute providers add openai-compatible … fails with Invalid provider because the CLI will not accept the abstract type — the node must exist first and the concrete id must be passed.
  3. Activate — PUT /api/providers/<cid> {"isActive":true}. The connection is created isActive:false; activation returns testStatus:"active" immediately when the upstream is reachable.
  4. Import the model — POST /api/provider-models {provider:"<node-id>", modelId}. The alternate validate-and-add endpoint requires a real Authorization header on this deployment and 401s — use the plain one.
  5. Append to auto-fastest — GET /api/combos, find auto-fastest, add {id:"<combo>-model-<name>-<model>", kind:"model", model:"<name>/<model>", providerId:"<node-id>", weight:0} to models[], then PUT /api/combos/<id> with the FULL body {name, strategy, enabled, config, models}. Pitfall: PUT rejects a body that has only models (COMBO_001 Invalid JSON body). POST /api/combos upserts by name, so it works for both create and re-list.

Teardown (safe): omniroute providers remove <name> --yes does an exact name match (no substrings) — verified in resolveRemoteConnection → findConnectionFromResponse. DELETE /api/provider-nodes/<node-id> removes the node. To strip a line from a combo: PUT /api/combos/<id> with the filtered models (don't send id/sortOrder/isHidden in the body).

Watch for server-side side effects: the OmniRoute ModelSync job runs on a timer and has been observed removing an existing duplicate connection on the same provider node during an unrelated create/delete window (2026-10-23, main-2 on the ollama node vanished while adding/removing a different node). Always snapshot GET /api/providers plus the provider_nodes / provider_connections rows before and after, so collateral damage is caught and reported, not hidden.

Pitfalls

  • Don't test with tiny max_tokens (16–32): free models spend the budget on reasoning tokens and return empty finish_reason=length, which looks like a routing bug but isn't.
  • Don't assume curl -f passing means the combo works — a 2xx empty-body response passes -f. Parse the JSON body.
  • Free-tier endpoints are flaky: a 429/"Endpoint is unavailable" on one model is usually transient per-model, not a config error — try the other combo members before changing config. The opposite case is a deterministic 400 Upstream request failed: Model is unavailable that reproduces across retries and token budgets: that's a dead id — drop it from the combo and sync lib/9router.sh.
  • Some model ids need a different protocol than openai chat completions and fail with ModelProtocolUnsupported — exclude them from the combo rather than trying to force them.
  • Codespace restarts rotate the ghu_ token (it lives in the vscode-server process env, not a file — restart = new PID = new token). The OmniRoute connection holds the old one and latches into authentication_error / "All credentials expired" — that state persists even after PUT /api/ providers/<id> with a fresh apiKey. Canonical fix (2026-11-01): skills/minions-llm-proxy-ops/scripts/add-ghcodespace-provider.sh --renew — finds the existing connection, DELETE + re-POST it with the freshly extracted ghu_, then runs a /models gate that clears the latch. Node / models / combo untouched. Idempotent — safe to run after every restart. Manual fallback if the script path fails: (1) extract from the live process (/proc/$(pgrep -f server-main.js | head -1)/ environ, GITHUB_TOKEN= line), PUT it to the ghcodespace connection's apiKey; (2) run bin/omniroute test <node> <any-served-model> — a single successful check clears the latch. Until (2), real completions still 401 with the stale-key error even though the stored key is fresh.

OmniRoute (:20128) does NOT accept this fix

The OpenCode header override is 9Router-specific. Verified live against OmniRoute 3.8.51 — do not waste time re-attempting it:

  • OmniRoute has no /api/providers/<id>/overrides equivalent.
  • Its open-sse build synthesizes OpenCode headers natively with OPENCODE_CLIENT / OPENCODE_USER_AGENT env knobs (in ~/.omniroute/.env, loaded at startup). Setting OPENCODE_CLIENT=cli + the UA and restarting does NOT clear the 403.
  • Passing the full x-opencode-* header set on the request itself changes the error from FreeTierError to No active credentials for provider: opencode — OmniRoute treats a valid CLI identity as a keyed account, not a bypass.
  • POST /api/providers/free-onboarding returns "not eligible" for opencode and opencode-zen — a real account/credential is required.
  • OmniRoute's combo also rots: opencode-zen/mimo-v2.5-free → 410 deprecated.
  • If the OpenCode free tier must be used, route through 9Router (:7352) — it already has the working fix.

See also

  • wiki/codespace-copilot-llm.md — how the Codespace Copilot panel reaches GitHub's LLM backend; endpoint-shape discovery.
  • wiki/codespace-copilot-mitm-handoff.md — capture findings: auto→MAI-Prod verdict, MAI-variant 400 dictionary, MITM restart/revert playbook.
  • skills/codespace-service-discovery/ — the generic "find the backend of X" method this stack's wiring started from.

04 同仓库更多 Skills