2
2
from ldclient import Config , Context , LDClient
3
3
from ldclient .integrations .test_data import TestData
4
4
5
- from ldai .client import LDAIAgent , LDAIAgentDefaults , LDAIClient , ModelConfig , ProviderConfig
5
+ from ldai .client import (LDAIAgentDefaults , LDAIClient , ModelConfig ,
6
+ ProviderConfig )
6
7
7
8
8
9
@pytest .fixture
9
10
def td () -> TestData :
10
11
td = TestData .data_source ()
11
-
12
+
12
13
# Single agent with instructions
13
14
td .update (
14
15
td .flag ('customer-support-agent' )
@@ -116,7 +117,7 @@ def test_single_agent_basic_functionality(ldai_client: LDAIClient):
116
117
117
118
assert len (agents ) == 1
118
119
assert 'customer-support-agent' in agents
119
-
120
+
120
121
agent = agents ['customer-support-agent' ]
121
122
assert agent .enabled is True
122
123
assert agent .model is not None
@@ -159,7 +160,7 @@ def test_agent_multi_context_interpolation(ldai_client: LDAIClient):
159
160
user_context = Context .builder ('user-key' ).name ('Bob' ).build ()
160
161
org_context = Context .builder ('org-key' ).kind ('org' ).name ('LaunchDarkly' ).set ('tier' , 'Enterprise' ).build ()
161
162
context = Context .multi_builder ().add (user_context ).add (org_context ).build ()
162
-
163
+
163
164
defaults = LDAIAgentDefaults (enabled = True , instructions = "Default" )
164
165
165
166
agents = ldai_client .agents (['multi-context-agent' ], context , defaults )
@@ -180,9 +181,9 @@ def test_multiple_agents_retrieval(ldai_client: LDAIClient):
180
181
variables = {'company_name' : 'MultiCorp' }
181
182
182
183
agents = ldai_client .agents (
183
- ['customer-support-agent' , 'sales-assistant' ],
184
- context ,
185
- defaults ,
184
+ ['customer-support-agent' , 'sales-assistant' ],
185
+ context ,
186
+ defaults ,
186
187
variables
187
188
)
188
189
@@ -192,12 +193,12 @@ def test_multiple_agents_retrieval(ldai_client: LDAIClient):
192
193
193
194
support_agent = agents ['customer-support-agent' ]
194
195
assert support_agent .enabled is True
195
- assert 'MultiCorp' in support_agent .instructions
196
+ assert support_agent . instructions is not None and 'MultiCorp' in support_agent .instructions
196
197
197
198
sales_agent = agents ['sales-assistant' ]
198
199
assert sales_agent .enabled is True
199
- assert 'MultiCorp' in sales_agent .instructions
200
- assert sales_agent .model .get_parameter ('temperature' ) == 0.7
200
+ assert sales_agent . instructions is not None and 'MultiCorp' in sales_agent .instructions
201
+ assert sales_agent .model is not None and sales_agent . model .get_parameter ('temperature' ) == 0.7
201
202
202
203
203
204
def test_disabled_agent (ldai_client : LDAIClient ):
@@ -244,9 +245,9 @@ def test_agent_uses_defaults_on_missing_flag(ldai_client: LDAIClient):
244
245
agent = agents ['non-existent-agent' ]
245
246
246
247
assert agent .enabled == defaults .enabled
247
- assert agent .model .name == 'default-gpt'
248
- assert agent .model .get_parameter ('temp' ) == 0.5
249
- assert agent .provider .name == 'default-provider'
248
+ assert agent .model is not None and agent . model .name == 'default-gpt'
249
+ assert agent .model is not None and agent . model .get_parameter ('temp' ) == 0.5
250
+ assert agent .provider is not None and agent . provider .name == 'default-provider'
250
251
assert agent .instructions == defaults .instructions
251
252
# Tracker should still be created for non-existent flags
252
253
assert agent .tracker is not None
@@ -263,13 +264,13 @@ def test_agent_error_handling(ldai_client: LDAIClient):
263
264
264
265
# Test with a mix of valid and invalid keys
265
266
agents = ldai_client .agents (
266
- ['customer-support-agent' , 'invalid-flag' ],
267
- context ,
267
+ ['customer-support-agent' , 'invalid-flag' ],
268
+ context ,
268
269
defaults
269
270
)
270
271
271
272
assert len (agents ) == 2
272
-
273
+
273
274
# Valid agent should work normally
274
275
valid_agent = agents ['customer-support-agent' ]
275
276
assert valid_agent .enabled is True
@@ -278,7 +279,7 @@ def test_agent_error_handling(ldai_client: LDAIClient):
278
279
# Invalid agent should use defaults but still be created
279
280
invalid_agent = agents ['invalid-flag' ]
280
281
assert invalid_agent .enabled == defaults .enabled
281
- assert invalid_agent .model .name == 'fallback-model'
282
+ assert invalid_agent .model is not None and invalid_agent . model .name == 'fallback-model'
282
283
assert invalid_agent .instructions == defaults .instructions
283
284
284
285
@@ -301,35 +302,15 @@ def test_agent_empty_agent_list(ldai_client: LDAIClient):
301
302
defaults = LDAIAgentDefaults (enabled = True , instructions = "Default" )
302
303
303
304
agents = ldai_client .agents ([], context , defaults )
304
-
305
+
305
306
assert len (agents ) == 0
306
307
assert agents == {}
307
308
308
309
309
- def test_agent_tracker_functionality (ldai_client : LDAIClient ):
310
- """Test that agent tracker works correctly."""
311
- context = Context .create ('user-key' )
312
- defaults = LDAIAgentDefaults (enabled = True , instructions = "Default" )
313
-
314
- agents = ldai_client .agents (['customer-support-agent' ], context , defaults )
315
- agent = agents ['customer-support-agent' ]
316
-
317
- assert agent .tracker is not None
318
- assert hasattr (agent .tracker , 'track_success' )
319
- assert hasattr (agent .tracker , 'track_duration' )
320
- assert hasattr (agent .tracker , 'track_tokens' )
321
-
322
- # Test that tracker has correct metadata
323
- track_data = agent .tracker ._LDAIConfigTracker__get_track_data ()
324
- assert track_data ['variationKey' ] == 'agent-v1'
325
- assert track_data ['configKey' ] == 'customer-support-agent'
326
- assert track_data ['version' ] == 1
327
-
328
-
329
310
def test_agents_backwards_compatibility_with_config (ldai_client : LDAIClient ):
330
311
"""Test that the existing config method still works after agent additions."""
331
312
from ldai .client import AIConfig , LDMessage
332
-
313
+
333
314
context = Context .create ('user-key' )
334
315
default_value = AIConfig (
335
316
enabled = True ,
@@ -339,7 +320,7 @@ def test_agents_backwards_compatibility_with_config(ldai_client: LDAIClient):
339
320
340
321
# This should still work as before
341
322
config , tracker = ldai_client .config ('customer-support-agent' , context , default_value )
342
-
323
+
343
324
assert config .enabled is True
344
325
assert config .model is not None
345
- assert tracker is not None
326
+ assert tracker is not None
0 commit comments