An open-source, faster Devin alternative
TypeScript
pi runtime across docs + SDK + CLI (staged for GA) (#476)
Igor Zalutski64e02e1fc567
diff --git a/cmd/oc/internal/commands/agent_crud.go b/cmd/oc/internal/commands/agent_crud.goindex 27f1d0c1..e5eb2c5a 100644--- a/cmd/oc/internal/commands/agent_crud.go+++ b/cmd/oc/internal/commands/agent_crud.go@@ -9,7 +9,7 @@ import (var agentCreateCmd = &cobra.Command{Use: "create <name>",Short: "Create an agent",- Example: " oc agent create issue-fixer --prompt \"You fix issues.\" --model anthropic/claude-sonnet-4-6\n" ++ Example: " oc agent create issue-fixer --prompt \"You fix issues.\" --model anthropic/claude-sonnet-5\n" +" (tip: `oc agent init` + `oc agent deploy` is the usual flow — create is for quick one-offs)",Args: cobra.ExactArgs(1),RunE: func(cmd *cobra.Command, args []string) error {@@ -114,8 +114,8 @@ var agentGetCmd = &cobra.Command{func registerAgentCrud() {agentCreateCmd.Flags().String("prompt", "", "System prompt (required)")- agentCreateCmd.Flags().String("model", "", "Model, e.g. anthropic/claude-sonnet-4-6 (required)")- agentCreateCmd.Flags().String("runtime", "claude", "Runtime family (claude|codex)")+ agentCreateCmd.Flags().String("model", "", "Model, e.g. anthropic/claude-sonnet-5 (required)")+ agentCreateCmd.Flags().String("runtime", "claude", "Runtime family (claude|codex|pi)")agentCreateCmd.Flags().String("credential", "", "Credential id (optional)")agentGetCmd.Flags().String("agent", "", "Agent id or name (else the cwd agent.toml)")diff --git a/cmd/oc/internal/commands/agent_init.go b/cmd/oc/internal/commands/agent_init.goindex 5e4b26ab..596235f9 100644--- a/cmd/oc/internal/commands/agent_init.go+++ b/cmd/oc/internal/commands/agent_init.go@@ -12,7 +12,7 @@ const agentTomlTmpl = `name = %qmodel = %q[runtime]-family = %q # claude | codex+family = %q # claude | codex | pitype = "default"[limits]@@ -39,7 +39,7 @@ var agentInitCmd = &cobra.Command{Use: "init [dir]",Short: "Scaffold a deployable agent directory (agent.toml + prompt.md + skills/)",Example: " oc agent init\n" +- " oc agent init ./agents/triage --name triage --model anthropic/claude-sonnet-4-6\n" ++ " oc agent init ./agents/triage --name triage --model anthropic/claude-sonnet-5\n" +" oc agent init && $EDITOR prompt.md && oc agent deploy",Args: cobra.MaximumNArgs(1),RunE: func(cmd *cobra.Command, args []string) error {@@ -86,6 +86,6 @@ var agentInitCmd = &cobra.Command{func init() {agentInitCmd.Flags().String("name", "", "Agent name (default: the directory name)")- agentInitCmd.Flags().String("model", "anthropic/claude-sonnet-4-6", "Model")- agentInitCmd.Flags().String("runtime", "claude", "Runtime family (claude|codex)")+ agentInitCmd.Flags().String("model", "anthropic/claude-sonnet-5", "Model")+ agentInitCmd.Flags().String("runtime", "claude", "Runtime family (claude|codex|pi)")}diff --git a/docs/agent-sessions/custom-runtimes.mdx b/docs/agent-sessions/custom-runtimes.mdxindex a98f13ab..f1a071c8 100644--- a/docs/agent-sessions/custom-runtimes.mdx+++ b/docs/agent-sessions/custom-runtimes.mdx@@ -63,6 +63,8 @@ Content-Type: application/jsonThe adapter has already read the event log. Your brain receives the new turn input, not a session cursor.+Everything in `config` is turn-invariant for the life of the box, so a resident brain may cache values like `mcp_endpoint`, `state_dir`, and the ports across turns. When something has to change — for example the session's skills — the platform restarts the brain rather than handing it a changed `config` mid-life.+## Step stream`POST /turn` responds with newline-delimited JSON. The brain streams its SDK's **native** events verbatim, one per line, then a terminal `done`:@@ -80,6 +82,21 @@ The platform ships a **per-SDK adapter** that maps native SDK events to [sessionTool calls, including user-visible `say` and `ask`, are made through MCP, not by emitting HTTP requests to OpenComputer.+## Deadlines++A turn runs under nested deadlines. Each inner clock expires before the one outside it, and the layer that enforces a deadline also cleans up the one below it.++| Clock | Value | Enforced by |+| --- | --- | --- |+| Health check | 2s per probe | adapter → your `/healthz` |+| Brain start | 30s to first `ready` | adapter (fails the turn if exceeded) |+| Step cap | `config.max_turns` (24) per `/turn` | your SDK — end the stream cleanly when hit |+| Model call | provider-dependent | your SDK |+| Turn deadline | `min(agent turnSeconds, 1800s)` | platform — the turn is killed at the deadline |+| Fence / cancel grace | 5s after the request is aborted | adapter — a brain still busy is killed; the next turn restarts it |++If your brain runs past the turn deadline the turn ends `deadline_exceeded`; the session can be steered to continue. Aim to yield often — fresh config and input arrive on the next turn.+## ToolsThe adapter exposes tools at `config.mcp_endpoint`. Your brain connects through your SDK's MCP support.@@ -95,6 +112,8 @@ The adapter exposes tools at `config.mcp_endpoint`. Your brain connects throughThe brain sandbox is for the model loop. The hands sandbox is where files and commands run.+The MCP endpoint is live only during an in-flight `/turn`. Don't call tools from a background timer or a deferred flush between turns — the endpoint is gone once the turn ends. The adapter always provides `config.mcp_endpoint`; connect to it — a brain that skips tools silently degrades to a chat-only agent.+## State and recoveryStore resumable state under `config.state_dir`. OpenComputer checkpoints that directory at turn boundaries and restores it after recovery.diff --git a/docs/agent-sessions/runtimes.mdx b/docs/agent-sessions/runtimes.mdxindex 1c207320..df0d794f 100644--- a/docs/agent-sessions/runtimes.mdx+++ b/docs/agent-sessions/runtimes.mdx@@ -10,11 +10,13 @@ A **runtime** executes the agent loop: provider SDK, model calls, and tool use.| --- | --- | --- || `claude` | `anthropic/…` (e.g. `anthropic/claude-opus-4-8`) | Managed, or an Anthropic key || `codex` | `openai/…` (e.g. `openai/gpt-5-codex`) | Managed, or an OpenAI key |+| `pi` | `anthropic/…` today — the runtime is provider-agnostic by construction; more providers land next | Managed, or an Anthropic key |`model` is passed straight through to the provider, so any model that provider serves works — only the **`provider/` prefix** is validated against the runtime (a bad prefix is rejected at agent create, a model the provider doesn't recognize fails on the first turn). Common choices:-- **`claude`:** `anthropic/claude-opus-4-8` (most capable), `anthropic/claude-sonnet-4-6` (balanced), `anthropic/claude-haiku-4-5` (fastest/cheapest).+- **`claude`:** `anthropic/claude-sonnet-5` (default, balanced), `anthropic/claude-opus-4-8` (most capable), `anthropic/claude-fable-5`, `anthropic/claude-haiku-4-5` (fastest/cheapest).- **`codex`:** `openai/gpt-5-codex`.+- **`pi`:** the `anthropic/…` catalog above. The runtime itself is provider-agnostic; additional providers are next.Sessions, [events](/agent-sessions/events), [steering](/agent-sessions/messaging), [tools](/agent-sessions/runtime-tools), and [webhooks](/agent-sessions/webhooks) share the same API across runtimes. `runtime` is fixed once the agent exists; to switch engines, create a new agent.@@ -48,17 +50,37 @@ Content-Type: application/json{"name": "reviewer","runtime": "codex",- "model": "openai/gpt-5-codex",+ "model": "anthropic/claude-sonnet-5","prompt": "Review code in the sandbox. Run tests. Explain risks.","key": "sk-..."}```-The runtime, model, and credential have to agree: `runtime: "codex"` needs an `openai/…` model and an OpenAI key, and `runtime: "claude"` needs an `anthropic/…` model and an Anthropic key. A mismatch is rejected when you create the agent, with a clear error — so a session never starts on a broken pairing. See [model credentials](/agent-sessions/credentials).+## `pi`++The [pi](https://github.com/earendil-works/pi) coding-agent harness (MIT). `pi` is built provider-agnostic — the harness drives whatever provider the model's `provider/` prefix names. Today it ships with `anthropic/…` models, on Managed billing or your Anthropic key; additional providers land next. Sandbox tools, the event stream, steering, and recovery are the same as the other runtimes.++```http+POST https://api.opencomputer.dev/v3/agents+Authorization: Bearer $OPENCOMPUTER_API_KEY+Content-Type: application/json++{+ "name": "reviewer",+ "runtime": "pi",+ "model": "anthropic/claude-sonnet-5",+ "prompt": "Review code in the sandbox. Run tests. Explain risks.",+ "credential": "managed"+}+```++The provider is taken from the model's `provider/` prefix — so as more providers land, switching provider is just a different `model` on the same `pi` agent, not a separate runtime.++The runtime, model, and credential have to agree. `claude` needs an `anthropic/…` model and an Anthropic key; `codex` needs an `openai/…` model and an OpenAI key; `pi` runs `anthropic/…` models today and needs an Anthropic key (or Managed). A mismatch is rejected when you create the agent, with a clear error — so a session never starts on a broken pairing. See [model credentials](/agent-sessions/credentials).## Architecture-The model is configuration, not part of the runtime image. Each runtime drives one provider: `claude` drives Anthropic, `codex` drives OpenAI. You choose the exact `provider/model` and key.+The model is configuration, not part of the runtime image. The provider is always taken from the model's `provider/` prefix, never from the runtime — a runtime only declares which providers it can drive: `claude` and `pi` drive Anthropic today (`pi` is built to drive any provider — more land next), `codex` drives OpenAI. You choose the exact `provider/model` and key.A runtime has two components:diff --git a/sdks/typescript/package-lock.json b/sdks/typescript/package-lock.jsonindex 3ec3388b..c8f1456b 100644--- a/sdks/typescript/package-lock.json+++ b/sdks/typescript/package-lock.json@@ -1,12 +1,12 @@{"name": "@opencomputer/sdk",- "version": "0.11.0",+ "version": "0.11.1","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "@opencomputer/sdk",- "version": "0.11.0",+ "version": "0.11.1","license": "MIT","devDependencies": {"@types/node": "^25.3.0",diff --git a/sdks/typescript/package.json b/sdks/typescript/package.jsonindex cde3931a..cb98d66c 100644--- a/sdks/typescript/package.json+++ b/sdks/typescript/package.json@@ -1,6 +1,6 @@{"name": "@opencomputer/sdk",- "version": "0.11.0",+ "version": "0.11.1","description": "TypeScript SDK for OpenComputer - cloud sandbox platform","type": "module","main": "dist/index.js",diff --git a/sdks/typescript/src/agents/agents.ts b/sdks/typescript/src/agents/agents.tsindex e9784b47..0f67b04f 100644--- a/sdks/typescript/src/agents/agents.ts+++ b/sdks/typescript/src/agents/agents.ts@@ -8,11 +8,11 @@ import {export interface CreateAgentParams {name: string;prompt: string;- /** `provider/model` id; must match the runtime's provider (`anthropic/…` for `claude`, `openai/…` for `codex`). */+ /** `provider/model` id; the provider must be one the runtime can drive (`anthropic/…` for `claude`, `openai/…` for `codex`, any catalog provider for `pi`). */model: string;- /** Defaults to `claude`. Fixes the model's provider (see `model`); immutable after create. */+ /** Defaults to `claude`. Determines which providers the model may use (see `model`); immutable after create. */runtime?: Runtime;- /** Model provider key for the runtime (Anthropic for `claude`, OpenAI for `codex`), stored as a sealed credential. Mutually exclusive with `credential`. */+ /** Model provider key, stored as a sealed credential — Anthropic for `claude`, OpenAI for `codex`, the model's provider for `pi`. Mutually exclusive with `credential`. */key?: string;/** Model source: `"managed"` (run via OpenComputer, no provider key) or a `cred_…` id. Omit for the org default. Mutually exclusive with `key`. */credential?: CredentialRef;@@ -21,7 +21,7 @@ export interface CreateAgentParams {export interface UpdateAgentParams {prompt?: string;- /** Stay within the agent's runtime provider (`anthropic/…` for `claude`, `openai/…` for `codex`); the runtime itself is immutable. */+ /** Stay within what the agent's runtime can drive (`anthropic/…` for `claude`, `openai/…` for `codex`, any catalog provider for `pi`); the runtime itself is immutable. */model?: string;key?: string;/** Re-point the model source: `"managed"`, a `cred_…` id, or `null` to clear (org default). Mutually exclusive with `key`. */diff --git a/sdks/typescript/src/agents/credentials.ts b/sdks/typescript/src/agents/credentials.tsindex be98d738..64ed46cc 100644--- a/sdks/typescript/src/agents/credentials.ts+++ b/sdks/typescript/src/agents/credentials.ts@@ -2,7 +2,7 @@ import type { Http } from "./http.js";import type { Credential } from "./types.js";export interface CreateCredentialParams {- /** The model provider this key is for (`anthropic` for the `claude` runtime, `openai` for `codex`). Defaults to `anthropic`. */+ /** The model provider this key is for — `anthropic` for `claude` and `pi`, `openai` for `codex`. Defaults to `anthropic`. */provider?: "anthropic" | "openai" | (string & {});/** Write-only — never returned by the API. */key: string;diff --git a/sdks/typescript/src/agents/types.ts b/sdks/typescript/src/agents/types.tsindex d1d9ab85..5b0bf8f8 100644--- a/sdks/typescript/src/agents/types.ts+++ b/sdks/typescript/src/agents/types.ts@@ -9,10 +9,11 @@ export type YieldReason =export interface Limits { tokens?: number; turnSeconds?: number; turns?: number; }-// The runtime an agent runs on. It fixes the model's provider — `claude` runs-// `anthropic/…` models, `codex` runs `openai/…` (more land over time). The union+// The runtime an agent runs on. `claude` and `pi` run `anthropic/…` models today and+// `codex` runs `openai/…`. `pi` is built provider-agnostic (the provider comes from the+// model's `provider/` prefix, not the runtime) — more providers land next. The union// keeps known values discoverable while still accepting future ones.-export type Runtime = "claude" | "codex" | (string & {});+export type Runtime = "claude" | "codex" | "pi" | (string & {});// A credential id (`newId("cred")` → `cred_…`). The template keeps the shape// checkable while still accepting any concrete id.diff --git a/web/src/api/mock.ts b/web/src/api/mock.tsindex 607b80b9..991e68fb 100644--- a/web/src/api/mock.ts+++ b/web/src/api/mock.ts@@ -466,7 +466,7 @@ const agents = [prompt:'You write clear, friendly developer documentation. Prefer short sentences and runnable examples.',prompt_hash: 'sha256:42bd07',- model: 'anthropic/claude-sonnet-4-6',+ model: 'anthropic/claude-sonnet-5',runtime: 'claude',credential_id: null,revision: 1,diff --git a/web/src/components/form.tsx b/web/src/components/form.tsxindex b4e7ef08..c2a1702d 100644--- a/web/src/components/form.tsx+++ b/web/src/components/form.tsx@@ -22,7 +22,9 @@ export function Select({}: {value: stringonValueChange: (value: string) => void- options: { value: string; label: string }[]+ // A `{ separator: true }` entry renders a divider between groups (e.g. models+ // grouped by provider) rather than a selectable item.+ options: ({ value: string; label: string } | { separator: true })[]id?: stringplaceholder?: stringdisabled?: boolean@@ -56,20 +58,27 @@ export function Select({className="bg-popover text-popover-foreground ring-foreground/10 shadow-overlay data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 z-50 max-h-(--radix-select-content-available-height) min-w-(--radix-select-trigger-width) origin-(--radix-select-content-transform-origin) overflow-hidden rounded-lg p-1 ring-1 duration-100"><SelectPrimitive.Viewport>- {options.map((o) => (- <SelectPrimitive.Item- key={o.value}- value={o.value}- className="focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center rounded-md py-1 pr-8 pl-2 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50"- >- <SelectPrimitive.ItemText>{o.label}</SelectPrimitive.ItemText>- <span className="absolute right-2 flex items-center">- <SelectPrimitive.ItemIndicator>- <Check className="size-4" />- </SelectPrimitive.ItemIndicator>- </span>- </SelectPrimitive.Item>- ))}+ {options.map((o, i) =>+ 'separator' in o ? (+ <SelectPrimitive.Separator+ key={`sep-${i}`}+ className="bg-border pointer-events-none -mx-1 my-1 h-px"+ />+ ) : (+ <SelectPrimitive.Item+ key={o.value}+ value={o.value}+ className="focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center rounded-md py-1 pr-8 pl-2 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50"+ >+ <SelectPrimitive.ItemText>{o.label}</SelectPrimitive.ItemText>+ <span className="absolute right-2 flex items-center">+ <SelectPrimitive.ItemIndicator>+ <Check className="size-4" />+ </SelectPrimitive.ItemIndicator>+ </span>+ </SelectPrimitive.Item>+ ),+ )}</SelectPrimitive.Viewport></SelectPrimitive.Content></SelectPrimitive.Portal>diff --git a/web/src/lib/runtimes.ts b/web/src/lib/runtimes.tsindex 542b3fad..8772aca5 100644--- a/web/src/lib/runtimes.ts+++ b/web/src/lib/runtimes.ts@@ -1,8 +1,9 @@// The runtimes the dashboard exposes, with their models + credential provider.-// The v3 API pairs each runtime with a provider (claude→anthropic, codex→openai)-// and requires a provider-prefixed model id, so everything model/credential-related-// keys off this one table — keeping the create dialog and the agent detail screen in-// sync. More runtimes (and models) land here as they ship.+// `claude` and `codex` each pair with one provider (claude→anthropic, codex→openai);+// `pi` drives any provider, so for pi the provider comes from the selected model's+// `provider/` prefix, not the runtime — see providerForModel + keyFieldFor, which the+// create dialog uses so a pi agent's key field follows its model. More runtimes (and+// models) land here as they ship.export type RuntimeModel = { value: string; label: string }@@ -12,6 +13,10 @@ export type RuntimeOption = {provider: string // credential provider + model-id prefixkeyLabel: string // label for the inline "new credential" key fieldkeyPlaceholder: string+ // Models are listed most-powerful-first within each provider. `defaultModel`+ // is the one a new agent preselects (else models[0]) — so the list can be+ // power-ordered while the default stays a mid-tier pick.+ defaultModel?: stringmodels: RuntimeModel[]}@@ -22,9 +27,12 @@ export const RUNTIMES: RuntimeOption[] = [provider: 'anthropic',keyLabel: 'Anthropic API key',keyPlaceholder: 'sk-ant-…',+ // Power-ordered; Sonnet 5 is the preselected default for new agents.+ defaultModel: 'anthropic/claude-sonnet-5',models: [{ value: 'anthropic/claude-opus-4-8', label: 'Claude Opus 4.8' },- { value: 'anthropic/claude-sonnet-4-6', label: 'Claude Sonnet 4.6' },+ { value: 'anthropic/claude-sonnet-5', label: 'Claude Sonnet 5' },+ { value: 'anthropic/claude-fable-5', label: 'Claude Fable 5' },{ value: 'anthropic/claude-haiku-4-5', label: 'Claude Haiku 4.5' },],},@@ -44,8 +52,38 @@ export const RUNTIMES: RuntimeOption[] = [{ value: 'openai/gpt-5.4-nano', label: 'GPT-5.4 Nano' },],},+ {+ value: 'pi',+ label: 'Pi',+ // Pi drives ANY provider — this `provider` is only the default (the first model's+ // prefix) for defaultModelFor/fallbacks. The create form derives the ACTUAL provider+ // from the selected model via providerForModel, since a pi agent's provider (and so+ // its key field + credential list) varies by model.+ provider: 'anthropic',+ keyLabel: 'Model provider API key',+ keyPlaceholder: 'API key',+ // Anthropic-only TODAY (what prod validates for pi). The runtime is built+ // provider-agnostic; other providers' models land here when the platform accepts+ // them (the create dialog already groups by provider via withModelGroups).+ defaultModel: 'anthropic/claude-sonnet-5',+ models: [+ { value: 'anthropic/claude-opus-4-8', label: 'Claude Opus 4.8' },+ { value: 'anthropic/claude-sonnet-5', label: 'Claude Sonnet 5' },+ { value: 'anthropic/claude-fable-5', label: 'Claude Fable 5' },+ { value: 'anthropic/claude-haiku-4-5', label: 'Claude Haiku 4.5' },+ ],+ },]+// Key-field copy per provider. Pi mixes providers within one runtime, so the create+// dialog keys the credential field off the selected model's provider, not the runtime.+export const PROVIDER_KEY_FIELDS: Record<string, { keyLabel: string; keyPlaceholder: string }> = {+ anthropic: { keyLabel: 'Anthropic API key', keyPlaceholder: 'sk-ant-…' },+ openai: { keyLabel: 'OpenAI API key', keyPlaceholder: 'sk-…' },+ google: { keyLabel: 'Google AI API key', keyPlaceholder: 'AIza…' },+ openrouter: { keyLabel: 'OpenRouter API key', keyPlaceholder: 'sk-or-…' },+}+export const DEFAULT_RUNTIME = RUNTIMES[0].valueexport const runtimeOptions = RUNTIMES.map((r) => ({@@ -60,5 +98,35 @@ export function getRuntime(value: string | undefined): RuntimeOption {}export function defaultModelFor(runtime: string): string {- return getRuntime(runtime).models[0].value+ const rt = getRuntime(runtime)+ return rt.defaultModel ?? rt.models[0].value+}++// The provider a model runs on is its `provider/` prefix — the API's source of truth.+// Works for every runtime: claude/codex models all share one prefix; pi's vary.+export function providerForModel(model: string): string {+ return model.split('/')[0] || ''+}++// The key-field copy for a provider, with a generic fallback for uncurated providers.+export function keyFieldFor(provider: string): { keyLabel: string; keyPlaceholder: string } {+ return PROVIDER_KEY_FIELDS[provider] ?? { keyLabel: 'Model provider API key', keyPlaceholder: 'API key' }+}++// A Select option that is either a model or a group divider.+export type ModelSelectOption = RuntimeModel | { separator: true }++// Insert a divider between consecutive models from different providers, so a+// multi-provider runtime's dropdown (pi) reads as grouped without vendor labels.+// Single-provider runtimes (claude/codex) have no boundary, so nothing changes.+export function withModelGroups(models: RuntimeModel[]): ModelSelectOption[] {+ const out: ModelSelectOption[] = []+ let prev: string | null = null+ for (const m of models) {+ const p = providerForModel(m.value)+ if (prev !== null && p !== prev) out.push({ separator: true })+ out.push(m)+ prev = p+ }+ return out}diff --git a/web/src/pages/AgentDetail.tsx b/web/src/pages/AgentDetail.tsxindex 6d86b59c..be186f7e 100644--- a/web/src/pages/AgentDetail.tsx+++ b/web/src/pages/AgentDetail.tsx@@ -36,7 +36,7 @@ import {type WorkingRepo,} from '@/components/working-repo-field'import { ApiHint, type ApiRef } from '@/components/api-hint'-import { getRuntime } from '@/lib/runtimes'+import { getRuntime, keyFieldFor, providerForModel, withModelGroups } from '@/lib/runtimes'const DOCS = 'https://docs.opencomputer.dev/agent-sessions'@@ -104,8 +104,12 @@ export default function AgentDetail() {queryFn: getCredentials,})const rt = getRuntime(agent?.runtime)+ // Provider follows the agent's MODEL prefix (pi spans providers within one runtime);+ // for claude/codex it equals the runtime's provider.+ const provider = providerForModel(agent?.model ?? '') || rt.provider+ const keyField = keyFieldFor(provider)const providerCreds = (credentials ?? []).filter(- (c) => c.provider === rt.provider,+ (c) => c.provider === provider,)const credLabel = (id: string) => {const c = providerCreds.find((x) => x.id === id)@@ -200,7 +204,7 @@ export default function AgentDetail() {mutationFn: async () => {const cred = await createCredential({key: newCredKey.trim(),- provider: rt.provider,+ provider: provider,name: newCredName.trim() || undefined,is_default: !providerCreds.some((c) => c.is_default),})@@ -370,7 +374,7 @@ export default function AgentDetail() {id="agent-model"value={agent.model}onValueChange={(m) => modelMutation.mutate(m)}- options={modelOptions}+ options={withModelGroups(modelOptions)}className="max-w-xs"/><Saving show={modelMutation.isPending} />@@ -531,7 +535,7 @@ export default function AgentDetail() {/></Field><Field- label={rt.keyLabel}+ label={keyField.keyLabel}htmlFor="new-cred-key"description="Encrypted in a dedicated secret store.">@@ -540,7 +544,7 @@ export default function AgentDetail() {type="password"value={newCredKey}onChange={(e) => setNewCredKey(e.target.value)}- placeholder={rt.keyPlaceholder}+ placeholder={keyField.keyPlaceholder}/></Field><div className="flex justify-end gap-2 sm:col-span-2">diff --git a/web/src/pages/Agents.tsx b/web/src/pages/Agents.tsxindex f34ec482..419c3d1a 100644--- a/web/src/pages/Agents.tsx+++ b/web/src/pages/Agents.tsx@@ -28,7 +28,10 @@ import {DEFAULT_RUNTIME,defaultModelFor,getRuntime,+ keyFieldFor,+ providerForModel,runtimeOptions,+ withModelGroups,} from '@/lib/runtimes'// Sentinels for the non-credential choices in the credential picker. The model@@ -79,12 +82,14 @@ export default function Agents() {const [newCredName, setNewCredName] = useState('')const [newCredKey, setNewCredKey] = useState('')- // Everything model/credential-related follows the chosen runtime- // (claude→anthropic, codex→openai): the model list, the credential provider it- // filters to, and the key label.+ // The model list follows the runtime; the credential provider + key field follow+ // the selected MODEL's provider prefix. For claude/codex that prefix always equals+ // the runtime's provider; for pi it varies by model, which is what makes pi work.const rt = getRuntime(runtime)+ const provider = providerForModel(model) || rt.provider+ const keyField = keyFieldFor(provider)const providerCreds = (credentials ?? []).filter(- (c) => c.provider === rt.provider,+ (c) => c.provider === provider,)const hasDefault = providerCreds.some((c) => c.is_default)@@ -115,17 +120,35 @@ export default function Agents() {// (runtime, model) pair or an off-provider credential.const onRuntimeChange = (value: string) => {setRuntime(value)- const next = getRuntime(value)- setModel(next.models[0].value)+ const nextModel = defaultModelFor(value)+ setModel(nextModel)setCredChoice(defaultCredFor(- (credentials ?? []).filter((c) => c.provider === next.provider),+ (credentials ?? []).filter(+ (c) => c.provider === providerForModel(nextModel),+ ),),)setNewCredName('')setNewCredKey('')}+ // Changing the model can change the provider (pi spans providers) — re-point the+ // credential fields at the new provider so we never submit an off-provider key.+ const onModelChange = (value: string) => {+ setModel(value)+ const nextProvider = providerForModel(value)+ if (nextProvider !== provider) {+ setCredChoice(+ defaultCredFor(+ (credentials ?? []).filter((c) => c.provider === nextProvider),+ ),+ )+ setNewCredName('')+ setNewCredKey('')+ }+ }+// Build options: Managed (always offered, no provider — runs without a BYO key) +// this runtime's provider creds + "New credential…".const credOptions = [@@ -150,7 +173,7 @@ export default function Agents() {} else if (credChoice === NEW_CRED) {const cred = await createCredential({key: newCredKey.trim(),- provider: rt.provider,+ provider: provider,name: newCredName.trim() || undefined,is_default: !hasDefault, // first key for this provider becomes its default})@@ -338,8 +361,8 @@ export default function Agents() {key={runtime}id="agent-model"value={model}- onValueChange={setModel}- options={rt.models}+ onValueChange={onModelChange}+ options={withModelGroups(rt.models)}/></Field></div>@@ -349,11 +372,11 @@ export default function Agents() {description={credChoice === MANAGED? 'Run via OpenComputer, billed to your credits — no key needed.'- : `The ${rt.provider} key this agent runs on (matches the runtime). Reuse one from Credentials, or add a new one here.`+ : `The ${provider} key this agent runs on (matches the model). Reuse one from Credentials, or add a new one here.`}><Select- key={runtime}+ key={provider}id="agent-cred"value={credChoice}onValueChange={setCredChoice}@@ -372,7 +395,7 @@ export default function Agents() {/></Field><Field- label={rt.keyLabel}+ label={keyField.keyLabel}htmlFor="new-cred-key"description="Encrypted in a dedicated secret store.">@@ -381,7 +404,7 @@ export default function Agents() {type="password"value={newCredKey}onChange={(e) => setNewCredKey(e.target.value)}- placeholder={rt.keyPlaceholder}+ placeholder={keyField.keyPlaceholder}/></Field></div>