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
9 changes: 9 additions & 0 deletions .opencode/agent/test-max-thinking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
description: Test agent with max thinking.
model: zai-coding-plan/glm-4.7
variant: max
---

You are a test agent for GLM-4.7 with max thinking enabled.

Your purpose is to test model variants in this codebase. Keep responses brief and direct.
9 changes: 9 additions & 0 deletions .opencode/agent/test-no-thinking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
description: Test agent with no thinking.
model: zai-coding-plan/glm-4.7
variant: none
---

You are a test agent for GLM-4.7 with thinking disabled.

Your purpose is to test model variants in this codebase. Keep responses brief and direct.
16 changes: 16 additions & 0 deletions .opencode/remember.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Enable or disable the plugin
"enabled": true,
// Where to store memories: "global", "project", or "both"
// - "global": ~/.config/opencode/memory/memories.sqlite (shared across projects)
// - "project": .opencode/memory/memories.sqlite (project-specific)
// - "both": search both, save to project
"scope": "project",
// Memory injection settings
"inject": {
// Number of memories to inject after user messages (default: 5)
"count": 5,
// Score threshold for [important] vs [related] tag (default: 0.6)
"highThreshold": 0.6
}
}
6 changes: 5 additions & 1 deletion packages/app/src/context/local.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
const m = current()
if (!m) return undefined
const key = `${m.provider.id}/${m.id}`
return store.variant?.[key]
const a = agent.current()
return (
store.variant?.[key] ??
(a?.model && `${a.model.providerID}/${a.model.modelID}` === key ? a.variant : undefined)
)
},
list() {
const m = current()
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 @@ -29,6 +29,7 @@ export namespace Agent {
topP: z.number().optional(),
temperature: z.number().optional(),
color: z.string().optional(),
variant: z.string().optional(),
permission: PermissionNext.Ruleset,
model: z
.object({
Expand Down Expand Up @@ -217,6 +218,7 @@ export namespace Agent {
item.topP = value.top_p ?? item.topP
item.mode = value.mode ?? item.mode
item.color = value.color ?? item.color
item.variant = value.variant ?? item.variant
item.hidden = value.hidden ?? item.hidden
item.name = value.name ?? item.name
item.steps = value.steps ?? item.steps
Expand Down
1 change: 1 addition & 0 deletions packages/opencode/src/cli/cmd/debug/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ async function createToolContext(agent: Agent.Info) {
parentID: messageID,
modelID: model.modelID,
providerID: model.providerID,
variant: agent.variant,
mode: "debug",
agent: agent.name,
path: {
Expand Down
5 changes: 4 additions & 1 deletion packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ export namespace Config {
.regex(/^#[0-9a-fA-F]{6}$/, "Invalid hex color format")
.optional()
.describe("Hex color code for the agent (e.g., #FF5733)"),
variant: z.string().optional().describe("Default model variant to use for this agent (e.g., 'high')"),
steps: z
.number()
.int()
Expand All @@ -600,6 +601,7 @@ export namespace Config {
"mode",
"hidden",
"color",
"variant",
"steps",
"maxSteps",
"options",
Expand Down Expand Up @@ -630,10 +632,11 @@ export namespace Config {
// Convert legacy maxSteps to steps
const steps = agent.steps ?? agent.maxSteps

return { ...agent, options, permission, steps } as typeof agent & {
return { ...agent, options, permission, steps, variant: agent.variant } as typeof agent & {
options?: Record<string, unknown>
permission?: Permission
steps?: number
variant?: string
}
})
.meta({
Expand Down
13 changes: 11 additions & 2 deletions packages/opencode/src/session/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ 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 selectedVariant = input.user.variant || input.agent.variant
const variant = !input.small && input.model.variants && selectedVariant ? input.model.variants[selectedVariant] : {}
l.info("variant selection", {
selectedVariant,
hasModelVariants: !!input.model.variants,
availableVariants: input.model.variants ? Object.keys(input.model.variants) : [],
variantOptions: variant,
})
const base = input.small
? ProviderTransform.smallOptions(input.model)
: ProviderTransform.options({
Expand All @@ -109,6 +115,7 @@ export namespace LLM {
mergeDeep(input.agent.options),
mergeDeep(variant),
)
l.info("merged options", { options })
if (isCodex) {
options.instructions = SystemPrompt.instructions()
}
Expand All @@ -121,6 +128,7 @@ export namespace LLM {
model: input.model,
provider,
message: input.user,
variant: selectedVariant,
},
{
temperature: input.model.capabilities.temperature
Expand All @@ -140,6 +148,7 @@ export namespace LLM {
model: input.model,
provider,
message: input.user,
variant: selectedVariant,
},
{
headers: {},
Expand Down
1 change: 1 addition & 0 deletions packages/opencode/src/session/message-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ export namespace MessageV2 {
parentID: z.string(),
modelID: z.string(),
providerID: z.string(),
variant: z.string().optional(),
/**
* @deprecated
*/
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 @@ -832,7 +832,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,
}

const parts = await Promise.all(
Expand Down
5 changes: 5 additions & 0 deletions packages/opencode/src/tool/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ export const TaskTool = Tool.define("task", async (ctx) => {
modelID: msg.info.modelID,
providerID: msg.info.providerID,
}
const variant = agent.variant ?? msg.info.variant

ctx.metadata({
title: params.description,
metadata: {
sessionId: session.id,
model,
variant,
},
})

Expand All @@ -133,6 +135,7 @@ export const TaskTool = Tool.define("task", async (ctx) => {
summary: Object.values(parts).sort((a, b) => a.id.localeCompare(b.id)),
sessionId: session.id,
model,
variant,
},
})
})
Expand All @@ -151,6 +154,7 @@ export const TaskTool = Tool.define("task", async (ctx) => {
modelID: model.modelID,
providerID: model.providerID,
},
variant,
agent: agent.name,
tools: {
todowrite: false,
Expand Down Expand Up @@ -183,6 +187,7 @@ export const TaskTool = Tool.define("task", async (ctx) => {
summary,
sessionId: session.id,
model,
variant,
},
output,
}
Expand Down
6 changes: 6 additions & 0 deletions packages/sdk/js/src/gen/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export type AssistantMessage = {
parentID: string
modelID: string
providerID: string
variant?: string
mode: string
path: {
cwd: string
Expand Down Expand Up @@ -990,6 +991,10 @@ export type AgentConfig = {
* Hex color code for the agent (e.g., #FF5733)
*/
color?: string
/**
* Default model variant to use for this agent (e.g., 'high')
*/
variant?: string
/**
* Maximum number of agentic iterations before forcing text-only response
*/
Expand Down Expand Up @@ -1590,6 +1595,7 @@ export type Agent = {
topP?: number
temperature?: number
color?: string
variant?: string
permission: {
edit: "ask" | "allow" | "deny"
bash: {
Expand Down
6 changes: 6 additions & 0 deletions packages/sdk/js/src/v2/gen/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export type AssistantMessage = {
parentID: string
modelID: string
providerID: string
variant?: string
mode: string
agent: string
path: {
Expand Down Expand Up @@ -1409,6 +1410,10 @@ export type AgentConfig = {
* Hex color code for the agent (e.g., #FF5733)
*/
color?: string
/**
* Default model variant to use for this agent (e.g., 'high')
*/
variant?: string
/**
* Maximum number of agentic iterations before forcing text-only response
*/
Expand Down Expand Up @@ -2117,6 +2122,7 @@ export type Agent = {
topP?: number
temperature?: number
color?: string
variant?: string
permission: PermissionRuleset
model?: {
modelID: string
Expand Down