Skip to content

Structured multi-perspective deliberation for hard decisions. Run full councils, focused triads, or duo debates across Claude Code, Codex, Gemini CLI, and OpenCode.

feat: wire openai_compatible_api routing for NIM seats (#26)

nyk5d95da24dbf4
diff --git a/SKILL.codex.md b/SKILL.codex.md
index c3f4d02..cd62c98 100644
--- a/SKILL.codex.md
+++ b/SKILL.codex.md
@@ -136,6 +136,17 @@ Wait with `spawn_timeout_ms`. If a seat fails or times out:
If live seats drop below `hard_min_live_seats`, switch to fully simulated mode for all seats and state this explicitly.
+### Step 3.5: OpenAI-Compatible Seats (NIM and future)
+
+For seats whose provider archetype is `openai_compatible_api` (NVIDIA NIM today; Together / Fireworks / vLLM in the future), dispatch via HTTP rather than the host runtime's `spawn_agent`:
+
+- Read `base_url` and `api_key_env` from the seat config (or detection JSON for auto-routing).
+- Resolve the API key from the env var at routing time. Never inline.
+- POST to `{base_url}/chat/completions` with an OpenAI-compatible payload (system+user messages, `temperature: 0.7`, `max_tokens: 1200`).
+- Extract `.choices[0].message.content`. If empty or non-2xx, mark the seat `degraded` and apply the standard fallback (anthropic per the agent's `model` frontmatter).
+- Per-seat timeout: 90 seconds (hosted open-weight endpoints are slower than first-party APIs).
+- The Round 2 anonymization protocol (Step 4) and Chairman selection (Step 5) apply equally to NIM seats — no special-case logic.
+
### Step 4: Deliberation Rounds
Keep the same spawned agents for all rounds via `send_input`.
diff --git a/SKILL.md b/SKILL.md
index f881b55..327a23e 100644
--- a/SKILL.md
+++ b/SKILL.md
@@ -183,7 +183,8 @@ Follow these steps in order. Do NOT skip steps or merge rounds.
- Prefer one provider per seat until pool exhausted
- Avoid placing polarity pair members on same provider when alternatives exist
- If unavoidable, use different model families or reasoning modes
-4. Log routing metadata: member → provider → model
+4. **OpenAI-compatible seats**: when a seat declares a provider whose archetype is `openai_compatible_api` (e.g. `provider: nvidia_nim`, future `together`, `fireworks`, `vllm`), the seat YAML MUST include `base_url` and `api_key_env`. The coordinator resolves the API key from the named env var at routing time — never inline the value. If the env var is unset, mark the seat as unavailable and trigger the per-seat fallback path (Path C anthropic default for that member only). Set `exec_method: openai_compatible_api` for the seat.
+5. Log routing metadata: member → provider → model → exec_method (e.g. `feynman → nvidia_nim → deepseek-ai/deepseek-v4-pro → openai_compatible_api`).
**Path B — Auto-routing** (default when no `--models` and no `--no-auto-route`):
1. Run the detection script via Bash: `bash ~/.claude/skills/council/scripts/detect-providers.sh`
@@ -193,9 +194,10 @@ Follow these steps in order. Do NOT skip steps or merge rounds.
**Auto-routing algorithm** (apply in order):
1. **Polarity pair separation** (hard constraint): For any polarity pair where both members are on the panel, assign them to different providers. Check the `council.polarity_pairs` field in each member's frontmatter.
-2. **Provider spread** (hard constraint): Distribute members across available providers as evenly as possible. With N providers and M members, each provider gets floor(M/N) or ceil(M/N) members.
-3. **Provider affinity** (soft tiebreaker): Use the `council.provider_affinity` field in each member's frontmatter. When choosing which provider to assign a member to, prefer providers listed earlier in their affinity array.
-4. **Tier matching** (soft): Members with `model: opus` in frontmatter get high-tier models per `configs/auto-route-defaults.yaml`. Members with `model: sonnet` get mid-tier models.
+2. **Provider spread** (hard constraint): Distribute members across available providers as evenly as possible. With N providers and M members, each provider gets floor(M/N) or ceil(M/N) members. NIM (`nvidia_nim`) is treated as a single "provider" for spread purposes even though it serves multiple model families — the within-NIM diversity is captured by `models[]`.
+3. **Provider affinity** (soft tiebreaker): Use the `council.provider_affinity` field in each member's frontmatter. When choosing which provider to assign a member to, prefer providers listed earlier in their affinity array. Members whose affinity does not list `nvidia_nim` should be assigned NIM only when no other provider has capacity.
+4. **Tier matching** (soft): Members with `model: opus` in frontmatter get high-tier models per `configs/auto-route-defaults.yaml` `provider_models.<provider>.high`. Members with `model: sonnet` get `.mid`. For NIM, `high` is the largest available reasoning model (default `deepseek-ai/deepseek-v4-pro`); `mid` is a smaller/faster variant.
+5. **OpenAI-compatible seat hydration**: For every seat assigned to a provider with `exec_method: openai_compatible_api`, the coordinator reads `base_url` and `api_key_env` from the detection JSON entry (NIM defaults to `https://integrate.api.nvidia.com/v1` and `NVIDIA_API_KEY`). The resolved API key is held in coordinator state only — never written to logs or transcripts.
**Path C — No routing** (`--no-auto-route`):
Use agent frontmatter `model` defaults (Claude-only). Skip detection entirely.
@@ -290,6 +292,27 @@ ollama run {model} "{full prompt}" 2>/dev/null
```
3. Capture stdout. Timeout: 120 seconds (local models are slower).
+**For `openai_compatible_api` (NVIDIA NIM, Together, Fireworks, vLLM, any OpenAI-compatible endpoint)** — run via Bash tool:
+1. Read and extract identity sections (same as codex_exec above).
+2. Resolve credentials at runtime: read `api_key_env` from the seat config and look up the value from the environment. If the env var is unset or empty, fall back to anthropic per the Fallback rule below — do NOT inline a placeholder.
+3. Read `base_url` from the seat config (e.g. `https://integrate.api.nvidia.com/v1` for NIM).
+4. Construct an OpenAI-compatible `/chat/completions` call:
+```bash
+curl -sS -X POST "{base_url}/chat/completions" \
+ -H "Authorization: Bearer ${!api_key_env}" \
+ -H "Content-Type: application/json" \
+ -d "$(jq -nc \
+ --arg model "{model}" \
+ --arg prompt "{full prompt}" \
+ --arg system "You are operating as a council member in a structured deliberation." \
+ '{model: $model, messages: [{role:"system",content:$system},{role:"user",content:$prompt}], temperature: 0.7, max_tokens: 1200}')" \
+ 2>/dev/null | jq -r '.choices[0].message.content // empty'
+```
+5. Capture stdout as the member's output. Timeout: 90 seconds (hosted open-weight endpoints are slower than first-party APIs).
+6. If the response is empty or jq fails to extract `.choices[0].message.content`, treat as a failed call and apply the Fallback rule.
+
+For auto-detection of NIM specifically (when no `--models` mapping is provided), `scripts/detect-providers.sh` emits an `nvidia_nim` entry with `exec_method: "openai_compatible_api"` and `binary` set to the endpoint URL — the routing algorithm then assigns NIM seats just like any other detected provider.
+
**Fallback**: If any external provider call fails or times out, log `[FALLBACK] {member} failed on {provider}/{model}. Falling back to anthropic/{frontmatter_model}.` and re-run as a Claude subagent. Skip the failed provider for remaining rounds.
**Prompt template** (used for ALL providers — for external providers, inline the identity preamble):
diff --git a/scripts/council-simulation-checklist.sh b/scripts/council-simulation-checklist.sh
index 8612b4b..028724b 100755
--- a/scripts/council-simulation-checklist.sh
+++ b/scripts/council-simulation-checklist.sh
@@ -94,6 +94,15 @@ grep -q "Kill Criteria" SKILL.codex.md || fail "Kill Criteria missing in SKILL.c
grep -q "Concrete Next Step" SKILL.codex.md || fail "Concrete Next Step missing in SKILL.codex.md (issue #21)"
pass "Verdict actionability sections present in SKILL.codex.md"
+# OpenAI-compatible API archetype (issue #16) — must be wired in dispatch + routing
+grep -q "openai_compatible_api" SKILL.md || fail "openai_compatible_api archetype missing in SKILL.md (issue #16)"
+grep -q "base_url" SKILL.md || fail "base_url handling missing in SKILL.md (issue #16)"
+grep -q "api_key_env" SKILL.md || fail "api_key_env handling missing in SKILL.md (issue #16)"
+pass "openai_compatible_api archetype wired in SKILL.md (dispatch + base_url + api_key_env)"
+
+grep -q "openai_compatible_api\|openai-compatible\|OpenAI-Compatible" SKILL.codex.md || fail "openai_compatible_api archetype missing in SKILL.codex.md (issue #16)"
+pass "openai_compatible_api archetype wired in SKILL.codex.md"
+
# --- Agent structure checks ---
required_sections=("Identity" "Grounding Protocol" "Analytical Method" "What You See" "What You Tend to Miss" "When Deliberating" "Output Format (Council Round 2)" "Output Format (Standalone)")