🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix: strip temperature/top_p for Claude Opus 4.7 (#13909)
YuTengjingd658daa95d98
diff --git a/packages/model-bank/src/aiModels/lobehub/chat/anthropic.ts b/packages/model-bank/src/aiModels/lobehub/chat/anthropic.tsindex 89a3f7ee7f3..7c66cddd4e2 100644--- a/packages/model-bank/src/aiModels/lobehub/chat/anthropic.ts+++ b/packages/model-bank/src/aiModels/lobehub/chat/anthropic.ts@@ -106,6 +106,7 @@ export const anthropicChatModels: AIChatModelCard[] = [},releasedAt: '2026-04-16',settings: {+ disabledParams: ['temperature', 'top_p'],extendParams: ['disableContextCaching', 'enableAdaptiveThinking', 'opus47Effort'],},type: 'chat',diff --git a/packages/model-bank/src/types/aiModel.ts b/packages/model-bank/src/types/aiModel.tsindex 383f841ae08..eb94d1712a0 100644--- a/packages/model-bank/src/types/aiModel.ts+++ b/packages/model-bank/src/types/aiModel.ts@@ -270,7 +270,15 @@ export type ExtendParamsType =| 'imageResolution2'| 'urlContext';+export type DisabledParamType = 'temperature' | 'top_p' | 'frequency_penalty' | 'presence_penalty';+export interface AiModelSettings {+ /**+ * Chat params that should be hidden from the agent config UI and stripped from+ * outbound requests. Use this for models whose API rejects specific sampling+ * params (e.g. Claude Opus 4.7 returns 400 on any non-default temperature / top_p).+ */+ disabledParams?: DisabledParamType[];extendParams?: ExtendParamsType[];/*** How the model layer implements search@@ -312,7 +320,15 @@ export const ExtendParamsTypeSchema = z.enum([export const ModelSearchImplementTypeSchema = z.enum(['tool', 'params', 'internal']);+export const DisabledParamTypeSchema = z.enum([+ 'temperature',+ 'top_p',+ 'frequency_penalty',+ 'presence_penalty',+]);+export const AiModelSettingsSchema = z.object({+ disabledParams: z.array(DisabledParamTypeSchema).optional(),extendParams: z.array(ExtendParamsTypeSchema).optional(),searchImpl: ModelSearchImplementTypeSchema.optional(),searchProvider: z.string().optional(),diff --git a/packages/model-runtime/src/const/models.ts b/packages/model-runtime/src/const/models.tsindex 3b7cc903cd8..b5d2abefbcb 100644--- a/packages/model-runtime/src/const/models.ts+++ b/packages/model-runtime/src/const/models.ts@@ -113,3 +113,24 @@ export const temperatureTopPConflictModelPatterns: RegExp[] = [export const hasTemperatureTopPConflict = (model: string): boolean => {return temperatureTopPConflictModelPatterns.some((pattern) => pattern.test(model));};++/**+ * Regex patterns for models that reject any non-default temperature / top_p / top_k.+ * These sampling parameters must be omitted from the request payload entirely;+ * otherwise the API returns a 400 error.+ *+ * Ref: https://platform.claude.com/docs/en/about-claude/models/migration-guide+ */+export const omitSamplingParamsModelPatterns: RegExp[] = [+ // Claude Opus 4.7 - Anthropic API (also LobeHub provider pass-through)+ /^claude-opus-4-7/,+ // OpenRouter formats use dot notation (e.g. anthropic/claude-opus-4.7)+ /^anthropic\/claude-opus-4\.7/,+ /^anthropic\/claude-4\.7-opus/,+ // AWS Bedrock formats (e.g. anthropic.claude-opus-4-7, us.anthropic.claude-opus-4-7-v1)+ /anthropic\.claude-opus-4-7/,+];++export const shouldOmitSamplingParams = (model: string): boolean => {+ return omitSamplingParamsModelPatterns.some((pattern) => pattern.test(model));+};diff --git a/packages/model-runtime/src/core/parameterResolver.test.ts b/packages/model-runtime/src/core/parameterResolver.test.tsindex 1506590c73a..9b77a185acd 100644--- a/packages/model-runtime/src/core/parameterResolver.test.ts+++ b/packages/model-runtime/src/core/parameterResolver.test.ts@@ -1,6 +1,6 @@import { describe, expect, it } from 'vitest';-import { hasTemperatureTopPConflict } from '../const/models';+import { hasTemperatureTopPConflict, shouldOmitSamplingParams } from '../const/models';import {createParameterResolver,resolveModelSamplingParameters,@@ -277,6 +277,39 @@ describe('resolveModelSamplingParameters', () => {expect(result).not.toHaveProperty('temperature');expect(result).not.toHaveProperty('top_p');});++ it('should omit temperature and top_p for models that reject sampling params', () => {+ const result = resolveModelSamplingParameters(+ 'claude-opus-4-7',+ { temperature: 0.7, top_p: 0.9 },+ { normalizeTemperature: false, preferTemperature: true },+ );++ // Both keys present with undefined values so spreading clears any pre-set payload fields+ expect(result).toEqual({ temperature: undefined, top_p: undefined });+ });++ it('should omit temperature and top_p for Bedrock Opus 4.7 id', () => {+ const result = resolveModelSamplingParameters(+ 'us.anthropic.claude-opus-4-7-v1',+ { temperature: 0.7, top_p: 0.9 },+ { normalizeTemperature: false, preferTemperature: true },+ );++ expect(result).toEqual({ temperature: undefined, top_p: undefined });+ });++ it('should not add spurious keys when omit-model input has no sampling fields', () => {+ const result = resolveModelSamplingParameters(+ 'claude-opus-4-7',+ {},+ { normalizeTemperature: false, preferTemperature: true },+ );++ expect(result).toEqual({});+ expect(result).not.toHaveProperty('temperature');+ expect(result).not.toHaveProperty('top_p');+ });});describe('createParameterResolver', () => {@@ -341,3 +374,36 @@ describe('hasTemperatureTopPConflict', () => {});});});++describe('shouldOmitSamplingParams', () => {+ it('should return true for Claude Opus 4.7 (Anthropic API id)', () => {+ expect(shouldOmitSamplingParams('claude-opus-4-7')).toBe(true);+ });++ it('should return true for Claude Opus 4.7 on Bedrock (with and without region prefix)', () => {+ expect(shouldOmitSamplingParams('anthropic.claude-opus-4-7')).toBe(true);+ expect(shouldOmitSamplingParams('us.anthropic.claude-opus-4-7-v1')).toBe(true);+ });++ it('should return true for Claude Opus 4.7 on OpenRouter (dot notation)', () => {+ expect(shouldOmitSamplingParams('anthropic/claude-opus-4.7')).toBe(true);+ expect(shouldOmitSamplingParams('anthropic/claude-4.7-opus')).toBe(true);+ });++ it('should return false for hypothetical dash-form OpenRouter id', () => {+ // OpenRouter uses dot notation; dash form is not a real id and must not match+ // to avoid accidentally stripping params from unrelated future model ids.+ expect(shouldOmitSamplingParams('anthropic/claude-opus-4-7')).toBe(false);+ });++ it('should return false for Claude Opus 4.6 and earlier', () => {+ expect(shouldOmitSamplingParams('claude-opus-4-6')).toBe(false);+ expect(shouldOmitSamplingParams('claude-sonnet-4-5-20250929')).toBe(false);+ expect(shouldOmitSamplingParams('anthropic.claude-opus-4-6-v1')).toBe(false);+ });++ it('should return false for non-Claude models', () => {+ expect(shouldOmitSamplingParams('gpt-4o')).toBe(false);+ expect(shouldOmitSamplingParams('gemini-2.5-pro')).toBe(false);+ });+});diff --git a/packages/model-runtime/src/core/parameterResolver.ts b/packages/model-runtime/src/core/parameterResolver.tsindex 8657709c14d..40c37848299 100644--- a/packages/model-runtime/src/core/parameterResolver.ts+++ b/packages/model-runtime/src/core/parameterResolver.ts@@ -1,4 +1,4 @@-import { hasTemperatureTopPConflict } from '../const/models';+import { hasTemperatureTopPConflict, shouldOmitSamplingParams } from '../const/models';/*** Chat completion parameter configuration@@ -264,6 +264,16 @@ export const resolveModelSamplingParameters = (const temperature = config.temperature ?? undefined;const top_p = config.top_p ?? undefined;+ // Some models (e.g. Claude Opus 4.7) reject any non-default temperature / top_p+ // and return a 400 error. Omit both parameters entirely — callers spread the+ // returned object, so setting the key to undefined lets JSON.stringify drop it.+ if (model && shouldOmitSamplingParams(model)) {+ const result: { temperature?: number; top_p?: number } = {};+ if (temperature !== undefined) result.temperature = undefined;+ if (top_p !== undefined) result.top_p = undefined;+ return result;+ }+const resolved = resolveParameters({ temperature, top_p },{diff --git a/src/features/AgentSetting/AgentModal/index.tsx b/src/features/AgentSetting/AgentModal/index.tsxindex 1ffeea4d7dc..e4640f75040 100644--- a/src/features/AgentSetting/AgentModal/index.tsx+++ b/src/features/AgentSetting/AgentModal/index.tsx@@ -10,6 +10,7 @@ import { useTranslation } from 'react-i18next';import InfoTooltip from '@/components/InfoTooltip';import { FORM_STYLE } from '@/const/layoutTokens';+import { aiModelSelectors, useAiInfraStore } from '@/store/aiInfra';import { selectors, useStore } from '../store';@@ -225,7 +226,16 @@ const AgentModal = memo(() => {[form],);- const paramItems: FormItemProps[] = (Object.keys(PARAM_CONFIG) as ParamKey[]).map((key) => {+ // Hide params the selected model rejects outright (e.g. Claude Opus 4.7 drops+ // temperature / top_p). Declared via `settings.disabledParams` on the model card.+ const disabledParams = useAiInfraStore(+ aiModelSelectors.modelDisabledParams(config.model, config.provider ?? ''),+ );+ const visibleParamKeys = (Object.keys(PARAM_CONFIG) as ParamKey[]).filter(+ (key) => !disabledParams?.includes(key),+ );++ const paramItems: FormItemProps[] = visibleParamKeys.map((key) => {const meta = PARAM_CONFIG[key];const enabled = enabledMap[key];diff --git a/src/store/aiInfra/slices/aiModel/selectors.test.ts b/src/store/aiInfra/slices/aiModel/selectors.test.tsindex 01f6803a692..3c761d069c7 100644--- a/src/store/aiInfra/slices/aiModel/selectors.test.ts+++ b/src/store/aiInfra/slices/aiModel/selectors.test.ts@@ -47,6 +47,9 @@ describe('aiModelSelectors', () => {reasoning: true,},contextWindowTokens: 4000,+ settings: {+ disabledParams: ['temperature', 'top_p'],+ },type: 'chat',},{@@ -228,4 +231,25 @@ describe('aiModelSelectors', () => {).toBeUndefined();});});++ describe('modelDisabledParams', () => {+ it('should return disabledParams when declared on the model card', () => {+ expect(aiModelSelectors.modelDisabledParams('model1', 'provider1')(mockState)).toEqual([+ 'temperature',+ 'top_p',+ ]);+ });++ it('should return undefined when the model has no settings', () => {+ expect(+ aiModelSelectors.modelDisabledParams('model4', 'provider2')(mockState),+ ).toBeUndefined();+ });++ it('should return undefined for an unknown model', () => {+ expect(+ aiModelSelectors.modelDisabledParams('missing', 'provider1')(mockState),+ ).toBeUndefined();+ });+ });});diff --git a/src/store/aiInfra/slices/aiModel/selectors.ts b/src/store/aiInfra/slices/aiModel/selectors.tsindex b77fe792c77..f9352584a1f 100644--- a/src/store/aiInfra/slices/aiModel/selectors.ts+++ b/src/store/aiInfra/slices/aiModel/selectors.ts@@ -93,6 +93,12 @@ const modelExtendParams = (id: string, provider: string) => (s: AIProviderStoreSreturn model?.settings?.extendParams;};+const modelDisabledParams = (id: string, provider: string) => (s: AIProviderStoreState) => {+ const model = getEnabledModelById(id, provider)(s);++ return model?.settings?.disabledParams;+};+const isModelHasExtendParams = (id: string, provider: string) => (s: AIProviderStoreState) => {const controls = modelExtendParams(id, provider)(s);@@ -155,6 +161,7 @@ export const aiModelSelectors = {isModelSupportVision,modelBuiltinSearchImpl,modelContextWindowTokens,+ modelDisabledParams,modelExtendParams,totalAiProviderModelList,};