@@ -167,11 +167,16 @@ export default function AgentSetupOrchestrator({
167167 } else {
168168 setEnabledAgentIds ( [ ] ) ;
169169 }
170- // Update the model
171- setMainAgentModel ( modelName ) ;
172- // Update the model ID if available
173- if ( result . data . model_id ) {
174- setMainAgentModelId ( result . data . model_id ) ;
170+ // Update the model - only if not creating a new agent (to preserve quick setup defaults)
171+ // When creating a new agent, the model will be initialized from localStorage by child components
172+ if ( ! isCreatingNewAgent || ! modelName ) {
173+ setMainAgentModel ( modelName ) ;
174+ // Update the model ID if available
175+ if ( result . data . model_id ) {
176+ setMainAgentModelId ( result . data . model_id ) ;
177+ }
178+ } else {
179+ log . info ( "[AgentSetupOrchestrator] Creating new agent - skipping model override from backend to preserve quick setup default" ) ;
175180 }
176181 // Update the maximum number of steps
177182 if ( maxSteps ) {
@@ -212,8 +217,9 @@ export default function AgentSetupOrchestrator({
212217 if ( ! isEditingAgent ) {
213218 // Only clear and get new Agent configuration in creating mode
214219 setBusinessLogic ( "" ) ;
215- setMainAgentModel ( null ) ; // Clear model selection when creating new agent
216- setMainAgentModelId ( null ) ; // Clear model ID when creating new agent
220+ // Don't clear model selection - let it use the default from global settings
221+ // setMainAgentModel(null); // Clear model selection when creating new agent
222+ // setMainAgentModelId(null); // Clear model ID when creating new agent
217223 fetchSubAgentIdAndEnableToolList ( t ) ;
218224 } else {
219225 // In edit mode, data is loaded in handleEditAgent, here validate the form
@@ -323,8 +329,24 @@ export default function AgentSetupOrchestrator({
323329 setIsEditingAgent ( false ) ;
324330 setEditingAgent ( null ) ;
325331 setIsCreatingNewAgent ( true ) ;
326- // Note: Don't clear content here - let the parent component's useEffect handle restoration
327- // The parent component will restore cached content if available
332+
333+ // Clear all content when creating new agent to avoid showing cached data
334+ setBusinessLogic ( "" ) ;
335+ setDutyContent ?.( "" ) ;
336+ setConstraintContent ?.( "" ) ;
337+ setFewShotsContent ?.( "" ) ;
338+ setAgentName ?.( "" ) ;
339+ setAgentDescription ?.( "" ) ;
340+ setAgentDisplayName ?.( "" ) ;
341+
342+ // Clear tool and agent selections
343+ setSelectedTools ( [ ] ) ;
344+ setEnabledToolIds ( [ ] ) ;
345+ setEnabledAgentIds ( [ ] ) ;
346+
347+ // Note: Don't clear model selection - let it use the default from global settings
348+ // The model will be set by the useEffect that handles default model selection
349+
328350 onEditingStateChange ?.( false , null ) ;
329351 } ;
330352
@@ -599,67 +621,47 @@ export default function AgentSetupOrchestrator({
599621 const targetAgentId =
600622 isEditingAgent && editingAgent ? editingAgent . id : mainAgentId ;
601623
602- if ( ! targetAgentId ) {
603- message . error ( t ( "businessLogic.config.error.noAgentId" ) ) ;
604- return ;
605- }
606-
624+ log . info ( "[AgentSetupOrchestrator] handleModelChange called:" , {
625+ value,
626+ modelId,
627+ targetAgentId,
628+ isCreatingNewAgent,
629+ isEditingAgent,
630+ } ) ;
631+
607632 // Update local state first
608633 setMainAgentModel ( value ) ;
609634 if ( modelId !== undefined ) {
610635 setMainAgentModelId ( modelId ) ;
611636 }
612637
613- // Call updateAgent API to save the model change
614- try {
615- const result = await updateAgent (
616- Number ( targetAgentId ) ,
617- undefined , // name
618- undefined , // description
619- value , // modelName
620- undefined , // maxSteps
621- undefined , // provideRunSummary
622- undefined , // enabled
623- undefined , // businessDescription
624- undefined , // dutyPrompt
625- undefined , // constraintPrompt
626- undefined , // fewShotsPrompt
627- undefined , // displayName
628- modelId // modelId
629- ) ;
630-
631- if ( ! result . success ) {
632- message . error (
633- result . message || t ( "businessLogic.config.error.modelUpdateFailed" )
634- ) ;
635- // Revert local state on failure
636- setMainAgentModel ( mainAgentModel ) ;
637- setMainAgentModelId ( mainAgentModelId ) ;
638- }
639- } catch ( error ) {
640- log . error ( "Error updating agent model:" , error ) ;
641- message . error ( t ( "businessLogic.config.error.modelUpdateFailed" ) ) ;
642- // Revert local state on failure
643- setMainAgentModel ( mainAgentModel ) ;
644- setMainAgentModelId ( mainAgentModelId ) ;
645- }
638+ // When editing (creating new or modifying existing), only update local state
639+ // The actual save will happen when user clicks the Save button
640+ // This ensures unsaved changes don't persist when switching between agents
641+ log . info ( "[AgentSetupOrchestrator] Model changed, updating local state only. Save will happen on Save button click." ) ;
646642 } ;
647643
648644 // Handle the update of the maximum number of steps
649645 const handleMaxStepChange = async ( value : number | null ) => {
650646 const targetAgentId =
651647 isEditingAgent && editingAgent ? editingAgent . id : mainAgentId ;
652648
653- if ( ! targetAgentId ) {
654- message . error ( t ( "businessLogic.config.error.noAgentId" ) ) ;
655- return ;
656- }
657-
658649 const newValue = value ?? 5 ;
659650
660651 // Update local state first
661652 setMainAgentMaxStep ( newValue ) ;
662653
654+ // If creating a new agent, only update local state without calling API
655+ if ( isCreatingNewAgent && ! targetAgentId ) {
656+ return ;
657+ }
658+
659+ // If no agent ID, show error and return
660+ if ( ! targetAgentId ) {
661+ message . error ( t ( "businessLogic.config.error.noAgentId" ) ) ;
662+ return ;
663+ }
664+
663665 // Call updateAgent API to save the max steps change
664666 try {
665667 const result = await updateAgent (
0 commit comments