lucidicai 2.1.2__py3-none-any.whl → 3.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. lucidicai/__init__.py +32 -390
  2. lucidicai/api/client.py +260 -92
  3. lucidicai/api/resources/__init__.py +16 -1
  4. lucidicai/api/resources/dataset.py +422 -82
  5. lucidicai/api/resources/event.py +399 -27
  6. lucidicai/api/resources/experiment.py +108 -0
  7. lucidicai/api/resources/feature_flag.py +78 -0
  8. lucidicai/api/resources/prompt.py +84 -0
  9. lucidicai/api/resources/session.py +545 -38
  10. lucidicai/client.py +395 -480
  11. lucidicai/core/config.py +73 -48
  12. lucidicai/core/errors.py +3 -3
  13. lucidicai/sdk/bound_decorators.py +321 -0
  14. lucidicai/sdk/context.py +20 -2
  15. lucidicai/sdk/decorators.py +283 -74
  16. lucidicai/sdk/event.py +538 -36
  17. lucidicai/sdk/event_builder.py +2 -4
  18. lucidicai/sdk/features/dataset.py +408 -232
  19. lucidicai/sdk/features/feature_flag.py +344 -3
  20. lucidicai/sdk/init.py +50 -279
  21. lucidicai/sdk/session.py +502 -0
  22. lucidicai/sdk/shutdown_manager.py +103 -46
  23. lucidicai/session_obj.py +321 -0
  24. lucidicai/telemetry/context_capture_processor.py +13 -6
  25. lucidicai/telemetry/extract.py +60 -63
  26. lucidicai/telemetry/litellm_bridge.py +3 -44
  27. lucidicai/telemetry/lucidic_exporter.py +143 -131
  28. lucidicai/telemetry/openai_agents_instrumentor.py +2 -2
  29. lucidicai/telemetry/openai_patch.py +7 -6
  30. lucidicai/telemetry/telemetry_manager.py +183 -0
  31. lucidicai/telemetry/utils/model_pricing.py +21 -30
  32. lucidicai/telemetry/utils/provider.py +77 -0
  33. lucidicai/utils/images.py +30 -14
  34. lucidicai/utils/queue.py +2 -2
  35. lucidicai/utils/serialization.py +27 -0
  36. {lucidicai-2.1.2.dist-info → lucidicai-3.0.0.dist-info}/METADATA +1 -1
  37. {lucidicai-2.1.2.dist-info → lucidicai-3.0.0.dist-info}/RECORD +39 -30
  38. {lucidicai-2.1.2.dist-info → lucidicai-3.0.0.dist-info}/WHEEL +0 -0
  39. {lucidicai-2.1.2.dist-info → lucidicai-3.0.0.dist-info}/top_level.txt +0 -0
@@ -1,9 +1,5 @@
1
- import os
2
1
  import logging
3
2
  from typing import Optional, Dict, List, Any
4
- from dotenv import load_dotenv
5
-
6
- from ...core.errors import APIKeyVerificationError
7
3
 
8
4
  logger = logging.getLogger("Lucidic")
9
5
 
