From c1bf7a2b9bc5e8128cce309b01a41cb3ee5afcc3 Mon Sep 17 00:00:00 2001 From: lexlian <9305752+lexlian@users.noreply.github.com> Date: Fri, 22 May 2026 19:12:58 +0800 Subject: [PATCH] fix(session): inline @agent mention uses agent's configured model Closes #28809 When mentioning an agent inline (e.g. "@other hello"), the agent name lives in the parts array as AgentPartInput. createUserMessage was only reading input.agent (top-level field set by UI agent switch), which remains unset for inline mentions, causing a fallback to the default agent's model instead of the mentioned agent's configured model. Co-Authored-By: Claude Opus 4.7 --- packages/opencode/src/session/prompt.ts | 2 +- packages/opencode/test/session/prompt.test.ts | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts index fc9fa0b96a8c..43a05e03f41c 100644 --- a/packages/opencode/src/session/prompt.ts +++ b/packages/opencode/src/session/prompt.ts @@ -686,7 +686,7 @@ export const layer = Layer.effect( }) const createUserMessage = Effect.fn("SessionPrompt.createUserMessage")(function* (input: PromptInput) { - const agentName = input.agent + const agentName = input.agent ?? input.parts.find((p): p is MessageV2.AgentPartInput => p.type === "agent")?.name const ag = agentName ? yield* agents.get(agentName) : yield* agents.defaultInfo() if (!ag) { const available = (yield* agents.list()).filter((a) => !a.hidden).map((a) => a.name) diff --git a/packages/opencode/test/session/prompt.test.ts b/packages/opencode/test/session/prompt.test.ts index ff9ded4d1927..fc81bfc7a0df 100644 --- a/packages/opencode/test/session/prompt.test.ts +++ b/packages/opencode/test/session/prompt.test.ts @@ -2227,6 +2227,57 @@ noLLMServer.instance( }, ) +// Inline agent mention uses agent's configured model + +it.instance( + "inline @agent mention uses the agent's configured model instead of default", + () => + Effect.gen(function* () { + const prompt = yield* SessionPrompt.Service + const sessions = yield* Session.Service + const session = yield* sessions.create({}) + + const msg = yield* prompt.prompt({ + sessionID: session.id, + noReply: true, + parts: [ + { type: "agent", name: "other" }, + { type: "text", text: "hello from other agent" }, + ], + }) + + if (msg.info.role !== "user") throw new Error("expected user message") + expect(msg.info.model.providerID).toBe(ProviderID.make("test")) + expect(msg.info.model.modelID).toBe(ModelID.make("test-model-2")) + + yield* sessions.remove(session.id) + }), + { + config: { + ...cfg, + provider: { + ...cfg.provider, + test: { + ...cfg.provider.test, + models: { + ...cfg.provider.test.models, + "test-model-2": { + ...cfg.provider.test.models["test-model"], + id: "test-model-2", + name: "Test Model 2", + }, + }, + }, + }, + agent: { + other: { + model: "test/test-model-2", + }, + }, + }, + }, +) + // Agent / command resolution errors noLLMServer.instance(