feat(eval): Kimi K3 through OpenCode via the Vercel AI Gateway - #124
Closed
Rodriguespn wants to merge 6 commits into
Closed
feat(eval): Kimi K3 through OpenCode via the Vercel AI Gateway#124Rodriguespn wants to merge 6 commits into
Rodriguespn wants to merge 6 commits into
Conversation
Adds `opencode` (OpenCode CLI) as an eval agent on the agents framework:
an agents/opencode module (runner + parser + factory + registry definition)
plus experiments. Orchestration is unchanged; opencode's transcript is parsed
into the same surface scorers use. Runs in both modes, like Claude Code / Codex.
- agents/opencode/runner.ts: install `opencode-ai`, then `opencode run <msg>
--format json --dangerously-skip-permissions < /dev/null` (opencode blocks on
stdin otherwise, even with the message as an arg). Multi-provider: model ids
are `provider/model`, typed from the vendor SDKs — `anthropic/${Model}` |
`openai/${ChatModel}` | `google/${GoogleGenerativeAIModelId}` | (string & {}).
The runner is built per-model: `apiKeyEnvVar` and `modelProvider` are resolved
from the provider prefix (anthropic→ANTHROPIC_API_KEY, openai→OPENAI_API_KEY,
google→GOOGLE_GENERATIVE_AI_API_KEY — opencode's google provider reads exactly
that), throwing on an unsupported provider. MCP is written to an
OPENCODE_CONFIG file in scratch. Stop reason from the terminal step_finish
reason (or an error event).
- agents/opencode/parser.ts: the 1.15 JSONL schema (text / tool_use / reasoning /
error / step_*). A tool_use record is self-contained → paired tool_call +
tool_result by callID; OPENCODE_TOOLS map; normalized command/path/url via the
shared extractArgs; loadedSkill from the `skill` tool or SKILL.md reads;
epoch-ms → ISO.
- agents/engine.ts + agents/types.ts: multi-provider CLIs carry an optional
`modelProvider` on the runner; the engine prefers it over the per-agent-id
mapping. `requireApiKey` now uses the shared `requireEnv` (agents/shared.ts) —
node-native env validation with a clear "<VAR> is not set / set but empty"
error.
- eval-metadata: `opencode` harness id; `google` model provider. Web app gains
the OpenCode agent label and strips the `provider/` prefix when formatting
model names.
- Experiments: opencode-claude-sonnet-5, opencode-gpt-5.4-mini,
opencode-gemini-flash. Adds `@ai-sdk/google` for the Gemini model-id types.
.env.example gains GOOGLE_GENERATIVE_AI_API_KEY.
Verified e2e (opencode 1.15.7) in the sandbox on tools-mode
investigate-db-001-table-row-counts: opencode-claude-sonnet-5 3/3,
opencode-gpt-5.4-mini 3/3, and opencode-gemini-flash 3/3 — all stoppedReason
"stop", using the Supabase MCP. The Gemini direct-provider tool-loop issue
observed on the original branch no longer reproduces.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Adds `moonshotai` as a fourth opencode provider: `moonshotai/<model>` ids resolve to the `MOONSHOT_API_KEY` credential (the env var opencode's moonshot provider reads), with `moonshotai` added to `modelProviderSchema` and the web app's model formatting. New opencode-kimi-k3 experiment. Provider resolution is unit-tested; the experiment is NOT yet verified end-to-end — the available Moonshot account is suspended (insufficient balance) and its key serves only kimi-k2.7-code / kimi-k2.6, not kimi-k3. opencode retries Moonshot quota errors silently, so a quota-dead key presents as an eval timeout, not an auth error. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The opencode harness and its experiments were authored before the repo-wide Biome pass (AI-831), which now sits in this branch's base after rebasing onto explore/ai-gateway-vendor-provider. Reformat those files (single quotes, wrapping) so the branch introduces no lint debt. No behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The opencode harness was added after the Vercel AI Gateway work, so it was the one harness without a gateway route. Wire it up the same opt-in way as the others: opencodeAgent gains a `gateway` flag (the engine already threads `useGateway` into the runner), and in gateway mode the runner writes a custom OpenAI-compatible provider into OPENCODE_CONFIG pointed at the gateway's /v1 surface and addresses the model under it (`vercel-ai-gateway/<vendor>/<model>`, keeping the gateway slug intact). The gateway key rides in the provider config so no vendor key env var is set for the run. opencode-kimi-k3 now runs `moonshotai/kimi-k3` through the gateway (`gateway: true`) — the model the direct Moonshot account couldn't serve. The gateway catalog confirms the slug is available; the run needs AI_GATEWAY_API_KEY instead of MOONSHOT_API_KEY. Unit tests cover both the config provider block and exec routing (model flag + env) for gateway vs direct. Not yet verified end-to-end (no local gateway key); CI holds the secret. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Without a `suite`, the experiment is invisible to the CI eval-refresh
workflow, which filters experiments by `--experiment-suite`
("no experiments matched experiment=opencode-kimi-k3"). Add
`suite: ['benchmark']` so Kimi K3 is part of the benchmark eval suite,
matching the other benchmark experiments.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add @opencode-ai/sdk as a type-only devDependency, pinned (via the pnpm catalog) to the exact CLI version the runner installs (1.15.7), and type buildOpencodeConfig's output against opencode's own `Config` schema (`McpLocalConfig` for MCP servers, `ProviderConfig` for the gateway provider block). A config-layout change on a CLI bump now fails to compile instead of breaking silently at runtime. Deliberately scoped to the config only: - Model ids stay `string` — opencode's model catalog is dynamic (models.dev), so there is no model-name union to import the way the vendor SDKs and the AI Gateway (GatewayModelId) provide one. - The transcript parser is NOT typed from this SDK. `run --format json` emits a reduced, differently-shaped record than the SDK's server-API Part/Event entities (the CLI's outer discriminants `tool_use`/`step_finish` don't exist in the SDK; inner parts omit the id/sessionID/messageID the SDK marks required), so the parser stays schema-defensive. Documented at both sites. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
Author
|
Closing in favor of #126 |
mattrossman
added a commit
that referenced
this pull request
Jul 28, 2026
…way (#126) Adds `opencode` as a CLI agent harness plus two experiments running Kimi K3 through the [Vercel AI Gateway](https://vercel.com/ai-gateway): `opencode-kimi-k3` and `opencode-kimi-k3-no-skills`. Consolidates parts of #56, #120, and #124 per [this thread](https://supabase.slack.com/archives/C0BAGJBL49E/p1784919389986449?thread_ts=1784890581.560609&cid=C0BAGJBL49E). AI gateway is used only for OpenCode w/ the new experiments. Uses OpenCode's [native `vercel` provider](https://vercel.com/docs/ai-gateway/coding-agents/opencode), so the only credential is `AI_GATEWAY_API_KEY` which is already configured in repo secrets. The CLI is pinned to 1.18.5 and must stay >= 1.17.0. Older versions don't await the run event loop ([opencode#31389](anomalyco/opencode#31389)) and intermittently exit mid-step with no final report, which was failing about half of sandbox runs regardless of model. Failures like that used to be invisible: results JSON just showed an empty transcript with `stoppedReason: "error"`. Running with `--debug` now prints opencode's actual errors, which is how this was diagnosed: ``` OpenCode error event: {"name":"UnknownError","data":{"message":"Unexpected server error. Check server logs for details.","ref":"err_1ffd1f34"}} ``` Incidental fix: eval refresh jobs now fail when the experiment writes no result instead of green-skipping (surfaced by a missing `AI_GATEWAY_API_KEY` in the workflow env, now also wired up). To test locally, add `AI_GATEWAY_API_KEY` to `.env` (create one in the [evals Vercel project](https://vercel.com/supabase/evals) under AI Gateway → API keys), then: ```sh pnpm eval -- --experiment opencode-kimi-k3 --eval investigate-db-001-table-row-counts ``` Closes AI-967, AI-964, AI-965 --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Runs Moonshot's Kimi K3 through OpenCode, served by the Vercel AI Gateway. Stacks on top of two PRs:
Stacking / review order
This is the third PR in the chain: OpenCode (#56) → AI Gateway (#120) → this → Vercel Sandboxes (#114).
Because it needs both OpenCode and the Gateway, and GitHub PRs have a single base, it currently targets
explore/ai-gateway-vendor-provider(the gateway branch) and also carries the OpenCode harness commits. Once #56 and #120 both land onmain, I'll rebase this ontomainso the diff collapses to just the Kimi delta below.The Kimi delta (what's new beyond #56 + #120)
moonshotai/*ids resolve toMOONSHOT_API_KEY.opencodeAgent({ gateway: true })writes a custom OpenAI-compatible provider intoOPENCODE_CONFIGpointed at the gateway/v1surface and addresses the model asvercel-ai-gateway/<vendor>/<model>(OpenCode splits provider/model on the first/, keeping the gateway slug intact). The key rides in the provider config; no vendor key env is set.opencode-kimi-k3experiment (suite: ['benchmark']) runningmoonshotai/kimi-k3via the gateway.@opencode-ai/sdk(type-only devDep, pinned to the installed CLI version) so config-shape drift fails to compile.Validation
✅ Verified end-to-end in CI through the gateway: run 30104060065 —
opencode-kimi-k3 × investigate-realtime-001-subscribed-no-eventsPASS 6/6, withANTHROPIC_API_KEYwithheld and onlyAI_GATEWAY_API_KEYpresent, so a passing eval proves the gateway carried the traffic. Unit tests cover config + exec routing (gateway vs direct).🤖 Generated with Claude Code