@@ -36,37 +32,15 @@ def get_dataset(
36
32
  APIKeyVerificationError: If API key or agent ID is missing or invalid.
37
33
  ValueError: If dataset_id is not provided.
38
34
  """
39
- load_dotenv()
40
-
41
35
  # Validation
42
36
  if not dataset_id:
43
37
  raise ValueError("Dataset ID is required")
44
38
 
45
- # Get credentials
46
- if api_key is None:
47
- api_key = os.getenv("LUCIDIC_API_KEY", None)
48
- if api_key is None:
49
- raise APIKeyVerificationError(
50
- "Make sure to either pass your API key into get_dataset() or set the LUCIDIC_API_KEY environment variable."
51
- )
52
-
53
- if agent_id is None:
54
- agent_id = os.getenv("LUCIDIC_AGENT_ID", None)
55
- if agent_id is None:
56
- raise APIKeyVerificationError(
57
- "Lucidic agent ID not specified. Make sure to either pass your agent ID into get_dataset() or set the LUCIDIC_AGENT_ID environment variable."
58
- )
59
-
60
- # Get HTTP client
61
- from ..init import get_http
62
- from ...core.config import SDKConfig
63
- from ...api.client import HttpClient
39
+ from ..init import ensure_http_and_resources, get_http
64
40
 
41
+ # Ensure HTTP client is initialized and stored in SDK state
42
+ ensure_http_and_resources(api_key=api_key, agent_id=agent_id)
65
43
  http = get_http()
66
- if not http:
67
- # Create a new HTTP client if needed
68
- config = SDKConfig.from_env(api_key=api_key, agent_id=agent_id)
69
- http = HttpClient(config)
70
44
 
71
45
  # Make request to get dataset
72
46
  response = http.get('getdataset', {'dataset_id': dataset_id})
@@ -126,31 +100,9 @@ def list_datasets(
126
100
  Raises:
127
101
  APIKeyVerificationError: If API key or agent ID is missing or invalid.
128
102
  """
129
- from ..init import get_resources, get_http
130
- from ...core.config import SDKConfig
131
- from ...api.client import HttpClient
132
-
133
- # Get or create resources
134
- resources = get_resources()
135
- if not resources or 'datasets' not in resources:
136
- load_dotenv()
137
-
138
- # Get credentials
139
- if api_key is None:
140
- api_key = os.getenv("LUCIDIC_API_KEY", None)
141
- if api_key is None:
142
- raise APIKeyVerificationError(
143
- "Make sure to either pass your API key or set the LUCIDIC_API_KEY environment variable."
144
- )
145
-
146
- if agent_id is None:
147
- agent_id = os.getenv("LUCIDIC_AGENT_ID", None)
148
-
149
- config = SDKConfig.from_env(api_key=api_key, agent_id=agent_id)
150
- http = HttpClient(config)
151
- from ...api.resources.dataset import DatasetResource
152
- resources = {'datasets': DatasetResource(http)}
103
+ from ..init import ensure_http_and_resources
153
104
 
105
+ resources = ensure_http_and_resources(api_key=api_key, agent_id=agent_id)
154
106
  return resources['datasets'].list_datasets(agent_id)
155
107
 
156
108
 
@@ -179,30 +131,9 @@ def create_dataset(
179
131
  Raises:
180
132
  APIKeyVerificationError: If API key or agent ID is missing or invalid.
181
133
  """
182
- from ..init import get_resources, get_http
183
- from ...core.config import SDKConfig
184
- from ...api.client import HttpClient
185
-
186
- # Get or create resources
187
- resources = get_resources()
188
- if not resources or 'datasets' not in resources:
189
- load_dotenv()
190
-
191
- if api_key is None:
192
- api_key = os.getenv("LUCIDIC_API_KEY", None)
193
- if api_key is None:
194
- raise APIKeyVerificationError(
195
- "Make sure to either pass your API key or set the LUCIDIC_API_KEY environment variable."
196
- )
197
-
198
- if agent_id is None:
199
- agent_id = os.getenv("LUCIDIC_AGENT_ID", None)
200
-
201
- config = SDKConfig.from_env(api_key=api_key, agent_id=agent_id)
202
- http = HttpClient(config)
203
- from ...api.resources.dataset import DatasetResource
204
- resources = {'datasets': DatasetResource(http)}
134
+ from ..init import ensure_http_and_resources
205
135
 
136
+ resources = ensure_http_and_resources(api_key=api_key, agent_id=agent_id)
206
137
  return resources['datasets'].create_dataset(name, description, tags, suggested_flag_config, agent_id)
207
138
 
208
139
 
@@ -233,29 +164,9 @@ def update_dataset(
233
164
  Raises:
234
165
  APIKeyVerificationError: If API key or agent ID is missing or invalid.
235
166
  """
236
- from ..init import get_resources, get_http
237
- from ...core.config import SDKConfig
238
- from ...api.client import HttpClient
167
+ from ..init import ensure_http_and_resources
239
168
 
240
- # Get or create resources
241
- resources = get_resources()
242
- if not resources or 'datasets' not in resources:
243
- load_dotenv()
244
-
245
- if api_key is None:
246
- api_key = os.getenv("LUCIDIC_API_KEY", None)
247
- if api_key is None:
248
- raise APIKeyVerificationError(
249
- "Make sure to either pass your API key or set the LUCIDIC_API_KEY environment variable."
250
- )
251
-
252
- if agent_id is None:
253
- agent_id = os.getenv("LUCIDIC_AGENT_ID", None)
254
-
255
- config = SDKConfig.from_env(api_key=api_key, agent_id=agent_id)
256
- http = HttpClient(config)
257
- from ...api.resources.dataset import DatasetResource
258
- resources = {'datasets': DatasetResource(http)}
169
+ resources = ensure_http_and_resources(api_key=api_key, agent_id=agent_id)
259
170
 
260
171
  kwargs = {}
261
172
  if name is not None:
@@ -289,30 +200,9 @@ def delete_dataset(
289
200
  Raises:
290
201
  APIKeyVerificationError: If API key or agent ID is missing or invalid.
291
202
  """
292
- from ..init import get_resources, get_http
293
- from ...core.config import SDKConfig
294
- from ...api.client import HttpClient
295
-
296
- # Get or create resources
297
- resources = get_resources()
298
- if not resources or 'datasets' not in resources:
299
- load_dotenv()
300
-
301
- if api_key is None:
302
- api_key = os.getenv("LUCIDIC_API_KEY", None)
303
- if api_key is None:
304
- raise APIKeyVerificationError(
305
- "Make sure to either pass your API key or set the LUCIDIC_API_KEY environment variable."
306
- )
307
-
308
- if agent_id is None:
309
- agent_id = os.getenv("LUCIDIC_AGENT_ID", None)
310
-
311
- config = SDKConfig.from_env(api_key=api_key, agent_id=agent_id)
312
- http = HttpClient(config)
313
- from ...api.resources.dataset import DatasetResource
314
- resources = {'datasets': DatasetResource(http)}
203
+ from ..init import ensure_http_and_resources
315
204
 
205
+ resources = ensure_http_and_resources(api_key=api_key, agent_id=agent_id)
316
206
  return resources['datasets'].delete_dataset(dataset_id)
317
207
 
318
208
 
@@ -349,30 +239,9 @@ def create_dataset_item(
349
239
  Raises:
350
240
  APIKeyVerificationError: If API key or agent ID is missing or invalid.
351
241
  """
352
- from ..init import get_resources, get_http
353
- from ...core.config import SDKConfig
354
- from ...api.client import HttpClient
355
-
356
- # Get or create resources
357
- resources = get_resources()
358
- if not resources or 'datasets' not in resources:
359
- load_dotenv()
360
-
361
- if api_key is None:
362
- api_key = os.getenv("LUCIDIC_API_KEY", None)
363
- if api_key is None:
364
- raise APIKeyVerificationError(
365
- "Make sure to either pass your API key or set the LUCIDIC_API_KEY environment variable."
366
- )
367
-
368
- if agent_id is None:
369
- agent_id = os.getenv("LUCIDIC_AGENT_ID", None)
370
-
371
- config = SDKConfig.from_env(api_key=api_key, agent_id=agent_id)
372
- http = HttpClient(config)
373
- from ...api.resources.dataset import DatasetResource
374
- resources = {'datasets': DatasetResource(http)}
242
+ from ..init import ensure_http_and_resources
375
243
 
244
+ resources = ensure_http_and_resources(api_key=api_key, agent_id=agent_id)
376
245
  return resources['datasets'].create_item(
377
246
  dataset_id, name, input_data,
378
247
  expected_output=expected_output,
@@ -404,30 +273,9 @@ def get_dataset_item(
404
273
  Raises:
405
274
  APIKeyVerificationError: If API key or agent ID is missing or invalid.
406
275
  """
407
- from ..init import get_resources, get_http
408
- from ...core.config import SDKConfig
409
- from ...api.client import HttpClient
410
-
411
- # Get or create resources
412
- resources = get_resources()
413
- if not resources or 'datasets' not in resources:
414
- load_dotenv()
415
-
416
- if api_key is None:
417
- api_key = os.getenv("LUCIDIC_API_KEY", None)
418
- if api_key is None:
419
- raise APIKeyVerificationError(
420
- "Make sure to either pass your API key or set the LUCIDIC_API_KEY environment variable."
421
- )
422
-
423
- if agent_id is None:
424
- agent_id = os.getenv("LUCIDIC_AGENT_ID", None)
425
-
426
- config = SDKConfig.from_env(api_key=api_key, agent_id=agent_id)
427
- http = HttpClient(config)
428
- from ...api.resources.dataset import DatasetResource
429
- resources = {'datasets': DatasetResource(http)}
276
+ from ..init import ensure_http_and_resources
430
277
 
278
+ resources = ensure_http_and_resources(api_key=api_key, agent_id=agent_id)
431
279
  return resources['datasets'].get_item(dataset_id, item_id)
432
280
 
433
281
 
@@ -466,29 +314,9 @@ def update_dataset_item(
466
314
  Raises:
467
315
  APIKeyVerificationError: If API key or agent ID is missing or invalid.
468
316
  """
469
- from ..init import get_resources, get_http
470
- from ...core.config import SDKConfig
471
- from ...api.client import HttpClient
472
-
473
- # Get or create resources
474
- resources = get_resources()
475
- if not resources or 'datasets' not in resources:
476
- load_dotenv()
477
-
478
- if api_key is None:
479
- api_key = os.getenv("LUCIDIC_API_KEY", None)
480
- if api_key is None:
481
- raise APIKeyVerificationError(
482
- "Make sure to either pass your API key or set the LUCIDIC_API_KEY environment variable."
483
- )
317
+ from ..init import ensure_http_and_resources
484
318
 
485
- if agent_id is None:
486
- agent_id = os.getenv("LUCIDIC_AGENT_ID", None)
487
-
488
- config = SDKConfig.from_env(api_key=api_key, agent_id=agent_id)
489
- http = HttpClient(config)
490
- from ...api.resources.dataset import DatasetResource
491
- resources = {'datasets': DatasetResource(http)}
319
+ resources = ensure_http_and_resources(api_key=api_key, agent_id=agent_id)
492
320
 
493
321
  kwargs = {}
494
322
  if name is not None:
@@ -530,30 +358,9 @@ def delete_dataset_item(
530
358
  Raises:
531
359
  APIKeyVerificationError: If API key or agent ID is missing or invalid.
532
360
  """
533
- from ..init import get_resources, get_http
534
- from ...core.config import SDKConfig
535
- from ...api.client import HttpClient
536
-
537
- # Get or create resources
538
- resources = get_resources()
539
- if not resources or 'datasets' not in resources:
540
- load_dotenv()
541
-
542
- if api_key is None:
543
- api_key = os.getenv("LUCIDIC_API_KEY", None)
544
- if api_key is None:
545
- raise APIKeyVerificationError(
546
- "Make sure to either pass your API key or set the LUCIDIC_API_KEY environment variable."
547
- )
548
-
549
- if agent_id is None:
550
- agent_id = os.getenv("LUCIDIC_AGENT_ID", None)
551
-
552
- config = SDKConfig.from_env(api_key=api_key, agent_id=agent_id)
553
- http = HttpClient(config)
554
- from ...api.resources.dataset import DatasetResource
555
- resources = {'datasets': DatasetResource(http)}
361
+ from ..init import ensure_http_and_resources
556
362
 
363
+ resources = ensure_http_and_resources(api_key=api_key, agent_id=agent_id)
557
364
  return resources['datasets'].delete_item(dataset_id, item_id)
558
365
 
559
366
 
@@ -578,28 +385,397 @@ def list_dataset_item_sessions(
578
385
  Raises:
579
386
  APIKeyVerificationError: If API key or agent ID is missing or invalid.
580
387
  """
581
- from ..init import get_resources, get_http
582
- from ...core.config import SDKConfig
583
- from ...api.client import HttpClient
388
+ from ..init import ensure_http_and_resources
389
+
390
+ resources = ensure_http_and_resources(api_key=api_key, agent_id=agent_id)
391
+ return resources['datasets'].list_item_sessions(dataset_id, item_id)
392
+
393
+
394
+ # ==================== Asynchronous Functions ====================
395
+
396
+
397
+ async def aget_dataset(
398
+ dataset_id: str,
399
+ api_key: Optional[str] = None,
400
+ agent_id: Optional[str] = None,
401
+ ) -> Dict[str, Any]:
402
+ """
403
+ Get a dataset by ID with all its items (asynchronous).
404
+
405
+ Args:
406
+ dataset_id: The ID of the dataset to retrieve (required).
407
+ api_key: API key for authentication. If not provided, will use the LUCIDIC_API_KEY environment variable.
408
+ agent_id: Agent ID. If not provided, will use the LUCIDIC_AGENT_ID environment variable.
409
+
410
+ Returns:
411
+ A dictionary containing the dataset information including:
412
+ - dataset_id: The dataset ID
413
+ - name: Dataset name
414
+ - description: Dataset description
415
+ - tags: List of tags
416
+ - created_at: Creation timestamp
417
+ - updated_at: Last update timestamp
418
+ - num_items: Number of items in the dataset
419
+ - items: List of dataset items
420
+
421
+ Raises:
422
+ APIKeyVerificationError: If API key or agent ID is missing or invalid.
423
+ ValueError: If dataset_id is not provided.
424
+ """
425
+ # Validation
426
+ if not dataset_id:
427
+ raise ValueError("Dataset ID is required")
428
+
429
+ from ..init import aensure_http_and_resources, get_http
430
+
431
+ # Ensure HTTP client is initialized and stored in SDK state
432
+ await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
433
+ http = get_http()
434
+
435
+ # Make request to get dataset
436
+ response = await http.aget('getdataset', {'dataset_id': dataset_id})
437
+
438
+ logger.info(f"Retrieved dataset {dataset_id} with {response.get('num_items', 0)} items")
439
+ return response
584
440
 
585
- # Get or create resources
586
- resources = get_resources()
587
- if not resources or 'datasets' not in resources:
588
- load_dotenv()
589
441
 
590
- if api_key is None:
591
- api_key = os.getenv("LUCIDIC_API_KEY", None)
592
- if api_key is None:
593
- raise APIKeyVerificationError(
594
- "Make sure to either pass your API key or set the LUCIDIC_API_KEY environment variable."
595
- )
442
+ async def aget_dataset_items(
443
+ dataset_id: str,
444
+ api_key: Optional[str] = None,
445
+ agent_id: Optional[str] = None,
446
+ ) -> List[Dict[str, Any]]:
447
+ """
448
+ Convenience function to get just the items from a dataset (asynchronous).
596
449
 
597
- if agent_id is None:
598
- agent_id = os.getenv("LUCIDIC_AGENT_ID", None)
450
+ Args:
451
+ dataset_id: The ID of the dataset to retrieve items from (required).
452
+ api_key: API key for authentication. If not provided, will use the LUCIDIC_API_KEY environment variable.
453
+ agent_id: Agent ID. If not provided, will use the LUCIDIC_AGENT_ID environment variable.
599
454
 
600
- config = SDKConfig.from_env(api_key=api_key, agent_id=agent_id)
601
- http = HttpClient(config)
602
- from ...api.resources.dataset import DatasetResource
603
- resources = {'datasets': DatasetResource(http)}
455
+ Returns:
456
+ A list of dataset items, where each item contains:
457
+ - datasetitem_id: The item ID
458
+ - name: Item name
459
+ - description: Item description
460
+ - tags: List of tags
461
+ - input: Input data for the item
462
+ - expected_output: Expected output data
463
+ - metadata: Additional metadata
464
+ - created_at: Creation timestamp
465
+
466
+ Raises:
467
+ APIKeyVerificationError: If API key or agent ID is missing or invalid.
468
+ ValueError: If dataset_id is not provided.
469
+ """
470
+ dataset = await aget_dataset(dataset_id, api_key, agent_id)
471
+ return dataset.get('items', [])
472
+
473
+
474
+ async def alist_datasets(
475
+ api_key: Optional[str] = None,
476
+ agent_id: Optional[str] = None,
477
+ ) -> Dict[str, Any]:
478
+ """
479
+ List all datasets for the agent (asynchronous).
480
+
481
+ Args:
482
+ api_key: API key for authentication. If not provided, will use the LUCIDIC_API_KEY environment variable.
483
+ agent_id: Agent ID. If not provided, will use the LUCIDIC_AGENT_ID environment variable.
484
+
485
+ Returns:
486
+ A dictionary containing:
487
+ - num_datasets: Number of datasets
488
+ - datasets: List of dataset summaries with dataset_id and name
489
+
490
+ Raises:
491
+ APIKeyVerificationError: If API key or agent ID is missing or invalid.
492
+ """
493
+ from ..init import aensure_http_and_resources
494
+
495
+ resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
496
+ return await resources['datasets'].alist_datasets(agent_id)
497
+
498
+
499
+ async def acreate_dataset(
500
+ name: str,
501
+ description: Optional[str] = None,
502
+ tags: Optional[List[str]] = None,
503
+ suggested_flag_config: Optional[Dict[str, Any]] = None,
504
+ api_key: Optional[str] = None,
505
+ agent_id: Optional[str] = None,
506
+ ) -> Dict[str, Any]:
507
+ """
508
+ Create a new dataset (asynchronous).
509
+
510
+ Args:
511
+ name: Dataset name (must be unique per agent)
512
+ description: Optional dataset description
513
+ tags: Optional list of tags
514
+ suggested_flag_config: Optional flag configuration
515
+ api_key: API key for authentication
516
+ agent_id: Agent ID
517
+
518
+ Returns:
519
+ A dictionary containing dataset_id
520
+
521
+ Raises:
522
+ APIKeyVerificationError: If API key or agent ID is missing or invalid.
523
+ """
524
+ from ..init import aensure_http_and_resources
525
+
526
+ resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
527
+ return await resources['datasets'].acreate_dataset(name, description, tags, suggested_flag_config, agent_id)
528
+
529
+
530
+ async def aupdate_dataset(
531
+ dataset_id: str,
532
+ name: Optional[str] = None,
533
+ description: Optional[str] = None,
534
+ tags: Optional[List[str]] = None,
535
+ suggested_flag_config: Optional[Dict[str, Any]] = None,
536
+ api_key: Optional[str] = None,
537
+ agent_id: Optional[str] = None,
538
+ ) -> Dict[str, Any]:
539
+ """
540
+ Update dataset metadata (asynchronous).
541
+
542
+ Args:
543
+ dataset_id: Dataset UUID to update
544
+ name: New name (optional)
545
+ description: New description (optional)
546
+ tags: New tags (optional)
547
+ suggested_flag_config: New flag config (optional)
548
+ api_key: API key for authentication
549
+ agent_id: Agent ID
550
+
551
+ Returns:
552
+ Updated dataset data
553
+
554
+ Raises:
555
+ APIKeyVerificationError: If API key or agent ID is missing or invalid.
556
+ """
557
+ from ..init import aensure_http_and_resources
558
+
559
+ resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
560
+
561
+ kwargs = {}
562
+ if name is not None:
563
+ kwargs['name'] = name
564
+ if description is not None:
565
+ kwargs['description'] = description
566
+ if tags is not None:
567
+ kwargs['tags'] = tags
568
+ if suggested_flag_config is not None:
569
+ kwargs['suggested_flag_config'] = suggested_flag_config
570
+
571
+ return await resources['datasets'].aupdate_dataset(dataset_id, **kwargs)
572
+
573
+
574
+ async def adelete_dataset(
575
+ dataset_id: str,
576
+ api_key: Optional[str] = None,
577
+ agent_id: Optional[str] = None,
578
+ ) -> Dict[str, Any]:
579
+ """
580
+ Delete a dataset and all its items (asynchronous).
581
+
582
+ Args:
583
+ dataset_id: Dataset UUID to delete
584
+ api_key: API key for authentication
585
+ agent_id: Agent ID
586
+
587
+ Returns:
588
+ Success message
589
+
590
+ Raises:
591
+ APIKeyVerificationError: If API key or agent ID is missing or invalid.
592
+ """
593
+ from ..init import aensure_http_and_resources
594
+
595
+ resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
596
+ return await resources['datasets'].adelete_dataset(dataset_id)
597
+
598
+
599
+ async def acreate_dataset_item(
600
+ dataset_id: str,
601
+ name: str,
602
+ input_data: Dict[str, Any],
603
+ expected_output: Optional[Dict[str, Any]] = None,
604
+ description: Optional[str] = None,
605
+ tags: Optional[List[str]] = None,
606
+ metadata: Optional[Dict[str, Any]] = None,
607
+ flag_overrides: Optional[Dict[str, Any]] = None,
608
+ api_key: Optional[str] = None,
609
+ agent_id: Optional[str] = None,
610
+ ) -> Dict[str, Any]:
611
+ """
612
+ Create a new dataset item (asynchronous).
613
+
614
+ Args:
615
+ dataset_id: Dataset UUID to add item to
616
+ name: Item name
617
+ input_data: Input data dictionary
618
+ expected_output: Expected output (optional)
619
+ description: Item description (optional)
620
+ tags: Item tags (optional)
621
+ metadata: Additional metadata (optional)
622
+ flag_overrides: Flag overrides (optional)
623
+ api_key: API key for authentication
624
+ agent_id: Agent ID
625
+
626
+ Returns:
627
+ Dictionary with datasetitem_id
628
+
629
+ Raises:
630
+ APIKeyVerificationError: If API key or agent ID is missing or invalid.
631
+ """
632
+ from ..init import aensure_http_and_resources
633
+
634
+ resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
635
+ return await resources['datasets'].acreate_item(
636
+ dataset_id, name, input_data,
637
+ expected_output=expected_output,
638
+ description=description,
639
+ tags=tags,
640
+ metadata=metadata,
641
+ flag_overrides=flag_overrides
642
+ )
643
+
644
+
645
+ async def aget_dataset_item(
646
+ dataset_id: str,
647
+ item_id: str,
648
+ api_key: Optional[str] = None,
649
+ agent_id: Optional[str] = None,
650
+ ) -> Dict[str, Any]:
651
+ """
652
+ Get a specific dataset item (asynchronous).
653
+
654
+ Args:
655
+ dataset_id: Dataset UUID
656
+ item_id: Item UUID
657
+ api_key: API key for authentication
658
+ agent_id: Agent ID
659
+
660
+ Returns:
661
+ Dataset item data
662
+
663
+ Raises:
664
+ APIKeyVerificationError: If API key or agent ID is missing or invalid.
665
+ """
666
+ from ..init import aensure_http_and_resources
667
+
668
+ resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
669
+ return await resources['datasets'].aget_item(dataset_id, item_id)
670
+
671
+
672
+ async def aupdate_dataset_item(
673
+ dataset_id: str,
674
+ item_id: str,
675
+ name: Optional[str] = None,
676
+ input_data: Optional[Dict[str, Any]] = None,
677
+ expected_output: Optional[Dict[str, Any]] = None,
678
+ description: Optional[str] = None,
679
+ tags: Optional[List[str]] = None,
680
+ metadata: Optional[Dict[str, Any]] = None,
681
+ flag_overrides: Optional[Dict[str, Any]] = None,
682
+ api_key: Optional[str] = None,
683
+ agent_id: Optional[str] = None,
684
+ ) -> Dict[str, Any]:
685
+ """
686
+ Update a dataset item (asynchronous).
687
+
688
+ Args:
689
+ dataset_id: Dataset UUID
690
+ item_id: Item UUID
691
+ name: New name (optional)
692
+ input_data: New input data (optional)
693
+ expected_output: New expected output (optional)
694
+ description: New description (optional)
695
+ tags: New tags (optional)
696
+ metadata: New metadata (optional)
697
+ flag_overrides: New flag overrides (optional)
698
+ api_key: API key for authentication
699
+ agent_id: Agent ID
700
+
701
+ Returns:
702
+ Updated item data
703
+
704
+ Raises:
705
+ APIKeyVerificationError: If API key or agent ID is missing or invalid.
706
+ """
707
+ from ..init import aensure_http_and_resources
708
+
709
+ resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
710
+
711
+ kwargs = {}
712
+ if name is not None:
713
+ kwargs['name'] = name
714
+ if input_data is not None:
715
+ kwargs['input'] = input_data
716
+ if expected_output is not None:
717
+ kwargs['expected_output'] = expected_output
718
+ if description is not None:
719
+ kwargs['description'] = description
720
+ if tags is not None:
721
+ kwargs['tags'] = tags
722
+ if metadata is not None:
723
+ kwargs['metadata'] = metadata
724
+ if flag_overrides is not None:
725
+ kwargs['flag_overrides'] = flag_overrides
726
+
727
+ return await resources['datasets'].aupdate_item(dataset_id, item_id, **kwargs)
728
+
729
+
730
+ async def adelete_dataset_item(
731
+ dataset_id: str,
732
+ item_id: str,
733
+ api_key: Optional[str] = None,
734
+ agent_id: Optional[str] = None,
735
+ ) -> Dict[str, Any]:
736
+ """
737
+ Delete a dataset item (asynchronous).
738
+
739
+ Args:
740
+ dataset_id: Dataset UUID
741
+ item_id: Item UUID
742
+ api_key: API key for authentication
743
+ agent_id: Agent ID
744
+
745
+ Returns:
746
+ Success message
747
+
748
+ Raises:
749
+ APIKeyVerificationError: If API key or agent ID is missing or invalid.
750
+ """
751
+ from ..init import aensure_http_and_resources
752
+
753
+ resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
754
+ return await resources['datasets'].adelete_item(dataset_id, item_id)
755
+
756
+
757
+ async def alist_dataset_item_sessions(
758
+ dataset_id: str,
759
+ item_id: str,
760
+ api_key: Optional[str] = None,
761
+ agent_id: Optional[str] = None,
762
+ ) -> Dict[str, Any]:
763
+ """
764
+ List all sessions for a dataset item (asynchronous).
765
+
766
+ Args:
767
+ dataset_id: Dataset UUID
768
+ item_id: Item UUID
769
+ api_key: API key for authentication
770
+ agent_id: Agent ID
771
+
772
+ Returns:
773
+ Dictionary with num_sessions and sessions list
774
+
775
+ Raises:
776
+ APIKeyVerificationError: If API key or agent ID is missing or invalid.
777
+ """
778
+ from ..init import aensure_http_and_resources
604
779
 
605
- return resources['datasets'].list_item_sessions(dataset_id, item_id)
780
+ resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
781
+ return await resources['datasets'].alist_item_sessions(dataset_id, item_id)