aid-runtime-python 0.1.165__py3-none-any.whl → 0.1.167__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.
aid_runtime/__init__.py CHANGED
@@ -199,6 +199,7 @@ from aid_runtime.providers import (
199
199
  Provider,
200
200
  RecordedProvider,
201
201
  RecordingProvider,
202
+ RecordingProviders,
202
203
  ReplayDivergenceError,
203
204
  ScriptedTurn,
204
205
  Transcript,
@@ -356,7 +357,7 @@ from aid_runtime.types import (
356
357
  )
357
358
 
358
359
  #: Kept in sync with ``pyproject.toml`` by a test, so the two cannot drift.
359
- __version__ = "0.1.165"
360
+ __version__ = "0.1.167"
360
361
 
361
362
  __all__ = [
362
363
  "AGENT_LABEL",
@@ -526,6 +527,7 @@ __all__ = [
526
527
  "RecallAtK",
527
528
  "RecordedProvider",
528
529
  "RecordingProvider",
530
+ "RecordingProviders",
529
531
  "RecursiveChunker",
530
532
  "RefreshMode",
531
533
  "RefreshSpec",
@@ -35,6 +35,7 @@ from aid_runtime.providers.http import DEFAULT_BASE_URL, OpenAICompatibleProvide
35
35
  from aid_runtime.providers.recorded import (
36
36
  RecordedProvider,
37
37
  RecordingProvider,
38
+ RecordingProviders,
38
39
  ReplayDivergenceError,
39
40
  Transcript,
40
41
  TranscriptEntry,
@@ -65,6 +66,7 @@ __all__ = [
65
66
  "Provider",
66
67
  "RecordedProvider",
67
68
  "RecordingProvider",
69
+ "RecordingProviders",
68
70
  "ReplayDivergenceError",
69
71
  "ScriptedTurn",
70
72
  "Transcript",
@@ -18,13 +18,21 @@ the request it is handed. A prompt edit, a changed tool result or a reordered st
18
18
  that digest, and the run stops with the call index and the first differing message instead
19
19
  of quietly serving an answer to a question nobody asked. The alternative -- matching on
20
20
  content -- would turn a diverged run into a permissive one.
21
+
22
+ Recording is the other half, and it is never automatic: a suite that recorded itself would
23
+ gate the build on whatever the model did on the day it ran, so capture happens only when a
24
+ run is asked to capture. :class:`RecordingProvider` wraps one live provider;
25
+ :class:`RecordingProviders` wraps the whole provider mapping, because the gateway picks a
26
+ provider per model and a run that fell back between vendors would otherwise leave the
27
+ fallback out of the file. Either way what is written is a :class:`Transcript` -- the same
28
+ shape replay reads, so there is one format and one digest, not two.
21
29
  """
22
30
 
23
31
  from __future__ import annotations
24
32
 
25
33
  import hashlib
26
34
  import json
27
- from collections.abc import AsyncIterator, Sequence
35
+ from collections.abc import AsyncIterator, Mapping, Sequence
28
36
  from pathlib import Path
29
37
  from typing import Any
30
38
 
@@ -46,6 +54,7 @@ from aid_runtime.types import (
46
54
  __all__ = [
47
55
  "RecordedProvider",
48
56
  "RecordingProvider",
57
+ "RecordingProviders",
49
58
  "ReplayDivergenceError",
50
59
  "Transcript",
51
60
  "TranscriptEntry",
@@ -107,6 +116,8 @@ class Transcript(BaseModel):
107
116
  model_config = ConfigDict(frozen=True, extra="forbid")
108
117
 
109
118
  provider: str
119
+ #: One vendor, or several comma-joined when the capture spanned a fallback. `model`
120
+ #: follows the same rule, because one run can answer under more than one model.
110
121
  model: str
111
122
  #: The spec version the recording was made under. A transcript is evidence about a
112
123
  #: particular document, so a bump that changes what an eval runs should prompt a
@@ -256,19 +267,65 @@ class RecordedProvider:
256
267
  )
257
268
 
258
269
 
270
+ class _Recorder:
271
+ """The calls the wrapped providers answered, kept as one transcript.
272
+
273
+ Shared by every provider a :class:`RecordingProviders` wraps. The two names it collects
274
+ are comma-joined rather than last-wins, because a capture that spanned a fallback would
275
+ otherwise describe itself as the one vendor it happened to call last.
276
+ """
277
+
278
+ def __init__(self, spec_version: str) -> None:
279
+ self.spec_version = spec_version
280
+ self.entries: list[TranscriptEntry] = []
281
+ self._providers: list[str] = []
282
+ self._models: list[str] = []
283
+
284
+ def note(self, *, provider: str, model: str) -> None:
285
+ if provider and provider not in self._providers:
286
+ self._providers.append(provider)
287
+ if model and model not in self._models:
288
+ self._models.append(model)
289
+
290
+ def append(self, entry: TranscriptEntry, *, provider: str, model: str) -> None:
291
+ self.note(provider=provider, model=model)
292
+ self.entries.append(entry)
293
+
294
+ def transcript(self) -> Transcript:
295
+ return Transcript(
296
+ provider=",".join(self._providers),
297
+ model=",".join(self._models),
298
+ spec_version=self.spec_version,
299
+ entries=tuple(self.entries),
300
+ )
301
+
302
+
259
303
  class RecordingProvider:
260
304
  """Wraps a live provider and keeps every exchange, so a run can be replayed offline.
261
305
 
262
306
  Recording is opt-in and explicit. Nothing here is enabled by an eval run that merely
263
307
  happens to have a network connection: a suite that recorded itself would gate the
264
308
  build on whatever the model did on the day it ran.
309
+
310
+ `recorder` shares the capture with the other providers of the same run, which is what
311
+ :class:`RecordingProviders` uses; given one, `spec_version` is the recorder's.
265
312
  """
266
313
 
267
- def __init__(self, inner: Provider, *, spec_version: str = "") -> None:
314
+ def __init__(
315
+ self,
316
+ inner: Provider,
317
+ *,
318
+ spec_version: str = "",
319
+ recorder: _Recorder | None = None,
320
+ ) -> None:
268
321
  self._inner = inner
269
- self._spec_version = spec_version
270
- self._entries: list[TranscriptEntry] = []
271
- self._model = ""
322
+ if recorder is None:
323
+ self._recorder = _Recorder(spec_version)
324
+ # Named here rather than only on the first call, so an empty recorder still
325
+ # says what it was going to record.
326
+ self._recorder.note(provider=str(inner.name), model="")
327
+ else:
328
+ self._recorder = recorder
272
329
 
273
330
  @property
274
331
  def name(self) -> str:
@@ -280,27 +337,28 @@ class RecordingProvider:
280
337
 
281
338
  @property
282
339
  def entries(self) -> tuple[TranscriptEntry, ...]:
283
- return tuple(self._entries)
340
+ return tuple(self._recorder.entries)
284
341
 
285
342
  def transcript(self) -> Transcript:
286
- return Transcript(
287
- provider=self.name,
288
- model=self._model,
289
- spec_version=self._spec_version,
290
- entries=tuple(self._entries),
291
- )
343
+ return self._recorder.transcript()
292
344
 
293
- async def complete(self, request: CompletionRequest, *, model: ModelSpec) -> CompletionResponse:
294
- response = await self._inner.complete(request, model=model)
295
- self._model = model.name
345
+ def _record(
346
+ self, request: CompletionRequest, response: CompletionResponse, *, model: ModelSpec
347
+ ) -> None:
296
348
  user = next((message.content for message in request.messages if message.role == "user"), "")
297
- self._entries.append(
349
+ self._recorder.append(
298
350
  TranscriptEntry(
299
351
  request_digest=_digest(request.messages),
300
352
  response=response,
301
353
  prompt_preview=user[:200],
302
- )
354
+ ),
355
+ provider=self.name,
356
+ model=model.name,
303
357
  )
358
+
359
+ async def complete(self, request: CompletionRequest, *, model: ModelSpec) -> CompletionResponse:
360
+ response = await self._inner.complete(request, model=model)
361
+ self._record(request, response, model=model)
304
362
  return response
305
363
 
306
364
  async def stream(
@@ -318,25 +376,49 @@ class RecordingProvider:
318
376
  (chunk.finish_reason for chunk in reversed(chunks) if chunk.finish_reason is not None),
319
377
  "stop",
320
378
  )
321
- self._model = model.name
322
- user = next((message.content for message in request.messages if message.role == "user"), "")
323
- self._entries.append(
324
- TranscriptEntry(
325
- request_digest=_digest(request.messages),
326
- response=CompletionResponse(
327
- text=text,
328
- model=model.name,
329
- provider=self.name,
330
- usage=usage
331
- if usage is not None
332
- else TokenUsage(input_tokens=0, output_tokens=0),
333
- finish_reason=finish,
334
- ),
335
- prompt_preview=user[:200],
336
- )
379
+ self._record(
380
+ request,
381
+ CompletionResponse(
382
+ text=text,
383
+ model=model.name,
384
+ provider=self.name,
385
+ usage=usage if usage is not None else TokenUsage(input_tokens=0, output_tokens=0),
386
+ finish_reason=finish,
387
+ ),
388
+ model=model,
337
389
  )
338
390
  for chunk in chunks:
339
391
  yield chunk
340
392
 
341
393
  async def aclose(self) -> None:
342
394
  return None
395
+
396
+
397
+ class RecordingProviders:
398
+ """Wraps every provider a run could call, so one capture covers the whole run.
399
+
400
+ `default_providers()` is keyed by provider name because the gateway selects a provider
401
+ per model, so wrapping a single entry would leave a fallback -- or a second agent on a
402
+ different vendor -- uncaptured, and the recording would silently replay as a shorter
403
+ run. This wraps the mapping instead and keys each wrapper the way the gateway expects.
404
+ """
405
+
406
+ def __init__(self, providers: Mapping[str, Provider], *, spec_version: str = "") -> None:
407
+ if not providers:
408
+ raise EvalError(
409
+ "there is no model provider to record: a capture of nothing would produce a "
410
+ "transcript that replays no call, so point the agent at a model before "
411
+ "recording one"
412
+ )
413
+ self._recorder = _Recorder(spec_version)
414
+ self._wrapped = {
415
+ name: RecordingProvider(provider, recorder=self._recorder)
416
+ for name, provider in providers.items()
417
+ }
418
+
419
+ @property
420
+ def providers(self) -> dict[str, Provider]:
421
+ return dict(self._wrapped)
422
+
423
+ def transcript(self) -> Transcript:
424
+ return self._recorder.transcript()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aid-runtime-python
3
- Version: 0.1.165
3
+ Version: 0.1.167
4
4
  Summary: The AID Framework Python runtime: model gateway with pinning and cost budgets, prompt registry, tool executor, OTel GenAI tracing, plain-async pipeline, and an eval harness that gates on statistical regression against a stored baseline.
5
5
  Author: The AID Framework authors
6
6
  License-Expression: Apache-2.0
@@ -1,4 +1,4 @@
1
- aid_runtime/__init__.py,sha256=ugsNkQFitj5ddM_4-BWbALi_eHkzmd4ansvwgnpK2ac,15227
1
+ aid_runtime/__init__.py,sha256=esvg7KWeCvbvmWtoWKHPjHpbqhBiYlP-_ZGOKhG-1z0,15277
2
2
  aid_runtime/cache.py,sha256=jhw_EBd9dfWEUzYeibOvIkVBqqiLUjqF5WKEPz9GkhE,6836
3
3
  aid_runtime/concurrency.py,sha256=z0tFQHw35ttFLKfazGBjCMPOLQOnUotE_OPpvR1piH4,2829
4
4
  aid_runtime/control.py,sha256=y6wPn0fqYJv0nVSsjzpzfiaq1Y7zBoMxCpdrEuqkfvg,17529
@@ -38,7 +38,7 @@ aid_runtime/evals/metrics.py,sha256=LvzKgW-7CNxcB0MmDXakDnwdgyzjpH8ceHq7mdi8mw4,
38
38
  aid_runtime/evals/predicate.py,sha256=JaeN1LJFpliI4JHYdFPtXfjH5_Aad-2-U3ZC6_hManE,8726
39
39
  aid_runtime/evals/runner.py,sha256=rI5AScHDPnwN5Ohw0I7zR2Df9pGSTE8Un6-lESCSV3g,12827
40
40
  aid_runtime/evals/trajectory.py,sha256=X7ssDigfFuMkjM6mR6LGSbb03A8iNf4oRbVqeSsU7Ww,4444
41
- aid_runtime/providers/__init__.py,sha256=5XMe1kPqckeyv2l_FrfYEiTPWOTGsPKpWtiiTdSn3ic,2284
41
+ aid_runtime/providers/__init__.py,sha256=SgCBtvERTy1y6BAkenH2vYiQH0rE883KDvIWewdNOdA,2334
42
42
  aid_runtime/providers/anthropic.py,sha256=xh_fJyujnFRcknEHFRxA5M-izeR2hJtit-865RrISOQ,15853
43
43
  aid_runtime/providers/base.py,sha256=1VYTZ_V9FR6f6pS0MB3LFeu-Zzv4toQvm3CwAQNbeT0,1851
44
44
  aid_runtime/providers/bedrock.py,sha256=mb-sF5u3Y3Dp_FBgrAublA7sKtExhWrWGOA5p9o0_HA,24515
@@ -46,7 +46,7 @@ aid_runtime/providers/fake.py,sha256=oAcpaDOUIp7lmKGEEWG5ktagstg2dvoHR-9xaUeCDLo
46
46
  aid_runtime/providers/gemini.py,sha256=gM4Kvgz6lnFbHgYYhyVCBTFTcGAKfiNuj7lS1XSldnU,3975
47
47
  aid_runtime/providers/gemini_wire.py,sha256=ZwIiYuAVihszE0c90-uAbSn6_hdMa2Md4asySIYeQTw,13032
48
48
  aid_runtime/providers/http.py,sha256=c5DLmX1FqtAUO01MqDf0m82x8zHD480LyL-QtTrxnn4,13168
49
- aid_runtime/providers/recorded.py,sha256=2MgAHEkt0jFlr2Z4x_5edASQithiLqtpeDy1tBy5rbA,13566
49
+ aid_runtime/providers/recorded.py,sha256=m5zwgVqfD4JwqbS1W4Nu5lpwvrpRKhmSCuICN6Y3Ymc,17101
50
50
  aid_runtime/providers/vertex.py,sha256=XdwPuPw2Ce5CGuoEyzY5jVpqtKeTXWOvY_9WegxheEk,9341
51
51
  aid_runtime/retrieval/__init__.py,sha256=DkFzyKzqT-NjRlOldstTK84y3paEWjWXri7V36xx_cY,6455
52
52
  aid_runtime/retrieval/chunking.py,sha256=jn4tWXaWaQpSkfhqW_pkgd0J95z8PKCasbMgM7l7w-I,20495
@@ -63,7 +63,7 @@ aid_runtime/retrieval/rerank.py,sha256=L4ICBi9YHDzhnKVtImKh5Wzre1HDzS8at-AKDkXBJ
63
63
  aid_runtime/retrieval/retriever.py,sha256=0Cx-_6Qcf2TRolFy4ktMseyyyr-WLphMYYHane0t9lA,24412
64
64
  aid_runtime/retrieval/stores.py,sha256=mG261rUHZIzB7niiTj_DuUzcNMOd4QYENk5ArgI1iBo,6840
65
65
  aid_runtime/retrieval/types.py,sha256=hJ5IRSD-PTfrc1xhuK6CBdX0Yr-S6L_JeSMPity8ecM,20447
66
- aid_runtime_python-0.1.165.dist-info/METADATA,sha256=Vtv64gwZNI-QZ1m9b4MgWRblZQPHjkTT86WhXiI8hUI,17163
67
- aid_runtime_python-0.1.165.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
68
- aid_runtime_python-0.1.165.dist-info/top_level.txt,sha256=QvODgNVRDDMmLcTnoIQ4jYnhqf-N4b9sHWEmaUUxp44,12
69
- aid_runtime_python-0.1.165.dist-info/RECORD,,
66
+ aid_runtime_python-0.1.167.dist-info/METADATA,sha256=XpqNtNi7wTSr_kA8RQzyXFeNMYcpvuJtghYMnQEA5Ts,17163
67
+ aid_runtime_python-0.1.167.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
68
+ aid_runtime_python-0.1.167.dist-info/top_level.txt,sha256=QvODgNVRDDMmLcTnoIQ4jYnhqf-N4b9sHWEmaUUxp44,12
69
+ aid_runtime_python-0.1.167.dist-info/RECORD,,