@@ -662,6 +662,8 @@ async def model_types(controller: BaseModelController = Depends(get_model_contro
662662 logger .info ("/controller/model/types" )
663663 try :
664664 types = set ()
665+
666+ # 1. Get models from controller (old worker-based models)
665667 models = await controller .get_all_instances (healthy_only = True )
666668 for model in models :
667669 worker_name , worker_type = model .model_name .split ("@" )
@@ -670,6 +672,67 @@ async def model_types(controller: BaseModelController = Depends(get_model_contro
670672 "text2sql_proxyllm" ,
671673 ]:
672674 types .add (worker_name )
675+
676+ # 2. Get models from system_app.config (JSON configuration)
677+ system_app = SystemApp .get_instance ()
678+ if system_app and system_app .config :
679+ # Try "agent.llm" direct key
680+ agent_llm_conf = system_app .config .get ("agent.llm" )
681+
682+ # If not found, try "agent" -> "llm" (nested dict access)
683+ if not agent_llm_conf :
684+ agent_conf = system_app .config .get ("agent" )
685+ if isinstance (agent_conf , dict ):
686+ agent_llm_conf = agent_conf .get ("llm" )
687+
688+ # Check for flattened keys (fallback)
689+ if not agent_llm_conf :
690+ flattened = system_app .config .get_all_by_prefix ("agent.llm." )
691+ if flattened :
692+ agent_llm_conf = {}
693+ prefix_len = len ("agent.llm." )
694+ for k , v in flattened .items ():
695+ agent_llm_conf [k [prefix_len :]] = v
696+
697+ # Also try app_config from configs dict (JSON config source)
698+ if not agent_llm_conf :
699+ app_config = system_app .config .configs .get ("app_config" )
700+ if app_config :
701+ agent_llm_attr = getattr (app_config , "agent_llm" , None )
702+ if agent_llm_attr :
703+ # Convert frontend format to backend format
704+ agent_llm_dict = (
705+ agent_llm_attr .model_dump (mode = "json" )
706+ if hasattr (agent_llm_attr , "model_dump" )
707+ else dict (agent_llm_attr )
708+ )
709+ # Convert providers -> provider, models -> model
710+ if "providers" in agent_llm_dict :
711+ providers = agent_llm_dict .pop ("providers" )
712+ if isinstance (providers , list ):
713+ converted = []
714+ for p in providers :
715+ if isinstance (p , dict ):
716+ cp = dict (p )
717+ if "models" in cp :
718+ cp ["model" ] = cp .pop ("models" )
719+ converted .append (cp )
720+ agent_llm_dict ["provider" ] = converted
721+ agent_llm_conf = agent_llm_dict
722+
723+ # Parse models from Multi-Provider List Structure [[agent.llm.provider]]
724+ if agent_llm_conf and isinstance (agent_llm_conf .get ("provider" ), list ):
725+ providers = agent_llm_conf .get ("provider" )
726+ for p_conf in providers :
727+ if isinstance (p_conf , dict ) and "model" in p_conf :
728+ p_models = p_conf .get ("model" )
729+ if isinstance (p_models , list ):
730+ for m in p_models :
731+ if isinstance (m , dict ) and "name" in m :
732+ m_name = m .get ("name" )
733+ # Add model name to types
734+ types .add (m_name )
735+
673736 return Result .succ (list (types ))
674737
675738 except Exception as e :
0 commit comments