88from pathlib import Path
99import ldclient
1010from ldclient import Context
11- from ldai . client import LDAIClient , LDAIAgentConfig , LDAIAgentDefaults , ModelConfig , ProviderConfig
11+ from ldai import LDAIClient , AIAgentConfigRequest , AIAgentConfigDefault , ModelConfig , ProviderConfig
1212from ldai .tracker import FeedbackKind
1313from dotenv import load_dotenv
1414from utils .logger import log_student , log_debug
@@ -68,14 +68,14 @@ def _load_config_defaults(self):
6868 " ld-aic validate --config-keys 'supervisor-agent,support-agent,security-agent'"
6969 )
7070
71- def _get_default_config (self , config_key : str ) -> LDAIAgentDefaults :
71+ def _get_default_config (self , config_key : str ) -> AIAgentConfigDefault :
7272 """Get fallback config from .ai_config_defaults.json
7373
7474 Args:
7575 config_key: The AI config key (e.g., 'support-agent')
7676
7777 Returns:
78- LDAIAgentDefaults object with config from the defaults file
78+ AIAgentConfigDefault object with config from the defaults file
7979
8080 Raises:
8181 ValueError: If config key not found in defaults
@@ -93,9 +93,9 @@ def _get_default_config(self, config_key: str) -> LDAIAgentDefaults:
9393
9494 config_data = self .config_defaults [config_key ]
9595
96- # Convert JSON config to LDAIAgentDefaults
96+ # Convert JSON config to AIAgentConfigDefault
9797 # Note: Tools are managed by LaunchDarkly and not part of defaults
98- return LDAIAgentDefaults (
98+ return AIAgentConfigDefault (
9999 enabled = config_data .get ("enabled" , True ),
100100 model = ModelConfig (
101101 name = config_data ["model" ]["name" ],
@@ -207,21 +207,21 @@ async def get_config(self, user_id: str, config_key: str = None, user_context: d
207207 default_config = self ._get_default_config (ai_config_key )
208208 log_debug (f"CONFIG MANAGER: Loaded fallback default - model: { default_config .model .name } " )
209209
210- agent_config = LDAIAgentConfig (
211- key = ai_config_key ,
212- default_value = default_config # Use validated production defaults from file
210+ # Call LaunchDarkly - SDK automatically falls back to default if LD unavailable
211+ result = self .ai_client .agent_config (
212+ ai_config_key ,
213+ ld_user_context ,
214+ default = default_config , # Use validated production defaults from file
213215 )
214-
215- # Call LaunchDarkly - SDK automatically falls back to default_value if LD unavailable
216- result = self .ai_client .agent (agent_config , ld_user_context )
217216 log_debug ("CONFIG MANAGER: ✅ Got config (from LaunchDarkly or fallback)" )
218217
219218 # Debug the actual configuration received (basic info only)
220219 try :
221220 config_dict = result .to_dict ()
222221 log_debug (f"CONFIG MANAGER: Model: { config_dict .get ('model' , {}).get ('name' , 'unknown' )} " )
223- if hasattr (result , 'tracker' ) and hasattr (result .tracker , '_variation_key' ):
224- log_debug (f"CONFIG MANAGER: Variation: { result .tracker ._variation_key } " )
222+ tracker = result .create_tracker ()
223+ if hasattr (tracker , '_variation_key' ):
224+ log_debug (f"CONFIG MANAGER: Variation: { tracker ._variation_key } " )
225225 except Exception as debug_e :
226226 log_debug (f"CONFIG MANAGER: Could not debug result: { debug_e } " )
227227
@@ -251,10 +251,11 @@ def track_cost_metric(self, agent_config, context, cost, config_key):
251251 """
252252 try :
253253 # Extract metadata from agent_config for experiment attribution
254+ tracker = agent_config .create_tracker ()
254255 metadata = {
255256 "version" : 1 ,
256257 "configKey" : config_key ,
257- "variationKey" : agent_config . tracker ._variation_key if hasattr (agent_config . tracker , '_variation_key' ) else 'unknown' ,
258+ "variationKey" : tracker ._variation_key if hasattr (tracker , '_variation_key' ) else 'unknown' ,
258259 "modelName" : agent_config .model .name if hasattr (agent_config , 'model' ) else 'unknown' ,
259260 "providerName" : agent_config .provider .name if hasattr (agent_config , 'provider' ) else 'unknown'
260261 }
0 commit comments