88from pydantic import BaseModel , Field
99from rich .console import Console
1010
11- from agentex .lib .cli .utils .auth_utils import _encode_principal_context
1211from agentex .lib .cli .utils .exceptions import DeploymentError , HelmError
1312from agentex .lib .cli .utils .kubectl_utils import check_and_switch_cluster_context
1413from agentex .lib .cli .utils .path_utils import calculate_docker_acp_module , PathResolutionError
@@ -116,6 +115,7 @@ def add_acp_command_to_helm_values(helm_values: dict[str, Any], manifest: AgentM
116115
117116def merge_deployment_configs (
118117 manifest : AgentManifest ,
118+ agent_env_config ,
119119 cluster_config : ClusterConfig | None ,
120120 deploy_overrides : InputDeployOverrides ,
121121 manifest_path : str ,
@@ -193,10 +193,12 @@ def merge_deployment_configs(
193193 if agent_config .env :
194194 all_env_vars .update (agent_config .env )
195195
196- # Add auth principal env var if manifest principal is set
197- encoded_principal = _encode_principal_context (manifest )
198- if encoded_principal :
199- all_env_vars [EnvVarKeys .AUTH_PRINCIPAL_B64 .value ] = encoded_principal
196+ # Add auth principal env var if environment config is set
197+ if agent_env_config and agent_env_config .auth :
198+ from agentex .lib .cli .utils .auth_utils import _encode_principal_context_from_env_config
199+ encoded_principal = _encode_principal_context_from_env_config (agent_env_config .auth )
200+ if encoded_principal :
201+ all_env_vars [EnvVarKeys .AUTH_PRINCIPAL_B64 .value ] = encoded_principal
200202
201203 # Handle credentials and check for conflicts
202204 if agent_config .credentials :
@@ -278,6 +280,11 @@ def merge_deployment_configs(
278280 if cluster_config .additional_overrides :
279281 _deep_merge (helm_values , cluster_config .additional_overrides )
280282
283+ # Apply agent environment configuration overrides
284+ if agent_env_config :
285+ if agent_env_config .helm_overrides :
286+ _deep_merge (helm_values , agent_env_config .helm_overrides )
287+
281288 # Set final environment variables
282289 if all_env_vars :
283290 helm_values ["env" ] = convert_env_vars_dict_to_list (all_env_vars )
@@ -334,6 +341,7 @@ def deploy_agent(
334341 namespace : str ,
335342 deploy_overrides : InputDeployOverrides ,
336343 override_file_path : str | None = None ,
344+ environment_name : str | None = None ,
337345) -> None :
338346 """Deploy an agent using helm"""
339347
@@ -347,6 +355,17 @@ def deploy_agent(
347355 manifest = AgentManifest .from_yaml (file_path = manifest_path )
348356 override_config = load_override_config (override_file_path )
349357
358+ # Load agent environment configuration
359+ agent_env_config = None
360+ if environment_name :
361+ manifest_dir = Path (manifest_path ).parent
362+ environments_config = manifest .load_environments_config (manifest_dir )
363+ if environments_config :
364+ agent_env_config = environments_config .get_config_for_env (environment_name )
365+ console .print (f"[green]✓[/green] Using environment config: { environment_name } " )
366+ else :
367+ console .print (f"[yellow]⚠[/yellow] No environments.yaml found, skipping environment-specific config" )
368+
350369 # Provide feedback about override configuration
351370 if override_config :
352371 console .print (f"[green]✓[/green] Using override config: { override_file_path } " )
@@ -359,7 +378,7 @@ def deploy_agent(
359378 add_helm_repo ()
360379
361380 # Merge configurations
362- helm_values = merge_deployment_configs (manifest , override_config , deploy_overrides , manifest_path )
381+ helm_values = merge_deployment_configs (manifest , agent_env_config , override_config , deploy_overrides , manifest_path )
363382
364383 # Create values file
365384 values_file = create_helm_values_file (helm_values )
0 commit comments