efficientai-sdk 0.1.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.
@@ -0,0 +1,682 @@
1
+ """Sync and async resources for simulations, suites, evaluators and results."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import time
6
+ from collections.abc import Mapping, Sequence
7
+ from typing import Any, Optional
8
+
9
+ from pydantic import PrivateAttr
10
+
11
+ from efficientai_sdk._base_client import AsyncAPIClient, SyncAPIClient
12
+ from efficientai_sdk._exceptions import APITimeoutError, ConfigurationError, EfficientAIError
13
+ from efficientai_sdk.simulations.models import (
14
+ TERMINAL_RESULT_STATUSES,
15
+ TERMINAL_RUN_STATUSES,
16
+ EvaluatorResult,
17
+ EvaluatorResultPage,
18
+ FailureAnalysis,
19
+ ResultBatchData,
20
+ SimulationRunData,
21
+ SimulationTrial,
22
+ )
23
+ from efficientai_sdk.simulations.polling import poll_async, poll_sync
24
+
25
+ RUNS_SUFFIX = "simulation-runs"
26
+ SUITES_SUFFIX = "evaluator-suites"
27
+ EVALUATORS_SUFFIX = "evaluators"
28
+ RESULTS_SUFFIX = "evaluator-results"
29
+
30
+
31
+ def _api_subpath(client: Any, suffix: str, *parts: object) -> str:
32
+ path = str(client.api_path(suffix))
33
+ for part in parts:
34
+ path = f"{path}/{part}"
35
+ return path
36
+
37
+
38
+ def _compact(data: Mapping[str, Any]) -> dict[str, Any]:
39
+ return {key: value for key, value in data.items() if value is not None}
40
+
41
+
42
+ def _ids(values: Sequence[object]) -> list[str]:
43
+ return [str(value) for value in values]
44
+
45
+
46
+ def _expect_dict(payload: Any, what: str) -> dict[str, Any]:
47
+ if isinstance(payload, dict):
48
+ return payload
49
+ raise EfficientAIError(f"Unexpected {what} response from the server.")
50
+
51
+
52
+ def _expect_list(payload: Any, what: str) -> list[Any]:
53
+ if isinstance(payload, list):
54
+ return payload
55
+ raise EfficientAIError(f"Unexpected {what} response from the server.")
56
+
57
+
58
+ class SimulationRun(SimulationRunData):
59
+ """One simulation run, bound to a sync client so :meth:`wait` can refresh it."""
60
+
61
+ _get: Any = PrivateAttr(default=None)
62
+
63
+ def wait(self, *, timeout: float = 1800, interval: float = 2.0) -> SimulationRun:
64
+ """Block until the run is completed, failed or cancelled.
65
+
66
+ Returns the latest run. A finished run that missed its threshold still
67
+ returns; check :attr:`passed`. Raises ``APITimeoutError`` on timeout.
68
+ """
69
+ if self._get is None:
70
+ raise ConfigurationError("This run is not bound to a client.")
71
+ return poll_sync(
72
+ self,
73
+ self._get,
74
+ lambda run: run.status in TERMINAL_RUN_STATUSES,
75
+ timeout=timeout,
76
+ interval=interval,
77
+ )
78
+
79
+
80
+ class AsyncSimulationRun(SimulationRunData):
81
+ """Async form of :class:`SimulationRun`."""
82
+
83
+ _get: Any = PrivateAttr(default=None)
84
+
85
+ async def wait(self, *, timeout: float = 1800, interval: float = 2.0) -> AsyncSimulationRun:
86
+ """Async form of :meth:`SimulationRun.wait`."""
87
+ if self._get is None:
88
+ raise ConfigurationError("This run is not bound to a client.")
89
+ return await poll_async(
90
+ self,
91
+ self._get,
92
+ lambda run: run.status in TERMINAL_RUN_STATUSES,
93
+ timeout=timeout,
94
+ interval=interval,
95
+ )
96
+
97
+
98
+ class ResultBatch(ResultBatchData):
99
+ """Suite or evaluator run handle for the sync client."""
100
+
101
+ _refresh: Any = PrivateAttr(default=None)
102
+
103
+ def wait(self, *, timeout: float = 1800, interval: float = 2.0) -> ResultBatch:
104
+ """Block until every evaluator result is completed or failed."""
105
+ if self._refresh is None:
106
+ raise ConfigurationError("This run is not bound to a client.")
107
+ return poll_sync(
108
+ self,
109
+ self._refresh,
110
+ _batch_done,
111
+ timeout=timeout,
112
+ interval=interval,
113
+ )
114
+
115
+
116
+ class AsyncResultBatch(ResultBatchData):
117
+ """Async form of :class:`ResultBatch`."""
118
+
119
+ _refresh: Any = PrivateAttr(default=None)
120
+
121
+ async def wait(self, *, timeout: float = 1800, interval: float = 2.0) -> AsyncResultBatch:
122
+ """Async form of :meth:`ResultBatch.wait`."""
123
+ if self._refresh is None:
124
+ raise ConfigurationError("This run is not bound to a client.")
125
+ return await poll_async(
126
+ self,
127
+ self._refresh,
128
+ _batch_done,
129
+ timeout=timeout,
130
+ interval=interval,
131
+ )
132
+
133
+
134
+ def _batch_done(batch: ResultBatchData) -> bool:
135
+ planned = batch._planned_run_count()
136
+ if planned and len(batch.results) < planned:
137
+ return False
138
+ if not batch.results:
139
+ return planned == 0
140
+ return all(result.status in TERMINAL_RESULT_STATUSES for result in batch.results)
141
+
142
+
143
+ def _bind_run(client: SyncAPIClient, payload: dict[str, Any]) -> SimulationRun:
144
+ run = SimulationRun.model_validate(payload)
145
+
146
+ def getter(budget: float) -> SimulationRun:
147
+ path = client.api_path(f"{RUNS_SUFFIX}/{run.id}")
148
+ body = _expect_dict(
149
+ client.request("GET", path, timeout=budget),
150
+ "simulation run",
151
+ )
152
+ return _bind_run(client, body)
153
+
154
+ run._get = getter
155
+ return run
156
+
157
+
158
+ def _bind_async_run(client: AsyncAPIClient, payload: dict[str, Any]) -> AsyncSimulationRun:
159
+ run = AsyncSimulationRun.model_validate(payload)
160
+
161
+ async def getter(budget: float) -> AsyncSimulationRun:
162
+ path = client.api_path(f"{RUNS_SUFFIX}/{run.id}")
163
+ body = _expect_dict(
164
+ await client.request("GET", path, timeout=budget),
165
+ "simulation run",
166
+ )
167
+ return _bind_async_run(client, body)
168
+
169
+ run._get = getter
170
+ return run
171
+
172
+
173
+ def _bind_batch(client: SyncAPIClient, payload: dict[str, Any]) -> ResultBatch:
174
+ batch = ResultBatch.model_validate(payload)
175
+ ids = [result.id for result in batch.results]
176
+
177
+ def refresh(budget: float) -> ResultBatch:
178
+ deadline = time.monotonic() + budget
179
+ results = []
180
+ for result_id in ids:
181
+ remaining = deadline - time.monotonic()
182
+ if remaining <= 0:
183
+ raise APITimeoutError("Timed out while refreshing suite results.")
184
+ path = _api_subpath(client, RESULTS_SUFFIX, result_id)
185
+ body = client.request("GET", path, timeout=remaining)
186
+ results.append(EvaluatorResult.model_validate(_expect_dict(body, "evaluator result")))
187
+ nxt = ResultBatch.model_validate(
188
+ {
189
+ "total_runs": batch.total_runs,
190
+ "task_ids": list(batch.task_ids),
191
+ "phone_call_refs": list(batch.phone_call_refs),
192
+ "results": [item.model_dump() for item in results],
193
+ }
194
+ )
195
+ nxt._refresh = refresh
196
+ return nxt
197
+
198
+ batch._refresh = refresh
199
+ return batch
200
+
201
+
202
+ def _bind_async_batch(client: AsyncAPIClient, payload: dict[str, Any]) -> AsyncResultBatch:
203
+ batch = AsyncResultBatch.model_validate(payload)
204
+ ids = [result.id for result in batch.results]
205
+
206
+ async def refresh(budget: float) -> AsyncResultBatch:
207
+ deadline = time.monotonic() + budget
208
+ results = []
209
+ for result_id in ids:
210
+ remaining = deadline - time.monotonic()
211
+ if remaining <= 0:
212
+ raise APITimeoutError("Timed out while refreshing suite results.")
213
+ path = _api_subpath(client, RESULTS_SUFFIX, result_id)
214
+ body = _expect_dict(
215
+ await client.request("GET", path, timeout=remaining),
216
+ "evaluator result",
217
+ )
218
+ results.append(EvaluatorResult.model_validate(body))
219
+ nxt = AsyncResultBatch.model_validate(
220
+ {
221
+ "total_runs": batch.total_runs,
222
+ "task_ids": list(batch.task_ids),
223
+ "phone_call_refs": list(batch.phone_call_refs),
224
+ "results": [item.model_dump() for item in results],
225
+ }
226
+ )
227
+ nxt._refresh = refresh
228
+ return nxt
229
+
230
+ batch._refresh = refresh
231
+ return batch
232
+
233
+
234
+ def _run_body(
235
+ *,
236
+ agent_id: object,
237
+ scenario_ids: Sequence[object],
238
+ persona_ids: Sequence[object],
239
+ n_attempts: int,
240
+ name: Optional[str],
241
+ metric_ids: Optional[Sequence[object]],
242
+ n_concurrent: Optional[int],
243
+ pass_threshold: Optional[float],
244
+ ) -> dict[str, Any]:
245
+ return _compact(
246
+ {
247
+ "agent_id": str(agent_id),
248
+ "scenario_ids": _ids(scenario_ids),
249
+ "persona_ids": _ids(persona_ids),
250
+ "n_attempts": n_attempts,
251
+ "name": name,
252
+ "metric_ids": _ids(metric_ids) if metric_ids is not None else None,
253
+ "n_concurrent": n_concurrent,
254
+ "pass_threshold": pass_threshold,
255
+ }
256
+ )
257
+
258
+
259
+ def _suite_body(
260
+ *,
261
+ runs_per_combination: Optional[int] = None,
262
+ to_number: Optional[str] = None,
263
+ from_number: Optional[str] = None,
264
+ ) -> dict[str, Any]:
265
+ return _compact(
266
+ {
267
+ "runs_per_combination": runs_per_combination,
268
+ "to_number": to_number,
269
+ "from_number": from_number,
270
+ }
271
+ )
272
+
273
+
274
+ def _analysis_body(
275
+ *,
276
+ provider: Optional[str],
277
+ model: Optional[str],
278
+ ) -> dict[str, Any]:
279
+ return _compact({"provider": provider, "model": model})
280
+
281
+
282
+ class SimulationsResource:
283
+ """``client.simulations``: create a run and read it back."""
284
+
285
+ def __init__(self, client: SyncAPIClient) -> None:
286
+ self._client = client
287
+
288
+ def run(
289
+ self,
290
+ *,
291
+ agent_id: object,
292
+ scenario_ids: Sequence[object],
293
+ persona_ids: Sequence[object],
294
+ n_attempts: int = 1,
295
+ name: Optional[str] = None,
296
+ metric_ids: Optional[Sequence[object]] = None,
297
+ n_concurrent: Optional[int] = None,
298
+ pass_threshold: Optional[float] = None,
299
+ ) -> SimulationRun:
300
+ """Start a simulation and return the queued run."""
301
+ payload = self._client.request(
302
+ "POST",
303
+ self._client.api_path(RUNS_SUFFIX),
304
+ json=_run_body(
305
+ agent_id=agent_id,
306
+ scenario_ids=scenario_ids,
307
+ persona_ids=persona_ids,
308
+ n_attempts=n_attempts,
309
+ name=name,
310
+ metric_ids=metric_ids,
311
+ n_concurrent=n_concurrent,
312
+ pass_threshold=pass_threshold,
313
+ ),
314
+ )
315
+ return _bind_run(self._client, _expect_dict(payload, "simulation run"))
316
+
317
+ def get(self, run_id: object) -> SimulationRun:
318
+ payload = self._client.request("GET", _api_subpath(self._client, RUNS_SUFFIX, run_id))
319
+ return _bind_run(self._client, _expect_dict(payload, "simulation run"))
320
+
321
+ def list(
322
+ self,
323
+ *,
324
+ agent_id: Optional[object] = None,
325
+ limit: Optional[int] = None,
326
+ ) -> list[SimulationRun]:
327
+ payload = self._client.request(
328
+ "GET",
329
+ self._client.api_path(RUNS_SUFFIX),
330
+ params=_compact({"agent_id": str(agent_id) if agent_id else None, "limit": limit}),
331
+ )
332
+ return [
333
+ _bind_run(self._client, item)
334
+ for item in _expect_list(payload, "simulation run list")
335
+ if isinstance(item, dict)
336
+ ]
337
+
338
+ def cancel(self, run_id: object) -> SimulationRun:
339
+ payload = self._client.request(
340
+ "POST", _api_subpath(self._client, RUNS_SUFFIX, run_id, "cancel")
341
+ )
342
+ return _bind_run(self._client, _expect_dict(payload, "simulation run"))
343
+
344
+ def rerun(self, run_id: object, *, only_failed: bool = False) -> SimulationRun:
345
+ payload = self._client.request(
346
+ "POST",
347
+ _api_subpath(self._client, RUNS_SUFFIX, run_id, "rerun"),
348
+ params={"only_failed": only_failed},
349
+ )
350
+ return _bind_run(self._client, _expect_dict(payload, "simulation run"))
351
+
352
+ def trials(self, run_id: object) -> Sequence[SimulationTrial]:
353
+ payload = self._client.request(
354
+ "GET", _api_subpath(self._client, RUNS_SUFFIX, run_id, "trials")
355
+ )
356
+ return [
357
+ SimulationTrial.model_validate(item)
358
+ for item in _expect_list(payload, "trial list")
359
+ if isinstance(item, dict)
360
+ ]
361
+
362
+ def trial(self, run_id: object, trial_id: object) -> SimulationTrial:
363
+ payload = self._client.request(
364
+ "GET", _api_subpath(self._client, RUNS_SUFFIX, run_id, "trials", trial_id)
365
+ )
366
+ return SimulationTrial.model_validate(_expect_dict(payload, "trial"))
367
+
368
+ def failure_analysis(
369
+ self,
370
+ run_id: object,
371
+ *,
372
+ generate: bool = False,
373
+ provider: Optional[str] = None,
374
+ model: Optional[str] = None,
375
+ ) -> FailureAnalysis:
376
+ """Return the cached analysis, or start a new one when ``generate`` is set."""
377
+ path = _api_subpath(self._client, RUNS_SUFFIX, run_id, "failure-analysis")
378
+ if generate:
379
+ payload = self._client.request(
380
+ "POST",
381
+ path,
382
+ json=_analysis_body(provider=provider, model=model),
383
+ )
384
+ else:
385
+ payload = self._client.request("GET", path)
386
+ return FailureAnalysis.model_validate(_expect_dict(payload, "failure analysis"))
387
+
388
+
389
+ class AsyncSimulationsResource:
390
+ """``await`` form of :class:`SimulationsResource`."""
391
+
392
+ def __init__(self, client: AsyncAPIClient) -> None:
393
+ self._client = client
394
+
395
+ async def run(
396
+ self,
397
+ *,
398
+ agent_id: object,
399
+ scenario_ids: Sequence[object],
400
+ persona_ids: Sequence[object],
401
+ n_attempts: int = 1,
402
+ name: Optional[str] = None,
403
+ metric_ids: Optional[Sequence[object]] = None,
404
+ n_concurrent: Optional[int] = None,
405
+ pass_threshold: Optional[float] = None,
406
+ ) -> AsyncSimulationRun:
407
+ payload = await self._client.request(
408
+ "POST",
409
+ self._client.api_path(RUNS_SUFFIX),
410
+ json=_run_body(
411
+ agent_id=agent_id,
412
+ scenario_ids=scenario_ids,
413
+ persona_ids=persona_ids,
414
+ n_attempts=n_attempts,
415
+ name=name,
416
+ metric_ids=metric_ids,
417
+ n_concurrent=n_concurrent,
418
+ pass_threshold=pass_threshold,
419
+ ),
420
+ )
421
+ return _bind_async_run(self._client, _expect_dict(payload, "simulation run"))
422
+
423
+ async def get(self, run_id: object) -> AsyncSimulationRun:
424
+ payload = await self._client.request("GET", _api_subpath(self._client, RUNS_SUFFIX, run_id))
425
+ return _bind_async_run(self._client, _expect_dict(payload, "simulation run"))
426
+
427
+ async def list(
428
+ self,
429
+ *,
430
+ agent_id: Optional[object] = None,
431
+ limit: Optional[int] = None,
432
+ ) -> list[AsyncSimulationRun]:
433
+ payload = await self._client.request(
434
+ "GET",
435
+ self._client.api_path(RUNS_SUFFIX),
436
+ params=_compact({"agent_id": str(agent_id) if agent_id else None, "limit": limit}),
437
+ )
438
+ return [
439
+ _bind_async_run(self._client, item)
440
+ for item in _expect_list(payload, "simulation run list")
441
+ if isinstance(item, dict)
442
+ ]
443
+
444
+ async def cancel(self, run_id: object) -> AsyncSimulationRun:
445
+ payload = await self._client.request(
446
+ "POST", _api_subpath(self._client, RUNS_SUFFIX, run_id, "cancel")
447
+ )
448
+ return _bind_async_run(self._client, _expect_dict(payload, "simulation run"))
449
+
450
+ async def rerun(self, run_id: object, *, only_failed: bool = False) -> AsyncSimulationRun:
451
+ payload = await self._client.request(
452
+ "POST",
453
+ _api_subpath(self._client, RUNS_SUFFIX, run_id, "rerun"),
454
+ params={"only_failed": only_failed},
455
+ )
456
+ return _bind_async_run(self._client, _expect_dict(payload, "simulation run"))
457
+
458
+ async def trials(self, run_id: object) -> Sequence[SimulationTrial]:
459
+ payload = await self._client.request(
460
+ "GET", _api_subpath(self._client, RUNS_SUFFIX, run_id, "trials")
461
+ )
462
+ return [
463
+ SimulationTrial.model_validate(item)
464
+ for item in _expect_list(payload, "trial list")
465
+ if isinstance(item, dict)
466
+ ]
467
+
468
+ async def trial(self, run_id: object, trial_id: object) -> SimulationTrial:
469
+ payload = await self._client.request(
470
+ "GET", _api_subpath(self._client, RUNS_SUFFIX, run_id, "trials", trial_id)
471
+ )
472
+ return SimulationTrial.model_validate(_expect_dict(payload, "trial"))
473
+
474
+ async def failure_analysis(
475
+ self,
476
+ run_id: object,
477
+ *,
478
+ generate: bool = False,
479
+ provider: Optional[str] = None,
480
+ model: Optional[str] = None,
481
+ ) -> FailureAnalysis:
482
+ path = _api_subpath(self._client, RUNS_SUFFIX, run_id, "failure-analysis")
483
+ if generate:
484
+ payload = await self._client.request(
485
+ "POST", path, json=_analysis_body(provider=provider, model=model)
486
+ )
487
+ else:
488
+ payload = await self._client.request("GET", path)
489
+ return FailureAnalysis.model_validate(_expect_dict(payload, "failure analysis"))
490
+
491
+
492
+ class SuitesResource:
493
+ """``client.suites``: run every combination in a suite."""
494
+
495
+ def __init__(self, client: SyncAPIClient) -> None:
496
+ self._client = client
497
+
498
+ def run(
499
+ self,
500
+ suite_id: object,
501
+ *,
502
+ runs_per_combination: Optional[int] = None,
503
+ to_number: Optional[str] = None,
504
+ from_number: Optional[str] = None,
505
+ ) -> ResultBatch:
506
+ payload = self._client.request(
507
+ "POST",
508
+ self._client.api_path(f"{SUITES_SUFFIX}/{suite_id}/run"),
509
+ json=_suite_body(
510
+ runs_per_combination=runs_per_combination,
511
+ to_number=to_number,
512
+ from_number=from_number,
513
+ ),
514
+ )
515
+ return _bind_batch(self._client, _expect_dict(payload, "suite run"))
516
+
517
+
518
+ class AsyncSuitesResource:
519
+ def __init__(self, client: AsyncAPIClient) -> None:
520
+ self._client = client
521
+
522
+ async def run(
523
+ self,
524
+ suite_id: object,
525
+ *,
526
+ runs_per_combination: Optional[int] = None,
527
+ to_number: Optional[str] = None,
528
+ from_number: Optional[str] = None,
529
+ ) -> AsyncResultBatch:
530
+ payload = await self._client.request(
531
+ "POST",
532
+ self._client.api_path(f"{SUITES_SUFFIX}/{suite_id}/run"),
533
+ json=_suite_body(
534
+ runs_per_combination=runs_per_combination,
535
+ to_number=to_number,
536
+ from_number=from_number,
537
+ ),
538
+ )
539
+ return _bind_async_batch(self._client, _expect_dict(payload, "suite run"))
540
+
541
+
542
+ class EvaluatorsResource:
543
+ """``client.evaluators``: run specific evaluators."""
544
+
545
+ def __init__(self, client: SyncAPIClient) -> None:
546
+ self._client = client
547
+
548
+ def run(self, evaluator_ids: Sequence[object]) -> ResultBatch:
549
+ payload = self._client.request(
550
+ "POST",
551
+ self._client.api_path(f"{EVALUATORS_SUFFIX}/run"),
552
+ json={"evaluator_ids": _ids(evaluator_ids)},
553
+ )
554
+ return _bind_batch(self._client, _expect_dict(payload, "evaluator run"))
555
+
556
+
557
+ class AsyncEvaluatorsResource:
558
+ def __init__(self, client: AsyncAPIClient) -> None:
559
+ self._client = client
560
+
561
+ async def run(self, evaluator_ids: Sequence[object]) -> AsyncResultBatch:
562
+ payload = await self._client.request(
563
+ "POST",
564
+ self._client.api_path(f"{EVALUATORS_SUFFIX}/run"),
565
+ json={"evaluator_ids": _ids(evaluator_ids)},
566
+ )
567
+ return _bind_async_batch(self._client, _expect_dict(payload, "evaluator run"))
568
+
569
+
570
+ class ResultsResource:
571
+ """``client.results``: read evaluator results."""
572
+
573
+ def __init__(self, client: SyncAPIClient) -> None:
574
+ self._client = client
575
+
576
+ def list(
577
+ self,
578
+ *,
579
+ agent_id: Optional[object] = None,
580
+ suite_id: Optional[object] = None,
581
+ evaluator_id: Optional[object] = None,
582
+ status: Optional[str] = None,
583
+ limit: Optional[int] = None,
584
+ skip: Optional[int] = None,
585
+ ) -> EvaluatorResultPage:
586
+ payload = self._client.request(
587
+ "GET",
588
+ self._client.api_path(RESULTS_SUFFIX),
589
+ params=_compact(
590
+ {
591
+ "agent_id": str(agent_id) if agent_id else None,
592
+ "suite_id": str(suite_id) if suite_id else None,
593
+ "evaluator_id": str(evaluator_id) if evaluator_id else None,
594
+ "status": status,
595
+ "limit": limit,
596
+ "skip": skip,
597
+ }
598
+ ),
599
+ )
600
+ return EvaluatorResultPage.model_validate(_expect_dict(payload, "evaluator result list"))
601
+
602
+ def get(self, result_id: object) -> EvaluatorResult:
603
+ payload = self._client.request("GET", _api_subpath(self._client, RESULTS_SUFFIX, result_id))
604
+ return EvaluatorResult.model_validate(_expect_dict(payload, "evaluator result"))
605
+
606
+ def metrics(self, result_id: object) -> dict[str, Any]:
607
+ payload = self._client.request(
608
+ "GET", _api_subpath(self._client, RESULTS_SUFFIX, result_id, "metrics")
609
+ )
610
+ return _expect_dict(payload, "evaluator result metrics")
611
+
612
+ def otel_correlation(self, result_id: object) -> dict[str, Any]:
613
+ payload = self._client.request(
614
+ "GET", _api_subpath(self._client, RESULTS_SUFFIX, result_id, "otel-correlation")
615
+ )
616
+ return _expect_dict(payload, "otel correlation")
617
+
618
+
619
+ class AsyncResultsResource:
620
+ def __init__(self, client: AsyncAPIClient) -> None:
621
+ self._client = client
622
+
623
+ async def list(
624
+ self,
625
+ *,
626
+ agent_id: Optional[object] = None,
627
+ suite_id: Optional[object] = None,
628
+ evaluator_id: Optional[object] = None,
629
+ status: Optional[str] = None,
630
+ limit: Optional[int] = None,
631
+ skip: Optional[int] = None,
632
+ ) -> EvaluatorResultPage:
633
+ payload = await self._client.request(
634
+ "GET",
635
+ self._client.api_path(RESULTS_SUFFIX),
636
+ params=_compact(
637
+ {
638
+ "agent_id": str(agent_id) if agent_id else None,
639
+ "suite_id": str(suite_id) if suite_id else None,
640
+ "evaluator_id": str(evaluator_id) if evaluator_id else None,
641
+ "status": status,
642
+ "limit": limit,
643
+ "skip": skip,
644
+ }
645
+ ),
646
+ )
647
+ return EvaluatorResultPage.model_validate(_expect_dict(payload, "evaluator result list"))
648
+
649
+ async def get(self, result_id: object) -> EvaluatorResult:
650
+ payload = await self._client.request(
651
+ "GET", _api_subpath(self._client, RESULTS_SUFFIX, result_id)
652
+ )
653
+ return EvaluatorResult.model_validate(_expect_dict(payload, "evaluator result"))
654
+
655
+ async def metrics(self, result_id: object) -> dict[str, Any]:
656
+ payload = await self._client.request(
657
+ "GET", _api_subpath(self._client, RESULTS_SUFFIX, result_id, "metrics")
658
+ )
659
+ return _expect_dict(payload, "evaluator result metrics")
660
+
661
+ async def otel_correlation(self, result_id: object) -> dict[str, Any]:
662
+ payload = await self._client.request(
663
+ "GET",
664
+ _api_subpath(self._client, RESULTS_SUFFIX, result_id, "otel-correlation"),
665
+ )
666
+ return _expect_dict(payload, "otel correlation")
667
+
668
+
669
+ __all__ = [
670
+ "AsyncEvaluatorsResource",
671
+ "AsyncResultBatch",
672
+ "AsyncResultsResource",
673
+ "AsyncSimulationRun",
674
+ "AsyncSimulationsResource",
675
+ "AsyncSuitesResource",
676
+ "EvaluatorsResource",
677
+ "ResultBatch",
678
+ "ResultsResource",
679
+ "SimulationRun",
680
+ "SimulationsResource",
681
+ "SuitesResource",
682
+ ]