Skip to content

feat: model option for generating agent #1855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
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 STATS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@
| 2025-08-10 | 165,695 (+2,925) | 167,109 (+1,388) | 332,804 (+4,313) |
| 2025-08-11 | 169,297 (+3,602) | 167,953 (+844) | 337,250 (+4,446) |
| 2025-08-12 | 176,307 (+7,010) | 171,876 (+3,923) | 348,183 (+10,933) |
| 2025-08-13 | 183,208 (+6,901) | 177,182 (+5,306) | 360,390 (+12,207) |
| 2025-08-14 | 189,245 (+6,037) | 179,741 (+2,559) | 368,986 (+8,596) |
| 2025-08-15 | 193,759 (+4,514) | 181,792 (+2,051) | 375,551 (+6,565) |
| 2025-08-16 | 198,221 (+4,462) | 184,558 (+2,766) | 382,779 (+7,228) |
| 2025-08-17 | 201,390 (+3,169) | 186,269 (+1,711) | 387,659 (+4,880) |
| 2025-08-18 | 204,702 (+3,312) | 187,399 (+1,130) | 392,101 (+4,442) |
| 2025-08-19 | 209,999 (+5,297) | 189,668 (+2,269) | 399,667 (+7,566) |
| 2025-08-20 | 214,727 (+4,728) | 191,481 (+1,813) | 406,208 (+6,541) |
| 2025-08-21 | 220,675 (+5,948) | 194,784 (+3,303) | 415,459 (+9,251) |
4 changes: 2 additions & 2 deletions packages/opencode/src/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ export namespace Agent {
return state().then((x) => Object.values(x))
}

export async function generate(input: { description: string }) {
const defaultModel = await Provider.defaultModel()
export async function generate(input: { description: string; model?: { providerID: string; modelID: string } }) {
const defaultModel = input.model ?? (await Provider.defaultModel())
const model = await Provider.getModel(defaultModel.providerID, defaultModel.modelID)
const system = SystemPrompt.header(defaultModel.providerID)
system.push(PROMPT_GENERATE)
Expand Down
37 changes: 34 additions & 3 deletions packages/opencode/src/cli/cmd/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ import * as prompts from "@clack/prompts"
import { UI } from "../ui"
import { Global } from "../../global"
import { Agent } from "../../agent/agent"
import { Provider } from "../../provider/provider"
import path from "path"
import matter from "gray-matter"
import { App } from "../../app/app"

const AgentCreateCommand = cmd({
command: "create",
describe: "create a new agent",
async handler() {
builder: (yargs) => {
return yargs.option("model", {
type: "string",
alias: ["m"],
describe: "model to use in the format of provider/model",
})
},
async handler(args) {
await App.provide({ cwd: process.cwd() }, async (app) => {
UI.empty()
prompts.intro("Create agent")
Expand Down Expand Up @@ -43,10 +51,33 @@ const AgentCreateCommand = cmd({
})
if (prompts.isCancel(query)) throw new UI.CancelledError()

let modelConfig: { providerID: string; modelID: string } | undefined
if (args.model) {
try {
const parsed = Provider.parseModel(args.model)
const provider = await Provider.getProvider(parsed.providerID)
if (!provider) {
throw new Error(`Provider '${parsed.providerID}' not found`)
}
await Provider.getModel(parsed.providerID, parsed.modelID)
modelConfig = parsed
} catch (error) {
prompts.log.error(`Invalid model: ${args.model}`)
prompts.log.error(error instanceof Error ? error.message : String(error))
throw new UI.CancelledError()
}
}

const spinner = prompts.spinner()

spinner.start("Generating agent configuration...")
const generated = await Agent.generate({ description: query })
const spinnerMessage = modelConfig
? `Generating agent configuration using ${modelConfig.providerID}/${modelConfig.modelID}...`
: "Generating agent configuration..."
spinner.start(spinnerMessage)
const generated = await Agent.generate({
description: query,
model: modelConfig,
})
spinner.stop(`Agent ${generated.identifier} generated`)

const availableTools = [
Expand Down