@@ -54,6 +54,7 @@ import { RunAgentUpdatedStreamEvent, RunRawModelStreamEvent } from './events';
5454import { RunState } from './runState' ;
5555import { StreamEventResponseCompleted } from './types/protocol' ;
5656import { convertAgentOutputTypeToSerializable } from './utils/tools' ;
57+ import { gpt5ReasoningSettingsRequired , isGpt5Default } from './defaultModel' ;
5758
5859const DEFAULT_MAX_TURNS = 10 ;
5960
@@ -369,6 +370,14 @@ export class Runner extends RunHooks<any, AgentOutputType<unknown>> {
369370 ...this . config . modelSettings ,
370371 ...state . _currentAgent . modelSettings ,
371372 } ;
373+ const agentModel = state . _currentAgent . model ;
374+ const agentModelSettings = state . _currentAgent . modelSettings ;
375+ modelSettings = sanitizeModelSettingsForNonGpt5Runner (
376+ agentModel ,
377+ agentModelSettings ,
378+ model ,
379+ modelSettings ,
380+ ) ;
372381 modelSettings = maybeResetToolChoice (
373382 state . _currentAgent ,
374383 state . _toolUseTracker ,
@@ -709,6 +718,14 @@ export class Runner extends RunHooks<any, AgentOutputType<unknown>> {
709718 ...this . config . modelSettings ,
710719 ...currentAgent . modelSettings ,
711720 } ;
721+ const agentModel = currentAgent . model ;
722+ const agentModelSettings = currentAgent . modelSettings ;
723+ modelSettings = sanitizeModelSettingsForNonGpt5Runner (
724+ agentModel ,
725+ agentModelSettings ,
726+ model ,
727+ modelSettings ,
728+ ) ;
712729 modelSettings = maybeResetToolChoice (
713730 currentAgent ,
714731 result . state . _toolUseTracker ,
@@ -1029,3 +1046,36 @@ export async function run<TAgent extends Agent<any, any>, TContext = undefined>(
10291046 return await runner . run ( agent , input , options ) ;
10301047 }
10311048}
1049+
1050+ /**
1051+ * When the default model is a GPT-5 variant, agents may carry GPT-5-specific providerData
1052+ * (e.g., reasoning effort, text verbosity). If a run resolves to a non-GPT-5 model and the
1053+ * agent relied on the default model (i.e., no explicit model set), these GPT-5-only settings
1054+ * are incompatible and should be stripped to avoid runtime errors.
1055+ */
1056+ function sanitizeModelSettingsForNonGpt5Runner (
1057+ agentModel : string | Model ,
1058+ agentModelSettings : ModelSettings ,
1059+ runnerModel : string | Model ,
1060+ modelSettings : ModelSettings ,
1061+ ) : ModelSettings {
1062+ if (
1063+ // gpt-5 is enabled for the default model for agents
1064+ isGpt5Default ( ) &&
1065+ // no explicitly set model for the agent
1066+ typeof agentModel === 'string' &&
1067+ agentModel === Agent . DEFAULT_MODEL_PLACEHOLDER &&
1068+ // this runner uses a non-gpt-5 model
1069+ ( typeof runnerModel !== 'string' ||
1070+ ! gpt5ReasoningSettingsRequired ( runnerModel ) ) &&
1071+ ( agentModelSettings . providerData ?. reasoning ||
1072+ agentModelSettings . providerData ?. text ?. verbosity ||
1073+ ( agentModelSettings . providerData as any ) ?. reasoning_effort )
1074+ ) {
1075+ // the incompatible parameters should be removed to avoid runtime errors
1076+ delete modelSettings . providerData ?. reasoning ;
1077+ delete ( modelSettings . providerData as any ) ?. text ?. verbosity ;
1078+ delete ( modelSettings . providerData as any ) ?. reasoning_effort ;
1079+ }
1080+ return modelSettings ;
1081+ }
0 commit comments