xonecas.io
64875
Mc

mini-coder / commit 291edb7

fix: route system prompt via instructions field for OpenAI GPT models

GPT models using the Responses API treat a system-role message in input
as lower priority than the instructions field, causing them to ignore
directives and stall instead of making tool calls.

- Detect openai/gpt-* and zen/gpt-* models and send the system prompt
  via providerOptions.openai.instructions instead of system
- Append a minimal continuation nudge for the gpt-* family, which
  broadly tends to describe tool calls rather than execute them
- Make modelString required on runTurn to catch future omissions at
  compile time
- Use indexOf/slice for model string parsing, consistent with the rest
  of the codebase

Sean2026-03-01 291edb78b9eb6cb87c24b6cf6754ff614ab05062 parent 1573cd1

2 files changed

src/agent/agent.ts+2−0
@@ -233,6 +233,7 @@ export async function runAgent(opts: AgentOptions): Promise<void> {
233233
234234 const events = runTurn({
235235 model: subLlm,
236+ modelString: model,
236237 messages: subMessages,
237238 tools: subTools,
238239 systemPrompt,
@@ -572,6 +573,7 @@ export async function runAgent(opts: AgentOptions): Promise<void> {
572573
573574 const events = runTurn({
574575 model: llm,
576+ modelString: currentModel,
575577 messages: coreHistory,
576578 tools: planMode
577579 ? [...buildReadOnlyToolSet({ cwd }), ...mcpTools]
src/llm-api/turn.ts+43−2
@@ -62,6 +62,21 @@ function toCoreTool(
6262
6363 // ─── Main turn function ───────────────────────────────────────────────────────
6464
65+/**
66+ * Returns true when the model string refers to an OpenAI GPT model, which uses
67+ * the Responses API and honours the `instructions` provider option as the
68+ * authoritative system prompt (rather than a system-role message in `input`).
69+ */
70+function isOpenAIGPT(modelString: string): boolean {
71+ const slashIdx = modelString.indexOf("/");
72+ const provider =
73+ slashIdx === -1 ? modelString : modelString.slice(0, slashIdx);
74+ const modelId = slashIdx === -1 ? "" : modelString.slice(slashIdx + 1);
75+ return (
76+ (provider === "openai" || provider === "zen") && modelId.startsWith("gpt-")
77+ );
78+}
79+
6580 /**
6681 * Run a single agent turn against the model.
6782 *
@@ -70,12 +85,13 @@ function toCoreTool(
7085 */
7186 export async function* runTurn(options: {
7287 model: CoreModel;
88+ modelString: string;
7389 messages: CoreMessage[];
7490 tools: ToolDef[];
7591 systemPrompt?: string;
7692 signal?: AbortSignal;
7793 }): AsyncGenerator<TurnEvent> {
78- const { model, messages, tools, systemPrompt, signal } = options;
94+ const { model, modelString, messages, tools, systemPrompt, signal } = options;
7995
8096 // stepCount tracks completed steps (incremented in onStepFinish).
8197 // Used to detect the second-to-last step for the warning injection.
@@ -109,6 +125,21 @@ export async function* runTurn(options: {
109125 let contextTokens = 0;
110126
111127 try {
128+ // OpenAI GPT models use the Responses API (@ai-sdk/openai v3 / ai v6 default),
129+ // which honours `instructions` as the authoritative system prompt. Passing it
130+ // as a system-role message in `input` works but is treated as a lower-priority
131+ // user turn, causing the model to deprioritise the instructions.
132+ const useInstructions =
133+ systemPrompt !== undefined &&
134+ modelString !== undefined &&
135+ isOpenAIGPT(modelString);
136+
137+ // GPT models tend to describe planned tool calls without making them, then
138+ // yield back to the user. This applies broadly across the gpt-* family.
139+ // The one-liner closes that gap without adding opinion about how to do the task.
140+ const GPT_CONTINUATION =
141+ "\n\nAlways make tool calls rather than describing them. Keep going until the task is complete, then stop.";
142+
112143 const streamOpts: StreamTextOptions = {
113144 model,
114145 messages,
@@ -130,7 +161,17 @@ export async function* runTurn(options: {
130161 return undefined;
131162 },
132163
133- ...(systemPrompt ? { system: systemPrompt } : {}),
164+ ...(systemPrompt && !useInstructions ? { system: systemPrompt } : {}),
165+ ...(useInstructions
166+ ? {
167+ providerOptions: {
168+ openai: {
169+ instructions: systemPrompt + GPT_CONTINUATION,
170+ store: false,
171+ },
172+ },
173+ }
174+ : {}),
134175 ...(signal ? { abortSignal: signal } : {}),
135176 };