@@ -254,6 +254,10 @@ export class Runner extends RunHooks<any, AgentOutputType<unknown>> {
254254
255255 try {
256256 while ( true ) {
257+ const explictlyModelSet =
258+ ( state . _currentAgent . model !== undefined &&
259+ state . _currentAgent . model !== '' ) ||
260+ ( this . config . model !== undefined && this . config . model !== '' ) ;
257261 let model = selectModel ( state . _currentAgent . model , this . config . model ) ;
258262
259263 if ( typeof model === 'string' ) {
@@ -370,10 +374,9 @@ export class Runner extends RunHooks<any, AgentOutputType<unknown>> {
370374 ...this . config . modelSettings ,
371375 ...state . _currentAgent . modelSettings ,
372376 } ;
373- const agentModel = state . _currentAgent . model ;
374377 const agentModelSettings = state . _currentAgent . modelSettings ;
375- modelSettings = sanitizeModelSettingsForNonGpt5Runner (
376- agentModel ,
378+ modelSettings = adjustModelSettingsForNonGPT5RunnerModel (
379+ explictlyModelSet ,
377380 agentModelSettings ,
378381 model ,
379382 modelSettings ,
@@ -704,6 +707,9 @@ export class Runner extends RunHooks<any, AgentOutputType<unknown>> {
704707 `Running agent ${ currentAgent . name } (turn ${ result . state . _currentTurn } )` ,
705708 ) ;
706709
710+ const explictlyModelSet =
711+ ( currentAgent . model !== undefined && currentAgent . model !== '' ) ||
712+ ( this . config . model !== undefined && this . config . model !== '' ) ;
707713 let model = selectModel ( currentAgent . model , this . config . model ) ;
708714
709715 if ( typeof model === 'string' ) {
@@ -718,10 +724,9 @@ export class Runner extends RunHooks<any, AgentOutputType<unknown>> {
718724 ...this . config . modelSettings ,
719725 ...currentAgent . modelSettings ,
720726 } ;
721- const agentModel = currentAgent . model ;
722727 const agentModelSettings = currentAgent . modelSettings ;
723- modelSettings = sanitizeModelSettingsForNonGpt5Runner (
724- agentModel ,
728+ modelSettings = adjustModelSettingsForNonGPT5RunnerModel (
729+ explictlyModelSet ,
725730 agentModelSettings ,
726731 model ,
727732 modelSettings ,
@@ -1053,18 +1058,17 @@ export async function run<TAgent extends Agent<any, any>, TContext = undefined>(
10531058 * agent relied on the default model (i.e., no explicit model set), these GPT-5-only settings
10541059 * are incompatible and should be stripped to avoid runtime errors.
10551060 */
1056- function sanitizeModelSettingsForNonGpt5Runner (
1057- agentModel : string | Model ,
1061+ function adjustModelSettingsForNonGPT5RunnerModel (
1062+ explictlyModelSet : boolean ,
10581063 agentModelSettings : ModelSettings ,
10591064 runnerModel : string | Model ,
10601065 modelSettings : ModelSettings ,
10611066) : ModelSettings {
10621067 if (
10631068 // gpt-5 is enabled for the default model for agents
10641069 isGpt5Default ( ) &&
1065- // no explicitly set model for the agent
1066- typeof agentModel === 'string' &&
1067- agentModel === Agent . DEFAULT_MODEL_PLACEHOLDER &&
1070+ // explicitly set model for the agent
1071+ explictlyModelSet &&
10681072 // this runner uses a non-gpt-5 model
10691073 ( typeof runnerModel !== 'string' ||
10701074 ! gpt5ReasoningSettingsRequired ( runnerModel ) ) &&
0 commit comments