Skip to content

Commit 857401f

Browse files
committed
feat: add model self-identification to system prompt
Prepend assistant info line between header and agent prompt so models know what they are and what version of OpenCode they're running in. Format: "You are {name} ({provider}: {id}) running in OpenCode v{version}, the best coding agent on the planet."
1 parent 9c8bc64 commit 857401f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/opencode/src/session/llm.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ export namespace LLM {
4747
const [language, cfg] = await Promise.all([Provider.getLanguage(input.model), Config.get()])
4848

4949
const system = SystemPrompt.header(input.model.providerID)
50+
const assistantInfo = await SystemPrompt.assistantInfo(input.model)
5051
system.push(
5152
[
53+
assistantInfo,
5254
// use agent prompt otherwise provider prompt
5355
...(input.agent.prompt ? [input.agent.prompt] : SystemPrompt.provider(input.model)),
5456
// any custom prompt passed into this call

packages/opencode/src/session/system.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Ripgrep } from "../file/ripgrep"
22
import { Global } from "../global"
33
import { Filesystem } from "../util/filesystem"
44
import { Config } from "../config/config"
5+
import { Installation } from "../installation"
6+
import { Provider } from "../provider/provider"
57

68
import { Instance } from "../project/instance"
79
import path from "path"
@@ -14,14 +16,19 @@ import PROMPT_GEMINI from "./prompt/gemini.txt"
1416
import PROMPT_ANTHROPIC_SPOOF from "./prompt/anthropic_spoof.txt"
1517

1618
import PROMPT_CODEX from "./prompt/codex.txt"
17-
import type { Provider } from "@/provider/provider"
1819

1920
export namespace SystemPrompt {
2021
export function header(providerID: string) {
2122
if (providerID.includes("anthropic")) return [PROMPT_ANTHROPIC_SPOOF.trim()]
2223
return []
2324
}
2425

26+
export async function assistantInfo(model?: Provider.Model) {
27+
if (!model) return `You are running in OpenCode v${Installation.VERSION}, the best coding agent on the planet.`
28+
const provider = await Provider.getProvider(model.providerID)
29+
return `You are ${model.name} (${provider.name}: ${model.id}) running in OpenCode v${Installation.VERSION}, the best coding agent on the planet.`
30+
}
31+
2532
export function provider(model: Provider.Model) {
2633
if (model.api.id.includes("gpt-5")) return [PROMPT_CODEX]
2734
if (model.api.id.includes("gpt-") || model.api.id.includes("o1") || model.api.id.includes("o3"))

0 commit comments

Comments
 (0)