Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .opencode/agent/triage.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mode: primary
hidden: true
model: opencode/claude-haiku-4-5
color: "#44BA81"
variant: "high"
tools:
"*": false
"github-triage": true
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/components/prompt-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
providerID: currentModel.provider.id,
}
const agent = currentAgent.name
const variant = local.model.variant.current()
const variant = local.model.variant.effective()

const clearInput = () => {
prompt.reset()
Expand Down Expand Up @@ -1954,7 +1954,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
class="text-text-base _hidden group-hover/prompt-input:inline-block capitalize text-12-regular"
onClick={() => local.model.variant.cycle()}
>
{local.model.variant.current() ?? language.t("common.default")}
{local.model.variant.effective() ?? language.t("common.default")}
</Button>
</TooltipKeybind>
</Show>
Expand Down
9 changes: 6 additions & 3 deletions packages/app/src/context/local.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
if (!m) return undefined
return models.variant.get({ providerID: m.provider.id, modelID: m.id })
},
effective() {
return this.current() ?? agent.current()?.variant
},
list() {
const m = current()
if (!m) return []
Expand All @@ -203,12 +206,12 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
cycle() {
const variants = this.list()
if (variants.length === 0) return
const currentVariant = this.current()
if (!currentVariant) {
const effective = this.effective()
if (!effective) {
this.set(variants[0])
return
}
const index = variants.indexOf(currentVariant)
const index = variants.indexOf(effective)
if (index === -1 || index === variants.length - 1) {
this.set(undefined)
return
Expand Down
2 changes: 2 additions & 0 deletions packages/opencode/src/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export namespace Agent {
})
.optional(),
prompt: z.string().optional(),
variant: z.string().optional(),
options: z.record(z.string(), z.any()),
steps: z.number().int().positive().optional(),
})
Expand Down Expand Up @@ -214,6 +215,7 @@ export namespace Agent {
native: false,
}
if (value.model) item.model = Provider.parseModel(value.model)
if (value.variant) item.variant = value.variant
item.prompt = value.prompt ?? item.prompt
item.description = value.description ?? item.description
item.temperature = value.temperature ?? item.temperature
Expand Down
6 changes: 3 additions & 3 deletions packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,8 @@ export function Prompt(props: PromptProps) {
const showVariant = createMemo(() => {
const variants = local.model.variant.list()
if (variants.length === 0) return false
const current = local.model.variant.current()
return !!current
const effective = local.model.variant.effective()
return !!effective
})

const spinnerDef = createMemo(() => {
Expand Down Expand Up @@ -956,7 +956,7 @@ export function Prompt(props: PromptProps) {
<Show when={showVariant()}>
<text fg={theme.textMuted}>·</text>
<text>
<span style={{ fg: theme.warning, bold: true }}>{local.model.variant.current()}</span>
<span style={{ fg: theme.warning, bold: true }}>{local.model.variant.effective()}</span>
</text>
</Show>
</box>
Expand Down
9 changes: 6 additions & 3 deletions packages/opencode/src/cli/cmd/tui/context/local.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
const key = `${m.providerID}/${m.modelID}`
return modelStore.variant[key]
},
effective() {
return this.current() ?? agent.current().variant
},
list() {
const m = currentModel()
if (!m) return []
Expand All @@ -341,12 +344,12 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
cycle() {
const variants = this.list()
if (variants.length === 0) return
const current = this.current()
if (!current) {
const effective = this.effective()
if (!effective) {
this.set(variants[0])
return
}
const index = variants.indexOf(current)
const index = variants.indexOf(effective)
if (index === -1 || index === variants.length - 1) {
this.set(undefined)
return
Expand Down
2 changes: 2 additions & 0 deletions packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ export namespace Config {
export const Agent = z
.object({
model: z.string().optional(),
variant: z.string().optional().describe("Default variant to use for this agent"),
temperature: z.number().optional(),
top_p: z.number().optional(),
prompt: z.string().optional(),
Expand Down Expand Up @@ -593,6 +594,7 @@ export namespace Config {
const knownKeys = new Set([
"name",
"model",
"variant",
"prompt",
"description",
"temperature",
Expand Down
9 changes: 7 additions & 2 deletions packages/opencode/src/session/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ export namespace LLM {
system.push(header, rest.join("\n"))
}

const variant =
!input.small && input.model.variants && input.user.variant ? input.model.variants[input.user.variant] : {}
const variant = (() => {
if (input.small) return {}
if (!input.model.variants) return {}
const selectedVariant = input.user.variant ?? input.agent.variant
if (!selectedVariant) return {}
return input.model.variants[selectedVariant] ?? {}
})()
const base = input.small
? ProviderTransform.smallOptions(input.model)
: ProviderTransform.options({
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/src/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ export namespace SessionPrompt {
agent: agent.name,
model: input.model ?? agent.model ?? (await lastModel(input.sessionID)),
system: input.system,
variant: input.variant,
variant: input.variant ?? agent.variant,
}
using _ = defer(() => InstructionPrompt.clear(info.id))

Expand Down
28 changes: 28 additions & 0 deletions packages/opencode/test/agent/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,3 +636,31 @@ test("defaultAgent throws when all primary agents are disabled", async () => {
},
})
})

test("agent variant can be set from config", async () => {
await using tmp = await tmpdir({
config: {
agent: {
build: { variant: "high" },
},
},
})
await Instance.provide({
directory: tmp.path,
fn: async () => {
const build = await Agent.get("build")
expect(build?.variant).toBe("high")
},
})
})

test("agent variant defaults to undefined when not set", async () => {
await using tmp = await tmpdir()
await Instance.provide({
directory: tmp.path,
fn: async () => {
const build = await Agent.get("build")
expect(build?.variant).toBeUndefined()
},
})
})
5 changes: 5 additions & 0 deletions packages/sdk/js/src/v2/gen/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,10 @@ export type PermissionConfig =

export type AgentConfig = {
model?: string
/**
* Default variant to use for this agent
*/
variant?: string
temperature?: number
top_p?: number
prompt?: string
Expand Down Expand Up @@ -2123,6 +2127,7 @@ export type Agent = {
providerID: string
}
prompt?: string
variant?: string
options: {
[key: string]: unknown
}
Expand Down
7 changes: 7 additions & 0 deletions packages/sdk/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -8995,6 +8995,10 @@
"model": {
"type": "string"
},
"variant": {
"description": "Default variant to use for this agent",
"type": "string"
},
"temperature": {
"type": "number"
},
Expand Down Expand Up @@ -10765,6 +10769,9 @@
"prompt": {
"type": "string"
},
"variant": {
"type": "string"
},
"options": {
"type": "object",
"propertyNames": {
Expand Down