🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(in-app-agent): force reasoning for Claude ids on the OpenAI Responses path (#16864)
David Trainade34d7e9efb3
diff --git a/worker/src/features/in-app-agent/runtime/model.ts b/worker/src/features/in-app-agent/runtime/model.tsindex b8a36b3670..3856645bca 100644--- a/worker/src/features/in-app-agent/runtime/model.ts+++ b/worker/src/features/in-app-agent/runtime/model.ts@@ -141,8 +141,17 @@ export function getInAppAgentReasoningProviderOptions(},};}- case "openai":- return resolveLangfuseAIOpenAICallFromEnv(config.baseURL).providerOptions;+ case "openai": {+ const call = resolveLangfuseAIOpenAICallFromEnv(config.baseURL);+ if (+ call.apiMode !== "responses" ||+ !config.modelId.includes(ANTHROPIC_CLAUDE_MODEL_ID_PART)+ ) {+ return call.providerOptions;+ }++ return forceResponsesReasoning(call.providerOptions);+ }case "bedrock":return getBedrockReasoningProviderOptions(config.modelId);default: {@@ -158,3 +167,24 @@ function resolveLangfuseAIOpenAICallFromEnv(baseURL: string | undefined) {useResponsesApi: env.LANGFUSE_AI_USE_RESPONSES_API,});}++// @ai-sdk/openai sends `reasoning` (and requests encrypted reasoning for+// stateless replay) only for model ids it detects as gpt/o-series reasoning+// models. `forceReasoning` extends that to Claude ids behind a Responses+// gateway. Forced reasoning also defaults `systemMessageMode` to `developer`;+// pinning it to `system` keeps the system role, so the reasoning fields are+// the only difference from the unforced request.+function forceResponsesReasoning(+ providerOptions: Extract<+ ReturnType<typeof resolveLangfuseAIOpenAICallFromEnv>,+ { apiMode: "responses" }+ >["providerOptions"],+) {+ return {+ openai: {+ ...providerOptions.openai,+ forceReasoning: true,+ systemMessageMode: "system" as const,+ },+ };+}diff --git a/worker/src/features/in-app-agent/runtime/reasoning.test.ts b/worker/src/features/in-app-agent/runtime/reasoning.test.tsindex dec8432997..98ccb72a98 100644--- a/worker/src/features/in-app-agent/runtime/reasoning.test.ts+++ b/worker/src/features/in-app-agent/runtime/reasoning.test.ts@@ -180,6 +180,69 @@ describe("OpenAI Responses request shape", () => {expect(calls).toHaveLength(1);expect(calls[0]?.url).toBe("https://llm-exec.internal/v1/responses");});++ it("requests summarized reasoning for Claude ids behind a Responses gateway", async () => {+ // @ai-sdk/openai emits `reasoning` only for model ids on its own+ // reasoning-model allowlist. Without `forceReasoning` a Claude id gets no+ // `reasoning`, so a translating gateway leaves thinking at the model+ // default (omitted display: no summary deltas, blank reasoning UI), and+ // the request does not ask for encrypted reasoning to replay on the next+ // tool step.+ Object.assign(env, { LANGFUSE_AI_USE_RESPONSES_API: "true" });++ const config = {+ provider: "openai" as const,+ modelId: "claude-opus-5",+ titleModelId: "gpt-5.6-luna",+ apiKey: "sk-test",+ baseURL: "https://llm-gateway.internal/v1",+ };+ const { calls, fetch } = createCaptureFetch(OPENAI_RESPONSES_RESPONSE);+ vi.stubGlobal("fetch", fetch);++ const model = createInAppAgentLanguageModel({ config });+ await model.doGenerate({+ prompt: [+ { role: "system" as const, content: "You are the Langfuse assistant." },+ ...userPrompt(),+ ],+ providerOptions: getInAppAgentReasoningProviderOptions(config),+ });++ expect(calls).toHaveLength(1);+ expect(calls[0]?.body.reasoning).toEqual({ summary: "auto" });+ expect(calls[0]?.body.store).toBe(false);+ expect(calls[0]?.body.include).toEqual(["reasoning.encrypted_content"]);+ // `systemMessageMode: "system"` keeps the system role.+ expect(calls[0]?.body.input).toEqual([+ { role: "system", content: "You are the Langfuse assistant." },+ { role: "user", content: [{ type: "input_text", text: "hi" }] },+ ]);+ });++ it("does not force reasoning for non-Claude custom model ids", async () => {+ Object.assign(env, { LANGFUSE_AI_USE_RESPONSES_API: "true" });++ const config = {+ provider: "openai" as const,+ modelId: "custom-chat-model",+ titleModelId: "custom-chat-model",+ apiKey: "sk-test",+ baseURL: "https://llm-gateway.internal/v1",+ };+ const { calls, fetch } = createCaptureFetch(OPENAI_RESPONSES_RESPONSE);+ vi.stubGlobal("fetch", fetch);++ const model = createInAppAgentLanguageModel({ config });+ await model.doGenerate({+ prompt: userPrompt(),+ providerOptions: getInAppAgentReasoningProviderOptions(config),+ });++ expect(calls).toHaveLength(1);+ expect(calls[0]?.body).not.toHaveProperty("reasoning");+ expect(calls[0]?.body.store).toBe(false);+ });});describe("Anthropic Messages request shape", () => {