Skip to content

Add Moonshot Kimi K3 computer-use provider#66

Merged
rgarcia merged 3 commits into
mainfrom
hypeship/add-kimi-k3-provider
Jul 17, 2026
Merged

Add Moonshot Kimi K3 computer-use provider#66
rgarcia merged 3 commits into
mainfrom
hypeship/add-kimi-k3-provider

Conversation

@rgarcia

@rgarcia rgarcia commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds moonshotai as a CUA provider so Kimi K3 can drive Kernel browsers: cua -p --model moonshotai:kimi-k3 "..." (moonshot: accepted as an alias, bare kimi-k3 resolves too). Requires MOONSHOT_API_KEY.

How it works

  • Moonshot has no native computer tool or coordinate protocol — its API is OpenAI-compatible chat completions with ordinary function tools, so this follows the xAI/Meta custom-function-tool pattern.
  • No custom stream adapter: kimi-k3 rides pi-ai 0.80.10's builtin moonshotai provider (openai-completions), whose registry entry already carries K3's compat quirks (deepseek-style thinking format, reasoning-content replay for K3's preserved-thinking-history requirement, max-only thinking effort).
  • The provider module declares a normalized 0–1 fractional coordinate contract. Live probes show Kimi grounding operates in width/height fractions: K2.5 emits 0–1 fractions regardless of prompt wording, and K3 follows the declared contract exactly — (0.927, 0.293) for a link centered at that exact fraction of the screenshot, consistent across repeated runs. The translator scales fractions to viewport pixels at execution.
  • Payload middleware sets parallel_tool_calls: false since browser actions mutate shared state.

pi bump 0.80.6 → 0.80.10

Needed for the Kimi K3 registry entry. Adaptations:

  • Models decorators in cua-agent delegate the new checkAuth/getAvailable/login/logout methods and the widened getAuth overload.
  • sendSessionIdHeader compat flag renamed to sessionAffinityFormat.
  • Grok 4.5's registry api moved to openai-responses (cua reroutes it anyway; test expectation updated).
  • CLI --thinking accepts pi's new max level (the only level K3 supports).

Testing

  • All unit tests pass across workspaces (cua-ai 164, cua-agent 160, cua-cli 88). ptywright dist tests fail locally on main too (native build) — unrelated.
  • Live K3 validation (all passing):
    • update-models discovery smoke: kimi-k3 emits a click function call.
    • computer-tool.integration.test.ts moonshotai case: canonical click with in-range fractional coordinates.
    • e2e.live.test.ts: CuaAgent and CuaAgentHarness both execute browser steps against a live Kernel browser with moonshotai:kimi-k3.
    • Coordinate convention confirmed: K3 returns 0–1 fractions under the shipped instructions, correctly grounded, stable across runs.
  • Also validated the same path against kimi-k2.5/k2.6/k2.7 via the discovery script (all pass the click smoke).

CI uses the new org-wide MOONSHOT_API_KEY secret for the integration/e2e jobs.


Note

Medium Risk
Touches multi-package model routing and a pi-ai bump with new live-provider CI paths; coordinate scaling and Kimi-specific thinking/tool-call behavior need correct runtime behavior.

Overview
Adds Moonshot Kimi K3 as a first-class CUA provider so agents and cua can run moonshotai:kimi-k3 (alias moonshot:, bare kimi-k3) with MOONSHOT_API_KEY.

In @onkernel/cua-ai, the new moonshot module follows the Meta/xAI pattern: canonical browser function tools (no native computer API), a 0–1 fractional coordinate contract with prompts/middleware, and parallel_tool_calls: false. kimi-k3 is annotated in models.ts and uses pi-ai’s builtin openai-completions transport (no custom stream adapter). Auth and ref aliases are wired through api-keys, runtime-spec, exports, docs, and tests.

@earendil-works/pi-ai / pi-agent-core go 0.80.6 → 0.80.10 for the Kimi registry entry. Agent Models wrappers forward checkAuth / getAvailable / login / logout and the widened getAuth; compat uses sessionAffinityFormat instead of sendSessionIdHeader. CLI --thinking gains max for K3.

CI, README/CLI help, and update-models discovery/drift scripts include Moonshot. Workspace versions bump (cua-ai 0.7.0, cua-agent 0.7.0, cua-cli 0.5.0) with integration and live e2e coverage for Kimi.

Reviewed by Cursor Bugbot for commit 70404a8. Bugbot is set up for automated code reviews on this repo. Configure here.

Expose kimi-k3 as moonshotai:kimi-k3 (alias moonshot:), streaming through
pi-ai's builtin OpenAI-compatible chat completions transport with
MOONSHOT_API_KEY. Kimi grounding emits 0-1 width/height fractions, so the
provider declares a fractional normalized coordinate contract and disables
parallel tool calls via payload middleware.

Bump pi packages to 0.80.10 for the Kimi K3 registry entry, adapting to the
Models auth surface and the sessionAffinityFormat compat rename, and accept
the new max thinking level in the CLI.
@rgarcia
rgarcia marked this pull request as ready for review July 17, 2026 18:04

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: K3 thinking map uses nulls
    • Added a Kimi K3 route override that maps all non-max thinking levels to "max" and updated the unit test to assert the new mapping.

Create PR

Or push these changes by commenting:

@cursor push d66ee77a5a
Preview (d66ee77a5a)
diff --git a/packages/ai/src/models.ts b/packages/ai/src/models.ts
--- a/packages/ai/src/models.ts
+++ b/packages/ai/src/models.ts
@@ -234,6 +234,12 @@
 			compat: { supportsDeveloperRole: false, sessionAffinityFormat: "openai-nosession", supportsLongCacheRetention: false },
 		};
 	}
