@@ -38,6 +38,8 @@ export default function AgentSetupOrchestrator({
3838 setIsCreatingNewAgent,
3939 mainAgentModel,
4040 setMainAgentModel,
41+ mainAgentModelId,
42+ setMainAgentModelId,
4143 mainAgentMaxStep,
4244 setMainAgentMaxStep,
4345 tools,
@@ -167,6 +169,10 @@ export default function AgentSetupOrchestrator({
167169 }
168170 // Update the model
169171 setMainAgentModel ( modelName ) ;
172+ // Update the model ID if available
173+ if ( result . data . model_id ) {
174+ setMainAgentModelId ( result . data . model_id ) ;
175+ }
170176 // Update the maximum number of steps
171177 if ( maxSteps ) {
172178 setMainAgentMaxStep ( maxSteps ) ;
@@ -207,6 +213,7 @@ export default function AgentSetupOrchestrator({
207213 // Only clear and get new Agent configuration in creating mode
208214 setBusinessLogic ( "" ) ;
209215 setMainAgentModel ( null ) ; // Clear model selection when creating new agent
216+ setMainAgentModelId ( null ) ; // Clear model ID when creating new agent
210217 fetchSubAgentIdAndEnableToolList ( t ) ;
211218 } else {
212219 // In edit mode, data is loaded in handleEditAgent, here validate the form
@@ -217,6 +224,7 @@ export default function AgentSetupOrchestrator({
217224 if ( ! isEditingAgent && hasInitialized . current ) {
218225 setBusinessLogic ( "" ) ;
219226 setMainAgentModel ( null ) ;
227+ setMainAgentModelId ( null ) ;
220228 setMainAgentMaxStep ( 5 ) ;
221229 // Delay refreshing agent list to avoid jumping
222230 setTimeout ( ( ) => {
@@ -408,7 +416,8 @@ export default function AgentSetupOrchestrator({
408416 dutyContent ,
409417 constraintContent ,
410418 fewShotsContent ,
411- agentDisplayName
419+ agentDisplayName ,
420+ mainAgentModelId ?? undefined
412421 ) ;
413422 } else {
414423 result = await updateAgent (
@@ -423,7 +432,8 @@ export default function AgentSetupOrchestrator({
423432 dutyContent ,
424433 constraintContent ,
425434 fewShotsContent ,
426- agentDisplayName
435+ agentDisplayName ,
436+ mainAgentModelId ?? undefined
427437 ) ;
428438 }
429439
@@ -542,6 +552,7 @@ export default function AgentSetupOrchestrator({
542552
543553 // Load Agent data to interface
544554 setMainAgentModel ( agentDetail . model ) ;
555+ setMainAgentModelId ( agentDetail . model_id ) ;
545556 setMainAgentMaxStep ( agentDetail . max_step ) ;
546557 setBusinessLogic ( agentDetail . business_description || "" ) ;
547558
@@ -584,15 +595,54 @@ export default function AgentSetupOrchestrator({
584595 } ;
585596
586597 // Handle the update of the model
587- const handleModelChange = async ( value : string ) => {
598+ const handleModelChange = async ( value : string , modelId ?: number ) => {
588599 const targetAgentId =
589600 isEditingAgent && editingAgent ? editingAgent . id : mainAgentId ;
590601
591602 if ( ! targetAgentId ) {
592603 message . error ( t ( "businessLogic.config.error.noAgentId" ) ) ;
593604 return ;
594605 }
606+
607+ // Update local state first
595608 setMainAgentModel ( value ) ;
609+ if ( modelId !== undefined ) {
610+ setMainAgentModelId ( modelId ) ;
611+ }
612+
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+ }
596646 } ;
597647
598648 // Handle the update of the maximum number of steps
@@ -607,7 +657,40 @@ export default function AgentSetupOrchestrator({
607657
608658 const newValue = value ?? 5 ;
609659
660+ // Update local state first
610661 setMainAgentMaxStep ( newValue ) ;
662+
663+ // Call updateAgent API to save the max steps change
664+ try {
665+ const result = await updateAgent (
666+ Number ( targetAgentId ) ,
667+ undefined , // name
668+ undefined , // description
669+ undefined , // modelName
670+ newValue , // maxSteps
671+ undefined , // provideRunSummary
672+ undefined , // enabled
673+ undefined , // businessDescription
674+ undefined , // dutyPrompt
675+ undefined , // constraintPrompt
676+ undefined , // fewShotsPrompt
677+ undefined , // displayName
678+ undefined // modelId
679+ ) ;
680+
681+ if ( ! result . success ) {
682+ message . error (
683+ result . message || t ( "businessLogic.config.error.maxStepsUpdateFailed" )
684+ ) ;
685+ // Revert local state on failure
686+ setMainAgentMaxStep ( mainAgentMaxStep ) ;
687+ }
688+ } catch ( error ) {
689+ log . error ( "Error updating agent max steps:" , error ) ;
690+ message . error ( t ( "businessLogic.config.error.maxStepsUpdateFailed" ) ) ;
691+ // Revert local state on failure
692+ setMainAgentMaxStep ( mainAgentMaxStep ) ;
693+ }
611694 } ;
612695
613696 // Handle importing agent
@@ -871,9 +954,10 @@ export default function AgentSetupOrchestrator({
871954 onAgentDisplayNameChange = { setAgentDisplayName }
872955 isEditingMode = { isEditingAgent || isCreatingNewAgent }
873956 mainAgentModel = { mainAgentModel ?? undefined }
957+ mainAgentModelId = { mainAgentModelId }
874958 mainAgentMaxStep = { mainAgentMaxStep }
875- onModelChange = { ( value : string ) =>
876- handleModelChange ( value )
959+ onModelChange = { ( value : string , modelId ?: number ) =>
960+ handleModelChange ( value , modelId )
877961 }
878962 onMaxStepChange = { handleMaxStepChange }
879963 onBusinessLogicChange = { ( value : string ) => setBusinessLogic ( value ) }
0 commit comments