aid-runtime-python 0.1.163__py3-none-any.whl → 0.1.164__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
@@ -356,7 +356,7 @@ from aid_runtime.types import (
356
356
  )
357
357
 
358
358
  #: Kept in sync with ``pyproject.toml`` by a test, so the two cannot drift.
359
- __version__ = "0.1.163"
359
+ __version__ = "0.1.164"
360
360
 
361
361
  __all__ = [
362
362
  "AGENT_LABEL",
@@ -294,7 +294,7 @@ class AgentRuntime:
294
294
  try:
295
295
  outcome = await self._drive(
296
296
  frame,
297
- principal=principal if principal is not None else Principal(),
297
+ principal=principal if principal is not None else Principal.unauthenticated(),
298
298
  memory_key=key,
299
299
  )
300
300
  except BaseException:
@@ -321,7 +321,7 @@ class AgentRuntime:
321
321
  outcome = await self._resume(
322
322
  checkpoint,
323
323
  resolved,
324
- principal if principal is not None else Principal(),
324
+ principal if principal is not None else Principal.unauthenticated(),
325
325
  )
326
326
  except BaseException:
327
327
  # Same rule as `run`: a resumed run that fails has been billed too.
@@ -36,14 +36,23 @@ _LOGICAL = frozenset({"and", "or"})
36
36
  class Principal:
37
37
  """Who a policy is evaluated for.
38
38
 
39
- Defaults are the anonymous-but-authenticated caller an app with no auth layer
40
- has: ``isAuthenticated()`` is true and both role and scope sets are empty, so
41
- ``hasRole('admin')`` is false rather than undefined.
39
+ ``authenticated`` defaults to **false** on purpose. A default that is authenticated is
40
+ a silent authorization bug: ``isAuthenticated()`` is the weakest policy the security
41
+ gate accepts on a mutating tool, so a caller the app never identified would satisfy it.
42
+ :meth:`unauthenticated` is the caller an app with no auth layer has -- no roles, no
43
+ scopes, and ``isAuthenticated()`` false, which is the closed answer. Pass
44
+ ``authenticated=True`` only from code that actually verified a token.
42
45
  """
43
46
 
44
47
  roles: frozenset[str] = frozenset()
45
48
  scopes: frozenset[str] = frozenset()
46
- authenticated: bool = True
49
+ authenticated: bool = False
50
+
51
+ @classmethod
52
+ def unauthenticated(cls) -> Principal:
53
+ """The caller a route seeds when nothing verified a token: anonymous, fail-closed."""
54
+
55
+ return cls(authenticated=False)
47
56
 
48
57
 
49
58
  def evaluate_policy(node: Mapping[str, Any], principal: Principal) -> bool:
@@ -24,10 +24,14 @@ missing secret must not degrade into "unsigned".
24
24
 
25
25
  Replay durability is limited by the nonce store, and that limit is real rather than
26
26
  theoretical: :class:`InProcessNonceStore` forgets on restart and does not span replicas.
27
- :class:`SqliteNonceStore` is durable and is what a ``state.kind: sqlite`` declaration
28
- gets. A ``state.kind: postgres`` declaration is served in-process for now, which the
29
- ``ir/resume-replay-weak`` gate states on the document rather than leaving to be
30
- discovered.
27
+ :class:`SqliteNonceStore` and :class:`PostgresNonceStore` are durable and are what a
28
+ ``state.kind: sqlite`` or ``state.kind: postgres`` declaration gets; only a document that
29
+ declares no store at all falls back to the in-process one, which ``ir/resume-replay-weak``
30
+ states on the document rather than leaving to be discovered.
31
+
32
+ This module stores the *nonce*, not the run. The checkpoint for a paused run still returns
33
+ to the caller, so resuming after a restart is the application's to arrange -- see
34
+ :mod:`aid_runtime.agents.state`.
31
35
  """
32
36
 
33
37
  from __future__ import annotations
@@ -20,6 +20,13 @@ that pauses without supplying one is refused. The one exception is deliberate an
20
20
  ``ApprovalPolicy.APPROVE``/``REJECT`` exist for datasets that are testing something other
21
21
  than the approval, and they are named so a reader of the eval sees the scripted answer.
22
22
 
23
+ **It runs as a stated principal.** An agent's tools and approvals are policies over a
24
+ :class:`Principal`, so an eval that does not name the caller is evaluating an anonymous
25
+ one. That default is the closed answer and is kept deliberately: a mutating tool whose
26
+ policy is ``isAuthenticated()`` is refused for it, and a case written for a signed-in
27
+ caller has to say so. An eval that quietly ran as an authenticated caller would report a
28
+ tool path that production, behind an app which never verified a token, could not take.
29
+
23
30
  What this measures is worth stating plainly, since the module is named after the eval and
24
31
  not the model. When the provider is a recorded transcript or a scripted fake, the model's
25
32
  choices are fixed input: the run verifies that the machinery around the model obeys the
@@ -37,6 +44,7 @@ from enum import StrEnum
37
44
 
38
45
  from aid_runtime.agents.loop import AgentRuntime
39
46
  from aid_runtime.agents.memory import InProcessMemoryStore
47
+ from aid_runtime.agents.policy import Principal
40
48
  from aid_runtime.agents.state import HumanDecision, RunResult, RunStatus
41
49
  from aid_runtime.errors import ConfigurationError, EvalError
42
50
  from aid_runtime.evals.dataset import EvalCase
@@ -88,6 +96,7 @@ class AgentEvalRunner:
88
96
  tools: Iterable[Tool] = (),
89
97
  approval_policy: ApprovalPolicy | str = ApprovalPolicy.FROM_CASE,
90
98
  max_resumes: int = _DEFAULT_MAX_RESUMES,
99
+ principal: Principal | None = None,
91
100
  ) -> None:
92
101
  if not providers:
93
102
  raise ConfigurationError(
@@ -107,6 +116,9 @@ class AgentEvalRunner:
107
116
  self._tools = tuple(tools)
108
117
  self._policy = ApprovalPolicy(approval_policy)
109
118
  self._max_resumes = max_resumes
119
+ #: The caller this eval simulates. Anonymous unless the caller names one, so a
120
+ #: mutating tool is refused rather than silently permitted.
121
+ self._principal = principal if principal is not None else Principal.unauthenticated()
110
122
  #: Cumulative model spend, which is what ``evaluate_once`` differences to charge
111
123
  #: each case. Read from the ledger of the most recent run.
112
124
  self._cost_usd = 0.0
@@ -139,7 +151,7 @@ class AgentEvalRunner:
139
151
  runtime = self._runtime()
140
152
  before = runtime.gateway.ledger.cost_usd
141
153
  try:
142
- result = await runtime.run(self._agent_id, case.input)
154
+ result = await runtime.run(self._agent_id, case.input, principal=self._principal)
143
155
  result, approvals = await self._settle(runtime, case, result)
144
156
  finally:
145
157
  # Charged even when the run raised: a case stopped by a guardrail was billed,
@@ -205,7 +217,7 @@ class AgentEvalRunner:
205
217
  _Rejection(boundary=rejection.boundary, names=rejection.names - names)
206
218
  for rejection in rejections
207
219
  ]
208
- result = await runtime.resume(checkpoint, decision)
220
+ result = await runtime.resume(checkpoint, decision, principal=self._principal)
209
221
  return result, _Approvals(
210
222
  pauses=pauses,
211
223
  decisions=tuple(applied),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aid-runtime-python
3
- Version: 0.1.163
3
+ Version: 0.1.164
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=aq8poIy2LFueKsPEbAN84Bi3Z2oETd3b_kvauiwj_Jo,15187
1
+ aid_runtime/__init__.py,sha256=M-pbsJJ90R1eocStUMJd5hgLvWhOXzSc0Qqa73qYRo4,15187
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
@@ -24,14 +24,14 @@ aid_runtime/agents/deep_agents.py,sha256=Eg_BLm2cg7T_tXSxR7ag8SEvTMCFBLHoIvln3Bo
24
24
  aid_runtime/agents/engine.py,sha256=3cXCYY806URDblYD500cfw7873IoVCy8BH1d4h2YAsc,5789
25
25
  aid_runtime/agents/guardrails.py,sha256=0HhbToZBxPZHEDRLyD9BGS_jmV-TkKPGEhRynYxLXx8,32813
26
26
  aid_runtime/agents/ir.py,sha256=MgqX5gEkq7vimXojtSNb5MuVeTIZaWkZCFitxAqSAe0,32855
27
- aid_runtime/agents/loop.py,sha256=gTfFRcRuGuyZpNdw2PK168A9Cp6LHBLJMUpHUxXPTnE,55952
27
+ aid_runtime/agents/loop.py,sha256=Byi7Z2OpnSKTJ2_7-elPXH-9WvoQUf5swPYYKk8oZhs,55984
28
28
  aid_runtime/agents/managed.py,sha256=SFyx6Rca2aoiMzA9q6B4Nfes6ZCjn_5_zN0SxzemIII,23247
29
29
  aid_runtime/agents/memory.py,sha256=6_D6k2bzAiR2euNvzr6HB28wsUUq-R-WTQc12gkB8ao,9156
30
- aid_runtime/agents/policy.py,sha256=ael0EW_hWfLu95rbqFMrR4WyqAPtgiSNvNw97xnthdw,6122
31
- aid_runtime/agents/resume.py,sha256=VAjJja2ZvXLLSRgz9Z_2b5Cs9Af5Kevr5qjuDpslpuw,17035
30
+ aid_runtime/agents/policy.py,sha256=IbJ9LQDPOumwup5K_eeyFAfCLFuMqEK6iSvBrM6o16Q,6610
31
+ aid_runtime/agents/resume.py,sha256=FM2SbsQZEOCKtHkEsu8riIcbsXYf9ieaioZ32UBN-to,17306
32
32
  aid_runtime/agents/state.py,sha256=feXZtQeD3vcKpNUPsCXby0J15UqkoD4_Gi-aT3Up8RI,7174
33
33
  aid_runtime/evals/__init__.py,sha256=5_qUGwiKR2l4p-F8RZ9QnxzFOxtNj7DWoEsA8uNyHIs,1991
34
- aid_runtime/evals/agent_runner.py,sha256=E1Vg48gNAeQzGGSyp0cK8H5mxGlVEPBq-FTaaTQ-CLE,12594
34
+ aid_runtime/evals/agent_runner.py,sha256=sffFGqZDBLmKkce6t82IaWJLHNq-q7HuSmIM61uEkoU,13513
35
35
  aid_runtime/evals/dataset.py,sha256=ZmTP-jWx9f2udYPyzvTtOuUse5Mp-uj5WNBPy-7aHKM,5946
36
36
  aid_runtime/evals/gate.py,sha256=uYUOw57MaGqSOsMvbB0C6MrjW4IbUJ57izyD6FSxkxw,17676
37
37
  aid_runtime/evals/metrics.py,sha256=LvzKgW-7CNxcB0MmDXakDnwdgyzjpH8ceHq7mdi8mw4,28541
@@ -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.163.dist-info/METADATA,sha256=XBOwwaxOR6fnCKOlGWFeUYukKzWGBsttWdLvtLCG9Vw,17163
67
- aid_runtime_python-0.1.163.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
68
- aid_runtime_python-0.1.163.dist-info/top_level.txt,sha256=QvODgNVRDDMmLcTnoIQ4jYnhqf-N4b9sHWEmaUUxp44,12
69
- aid_runtime_python-0.1.163.dist-info/RECORD,,
66
+ aid_runtime_python-0.1.164.dist-info/METADATA,sha256=GBlFqJjmGPFPh8i0p9I47WUlTEMiJEJbdYoNfEt8N2k,17163
67
+ aid_runtime_python-0.1.164.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
68
+ aid_runtime_python-0.1.164.dist-info/top_level.txt,sha256=QvODgNVRDDMmLcTnoIQ4jYnhqf-N4b9sHWEmaUUxp44,12
69
+ aid_runtime_python-0.1.164.dist-info/RECORD,,