+	if (model.provider === "moonshotai" && model.id === "kimi-k3") {
+		return {
+			...model,
+			thinkingLevelMap: { ...model.thinkingLevelMap, off: "max", minimal: "max", low: "max", medium: "max", high: "max", xhigh: "max" },
+		};
+	}
 	return model;
 }
 

diff --git a/packages/ai/test/models.test.ts b/packages/ai/test/models.test.ts
--- a/packages/ai/test/models.test.ts
+++ b/packages/ai/test/models.test.ts
@@ -87,9 +87,10 @@
 		expect(kimi.input).toContain("image");
 		expect(kimi.contextWindow).toBe(1_048_576);
 		expect(kimi.maxTokens).toBe(131_072);
-		// K3 launched with max-only thinking effort; pi-ai clamps the rest away.
+		// K3 only accepts max reasoning effort, so every level maps to max.
 		expect(kimi.thinkingLevelMap?.max).toBe("max");
-		expect(kimi.thinkingLevelMap?.high).toBeNull();
+		expect(kimi.thinkingLevelMap?.high).toBe("max");
+		expect(kimi.thinkingLevelMap?.low).toBe("max");
 	});
 
 	it("accepts the moonshot: alias for moonshotai refs", () => {

You can send follow-ups to the cloud agent here.

Comment thread packages/ai/src/models.ts
@rgarcia
rgarcia merged commit f1c91f7 into main Jul 17, 2026
6 checks passed
@rgarcia
rgarcia deleted the hypeship/add-kimi-k3-provider branch July 17, 2026 18:41

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.

Reviewed by Cursor Bugbot for commit 70404a8. Configure here.

// google:gemini-3-flash-preview GOOGLE_API_KEY
// meta:muse-spark-1.1 META_API_KEY
// xai:grok-4.5 XAI_API_KEY
// moonshotai:kimi-k3 MOONSHOT_API_KEY

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quickstart starves K3 thinking budget

Medium Severity

The quickstart now advertises moonshotai:kimi-k3 but still caps maxTokens at 1024. K3 always runs max-only thinking, so reasoning can consume the budget before a tool call is emitted. The integration case already raises this to 8192 for the same reason; following the documented quickstart with Kimi is likely to return text-only or truncated replies instead of a click.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 70404a8. Configure here.

// google:gemini-3-flash-preview GOOGLE_API_KEY
// meta:muse-spark-1.1 META_API_KEY
// xai:grok-4.5 XAI_API_KEY
// moonshotai:kimi-k3 MOONSHOT_API_KEY

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example skips Moonshot payload hook

Medium Severity

Moonshot’s serial-tool constraint lives only in providerModule.onPayload (parallel_tool_calls: false), unlike Meta/xAI where the transport enforces it. The quickstart resolves a runtime spec that includes that hook, then calls cuaModels().complete without passing spec.onPayload, so the advertised Moonshot path never applies the constraint.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 70404a8. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant