@@ -257,6 +257,24 @@ export async function projectInferenceRoute(
257257 ? agent . model
258258 : agent ?. model ?. primary ||
259259 ( typeof defaults ?. model === "string" ? defaults . model : defaults ?. model ?. primary ) ;
260+ const agentRouteOverrides = agent
261+ ? {
262+ agentDir : agent . agentDir ,
263+ model : structuredClone ( agent . model ) ,
264+ params : structuredClone ( agent . params ) ,
265+ tools : structuredClone ( agent . tools ) ,
266+ models : projectRelevantModelMap ( {
267+ models : agent . models ,
268+ providerIds,
269+ modelId : route ?. model ,
270+ rawModel,
271+ } ) ,
272+ agentRuntime : structuredClone ( agent . agentRuntime ) ,
273+ }
274+ : undefined ;
275+ const hasAgentRouteOverrides =
276+ agentRouteOverrides !== undefined &&
277+ Object . values ( agentRouteOverrides ) . some ( ( value ) => value !== undefined ) ;
260278 let projectedRoute : DefaultInferenceRouteProjection [ "route" ] = null ;
261279 if ( route ) {
262280 const { runConfig : _runConfig , ...routeWithoutConfig } = route ;
@@ -286,21 +304,11 @@ export async function projectInferenceRoute(
286304 } ) ,
287305 agentRuntime : structuredClone ( defaults ?. agentRuntime ) ,
288306 } ,
289- ...( agent
307+ ...( agent && hasAgentRouteOverrides
290308 ? {
291309 agent : {
292310 id : normalizeAgentId ( agent . id ) ,
293- agentDir : agent . agentDir ,
294- model : structuredClone ( agent . model ) ,
295- params : structuredClone ( agent . params ) ,
296- tools : structuredClone ( agent . tools ) ,
297- models : projectRelevantModelMap ( {
298- models : agent . models ,
299- providerIds,
300- modelId : route ?. model ,
301- rawModel,
302- } ) ,
303- agentRuntime : structuredClone ( agent . agentRuntime ) ,
311+ ...agentRouteOverrides ,
304312 } ,
305313 }
306314 : { } ) ,
0 commit comments