aid-runtime-python 0.1.163__tar.gz → 0.1.164__tar.gz

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 (130) hide show
  1. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/PKG-INFO +1 -1
  2. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/pyproject.toml +1 -1
  3. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/__init__.py +1 -1
  4. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/agents/loop.py +2 -2
  5. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/agents/policy.py +13 -4
  6. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/agents/resume.py +8 -4
  7. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/evals/agent_runner.py +14 -2
  8. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime_python.egg-info/PKG-INFO +1 -1
  9. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_agent_eval_runner.py +79 -4
  10. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_agents_deep_agents.py +8 -2
  11. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_tool_permissions.py +41 -2
  12. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/README.md +0 -0
  13. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/setup.cfg +0 -0
  14. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/agents/__init__.py +0 -0
  15. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/agents/chat_model.py +0 -0
  16. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/agents/deep_agents.py +0 -0
  17. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/agents/engine.py +0 -0
  18. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/agents/guardrails.py +0 -0
  19. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/agents/ir.py +0 -0
  20. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/agents/managed.py +0 -0
  21. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/agents/memory.py +0 -0
  22. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/agents/state.py +0 -0
  23. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/cache.py +0 -0
  24. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/concurrency.py +0 -0
  25. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/control.py +0 -0
  26. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/cost.py +0 -0
  27. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/decisions.py +0 -0
  28. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/errors.py +0 -0
  29. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/evals/__init__.py +0 -0
  30. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/evals/dataset.py +0 -0
  31. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/evals/gate.py +0 -0
  32. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/evals/metrics.py +0 -0
  33. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/evals/predicate.py +0 -0
  34. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/evals/runner.py +0 -0
  35. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/evals/trajectory.py +0 -0
  36. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/gateway.py +0 -0
  37. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/local_trace.py +0 -0
  38. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/metrics.py +0 -0
  39. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/pipeline.py +0 -0
  40. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/prompts.py +0 -0
  41. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/providers/__init__.py +0 -0
  42. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/providers/anthropic.py +0 -0
  43. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/providers/base.py +0 -0
  44. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/providers/bedrock.py +0 -0
  45. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/providers/fake.py +0 -0
  46. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/providers/gemini.py +0 -0
  47. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/providers/gemini_wire.py +0 -0
  48. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/providers/http.py +0 -0
  49. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/providers/recorded.py +0 -0
  50. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/providers/vertex.py +0 -0
  51. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/py.typed +0 -0
  52. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/redaction.py +0 -0
  53. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/retrieval/__init__.py +0 -0
  54. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/retrieval/chunking.py +0 -0
  55. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/retrieval/citations.py +0 -0
  56. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/retrieval/connectors.py +0 -0
  57. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/retrieval/embedding.py +0 -0
  58. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/retrieval/filters.py +0 -0
  59. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/retrieval/gate.py +0 -0
  60. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/retrieval/hybrid.py +0 -0
  61. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/retrieval/knowledge_base.py +0 -0
  62. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/retrieval/metrics.py +0 -0
  63. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/retrieval/pgvector.py +0 -0
  64. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/retrieval/rerank.py +0 -0
  65. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/retrieval/retriever.py +0 -0
  66. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/retrieval/stores.py +0 -0
  67. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/retrieval/types.py +0 -0
  68. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/steps.py +0 -0
  69. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/structured.py +0 -0
  70. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/telemetry.py +0 -0
  71. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/tools.py +0 -0
  72. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/tracing.py +0 -0
  73. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime/types.py +0 -0
  74. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime_python.egg-info/SOURCES.txt +0 -0
  75. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime_python.egg-info/dependency_links.txt +0 -0
  76. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime_python.egg-info/requires.txt +0 -0
  77. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/src/aid_runtime_python.egg-info/top_level.txt +0 -0
  78. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_agents_budget.py +0 -0
  79. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_agents_checkpoint_integrity.py +0 -0
  80. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_agents_hitl.py +0 -0
  81. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_agents_loop.py +0 -0
  82. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_agents_memory.py +0 -0
  83. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_anthropic_provider.py +0 -0
  84. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_bedrock_provider.py +0 -0
  85. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_cache.py +0 -0
  86. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_concurrency.py +0 -0
  87. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_control.py +0 -0
  88. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_cost.py +0 -0
  89. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_dataset.py +0 -0
  90. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_decisions.py +0 -0
  91. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_evals.py +0 -0
  92. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_evals_assert_gate.py +0 -0
  93. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_evals_budgets.py +0 -0
  94. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_evals_decision.py +0 -0
  95. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_evals_gate.py +0 -0
  96. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_evals_predicate.py +0 -0
  97. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_evals_trajectory.py +0 -0
  98. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_gateway.py +0 -0
  99. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_gemini_provider.py +0 -0
  100. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_guardrails.py +0 -0
  101. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_guardrails_managed.py +0 -0
  102. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_guardrails_model_armor.py +0 -0
  103. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_http_provider.py +0 -0
  104. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_local_trace.py +0 -0
  105. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_metrics.py +0 -0
  106. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_package.py +0 -0
  107. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_pipeline.py +0 -0
  108. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_prompts.py +0 -0
  109. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_recorded_provider.py +0 -0
  110. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_redaction.py +0 -0
  111. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_retrieval_chunking.py +0 -0
  112. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_retrieval_citations.py +0 -0
  113. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_retrieval_connectors.py +0 -0
  114. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_retrieval_embedding.py +0 -0
  115. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_retrieval_filters.py +0 -0
  116. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_retrieval_gate.py +0 -0
  117. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_retrieval_hybrid.py +0 -0
  118. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_retrieval_knowledge_base.py +0 -0
  119. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_retrieval_metrics.py +0 -0
  120. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_retrieval_rerank.py +0 -0
  121. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_retrieval_stores.py +0 -0
  122. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_retrieval_types.py +0 -0
  123. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_steps.py +0 -0
  124. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_streaming.py +0 -0
  125. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_structured.py +0 -0
  126. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_telemetry.py +0 -0
  127. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_tools.py +0 -0
  128. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_tracing.py +0 -0
  129. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_types.py +0 -0
  130. {aid_runtime_python-0.1.163 → aid_runtime_python-0.1.164}/tests/test_vertex_provider.py +0 -0
@@ -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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "aid-runtime-python"
7
- version = "0.1.163"
7
+ version = "0.1.164"
8
8
  description = "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."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -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
@@ -18,7 +18,7 @@ from typing import Any, cast
18
18
  import pytest
19
19
  from pydantic import ValidationError
20
20
 
21
- from agent_support import AUTHENTICATED, recording_tool, solo, tool_def
21
+ from agent_support import ADMIN_ONLY, AUTHENTICATED, recording_tool, solo, tool_def
22
22
  from aid_runtime import (
23
23
  AgentEvalRunner,
24
24
  ApprovalPolicy,
@@ -32,10 +32,11 @@ from aid_runtime import (
32
32
  RecordingProvider,
33
33
  RunStatus,
34
34
  ScriptedTurn,
35
+ ToolPermissionError,
35
36
  ToolTrace,
36
37
  evaluate_once,
37
38
  )
38
- from aid_runtime.agents import HumanDecision
39
+ from aid_runtime.agents import HumanDecision, Principal
39
40
  from aid_runtime.evals.dataset import Dataset
40
41
  from aid_runtime.providers.recorded import Transcript
41
42
 
@@ -43,6 +44,10 @@ PROVIDER = "fake"
43
44
  PROMPT = "You refund orders and nothing else."
44
45
  QUESTION = "Refund order 4471."
45
46
 
47
+ #: The caller these fixtures simulate: signed in, with no roles or scopes of its own, so
48
+ #: an ``isAuthenticated()`` policy holds and a ``hasRole(...)`` one does not.
49
+ _SIGNED_IN = Principal(authenticated=True)
50
+
46
51
 
47
52
  def _agent(**agent_fields: Any) -> dict[str, Any]:
48
53
  """One agent, one searchable tool, scripted by the caller's fake."""
@@ -57,8 +62,9 @@ def _agent(**agent_fields: Any) -> dict[str, Any]:
57
62
  def _gated(**agent_fields: Any) -> dict[str, Any]:
58
63
  """The same agent, except every step waits for a person.
59
64
 
60
- ``isAuthenticated()`` is true for the default principal, which makes it the
61
- unconditional ``when`` a spec can actually express -- there is no ``kind: always``.
65
+ ``isAuthenticated()`` is the unconditional ``when`` a spec can actually express --
66
+ there is no ``kind: always`` -- so this fixture only pauses for a principal that is
67
+ authenticated, which is the principal every runner in this module simulates.
62
68
  """
63
69
  return _agent(hitl={"when": AUTHENTICATED, "channel": "ops"}, **agent_fields)
64
70
 
@@ -67,6 +73,19 @@ def _provider(*turns: ScriptedTurn) -> FakeProvider:
67
73
  return FakeProvider(name=PROVIDER, script=list(turns))
68
74
 
69
75
 
76
+ def _write_agent(*, auth: dict[str, Any] | None = None) -> dict[str, Any]:
77
+ """One agent whose only tool mutates, so ``isAuthenticated()`` stands between it and a caller.
78
+
79
+ ``tool_def`` supplies that policy when the tool writes, because the security gate
80
+ rejects a mutating tool without one: this is the shape a compiled document really has.
81
+ """
82
+ return solo(
83
+ prompt=PROMPT,
84
+ tool_specs=[tool_def("t1", "search", side_effects="write", auth=auth)],
85
+ tools=["t1"],
86
+ )
87
+
88
+
70
89
  def _runner(
71
90
  document: dict[str, Any],
72
91
  provider: Provider,
@@ -74,11 +93,16 @@ def _runner(
74
93
  tools: Any = None,
75
94
  policy: ApprovalPolicy | str = ApprovalPolicy.FROM_CASE,
76
95
  max_resumes: int = 8,
96
+ principal: Principal | None = _SIGNED_IN,
77
97
  ) -> AgentEvalRunner:
78
98
  """A runner over ``document``, registering ``search`` unless the test says otherwise.
79
99
 
80
100
  Registering the documented tool by default keeps every test driving a document whose
81
101
  declared tools are present. A test that cares about the tool passes its own recorder.
102
+
103
+ The default principal is a signed-in one because these fixtures describe an app that
104
+ verified a token; the runner's own default is anonymous on purpose, and the tests in
105
+ :class:`TestPrincipal` are the ones that exercise it.
82
106
  """
83
107
  registered = (recording_tool()[0],) if tools is None else tools
84
108
  return AgentEvalRunner(
@@ -88,6 +112,7 @@ def _runner(
88
112
  tools=registered,
89
113
  approval_policy=policy,
90
114
  max_resumes=max_resumes,
115
+ principal=principal,
91
116
  )
92
117
 
93
118
 
@@ -453,6 +478,56 @@ class TestRefusal:
453
478
  assert case.approvals == (HumanDecision.APPROVE,)
454
479
 
455
480
 
481
+ class TestPrincipal:
482
+ """What an eval claims when it does not name the caller it simulates."""
483
+
484
+ async def test_with_no_principal_a_write_tool_is_refused(self) -> None:
485
+ """The default is anonymous, so a mutating tool is refused, not permitted.
486
+
487
+ An eval that silently ran as an authenticated caller would report a tool path
488
+ production could not take behind an app that never verified a token.
489
+ """
490
+ tool, recorder = recording_tool()
491
+ document = _write_agent()
492
+ provider = _provider(ScriptedTurn.tool("search", {"query": "4471"}))
493
+
494
+ with pytest.raises(ToolPermissionError) as raised:
495
+ await _runner(document, provider, tools=(tool,), principal=None)(
496
+ EvalCase(id="refund", input=QUESTION)
497
+ )
498
+
499
+ assert recorder.queries == []
500
+ assert "denies this principal" in raised.value.reason
501
+
502
+ async def test_a_signed_in_principal_can_reach_the_same_tool(self) -> None:
503
+ """The positive control for the case above: the refusal was the caller, not the tool."""
504
+ tool, recorder = recording_tool()
505
+ document = _write_agent()
506
+ provider = _provider(
507
+ ScriptedTurn.tool("search", {"query": "4471"}),
508
+ ScriptedTurn.answer("refunded"),
509
+ )
510
+
511
+ await _runner(document, provider, tools=(tool,), principal=_SIGNED_IN)(
512
+ EvalCase(id="refund", input=QUESTION)
513
+ )
514
+
515
+ assert recorder.queries == ["4471"]
516
+
517
+ async def test_an_unprivileged_principal_still_cannot_use_an_admin_role(self) -> None:
518
+ """Signed in is not the same as privileged: roles are still evaluated per tool."""
519
+ tool, recorder = recording_tool()
520
+ document = _write_agent(auth=ADMIN_ONLY)
521
+ provider = _provider(ScriptedTurn.tool("search", {"query": "4471"}))
522
+
523
+ with pytest.raises(ToolPermissionError):
524
+ await _runner(document, provider, tools=(tool,), principal=_SIGNED_IN)(
525
+ EvalCase(id="refund", input=QUESTION)
526
+ )
527
+
528
+ assert recorder.queries == []
529
+
530
+
456
531
  class TestReplay:
457
532
  async def test_a_recorded_transcript_drives_the_run_without_a_vendor(self) -> None:
458
533
  """Record once against a scripted fake, then gate on the bytes forever."""
@@ -61,6 +61,7 @@ from aid_runtime.agents.engine import (
61
61
  DEEPAGENTS_PIN,
62
62
  installed_deepagents_version,
63
63
  )
64
+ from aid_runtime.agents.policy import Principal
64
65
  from aid_runtime.agents.state import RunStatus
65
66
 
66
67
  pytestmark = pytest.mark.skipif(
@@ -70,6 +71,11 @@ pytestmark = pytest.mark.skipif(
70
71
 
71
72
  PROMPT = "Answer in one sentence."
72
73
  QUESTION = "How long does delivery take?"
74
+
75
+ #: The caller the approval tests simulate: signed in, so a ``deploy`` tool whose policy is
76
+ #: ``isAuthenticated()`` is permitted once a person approves it. The runtime's own default
77
+ #: is anonymous, and an anonymous caller is refused at the tool boundary instead.
78
+ _SIGNED_IN = Principal(authenticated=True)
73
79
  PIN = DEEPAGENTS_PIN
74
80
 
75
81
 
@@ -609,7 +615,7 @@ async def test_hitl_pauses_before_the_tool_and_approval_executes_it() -> None:
609
615
  script=[ScriptedTurn.tool("deploy", {"query": "prod"})],
610
616
  )
611
617
 
612
- paused = await harness.runtime.run("solo", QUESTION)
618
+ paused = await harness.runtime.run("solo", QUESTION, principal=_SIGNED_IN)
613
619
 
614
620
  assert paused.status is RunStatus.PAUSED
615
621
  assert paused.checkpoint is not None
@@ -617,7 +623,7 @@ async def test_hitl_pauses_before_the_tool_and_approval_executes_it() -> None:
617
623
  # The tool has not run: a pause is a question, not a decision.
618
624
  assert recorder.calls == 0
619
625
 
620
- resumed = await harness.runtime.resume(paused.checkpoint, "approve")
626
+ resumed = await harness.runtime.resume(paused.checkpoint, "approve", principal=_SIGNED_IN)
621
627
 
622
628
  assert resumed.completed
623
629
  assert recorder.queries == ["prod"]
@@ -14,7 +14,7 @@ import pytest
14
14
 
15
15
  from agent_support import ADMIN_ONLY, SEARCH_SCHEMA, build, solo, tool_def
16
16
  from aid_runtime import ScriptedTurn, Tool, ToolPermissionError
17
- from aid_runtime.agents import RunStatus
17
+ from aid_runtime.agents import Principal, RunStatus
18
18
 
19
19
  WRITER = "writer"
20
20
  READER = "reader"
@@ -56,13 +56,22 @@ async def _run(
56
56
  *,
57
57
  extra: Sequence[Tool] = (),
58
58
  target: str = WRITER,
59
+ principal: Principal | None = None,
59
60
  ) -> Any:
61
+ """Run one call against ``document`` as ``principal``.
62
+
63
+ The default is signed in but unprivileged: every mutating fixture tool carries
64
+ ``isAuthenticated()``, so the anonymous principal the runtime seeds would refuse
65
+ before the grant under test was ever consulted. Roles stay empty so an
66
+ ``ADMIN_ONLY`` policy still denies, which is what the negative cases assert.
67
+ """
60
68
  harness = build(
61
69
  document,
62
70
  script=[ScriptedTurn.tool(target, {"query": "hello"}), ScriptedTurn.answer("done")],
63
71
  tools=[tool, *extra],
64
72
  )
65
- return await harness.runtime.run("solo", "do the thing")
73
+ caller = principal if principal is not None else Principal(authenticated=True)
74
+ return await harness.runtime.run("solo", "do the thing", principal=caller)
66
75
 
67
76
 
68
77
  # --- the grant is the agent's declared tool list ---------------------------------
@@ -153,6 +162,36 @@ async def test_an_auth_policy_that_denies_this_principal_never_runs_the_body() -
153
162
  assert "denies this principal" in raised.value.reason
154
163
 
155
164
 
165
+ async def test_an_unauthenticated_caller_cannot_reach_a_write_tool() -> None:
166
+ """``isAuthenticated()`` is the weakest mutating policy, so anonymous must not hold it.
167
+
168
+ This is the route-level defect in miniature: a handler that forgets to pass the
169
+ principal it verified runs as whoever the runtime defaults to. The assertion is on the
170
+ default, not just on an explicit anonymous principal, because that is the one a
171
+ forgotten argument produces.
172
+ """
173
+ tool, calls = counting_tool(WRITER)
174
+ document = solo(tool_specs=[tool_def(WRITER, WRITER, side_effects="write")], tools=[WRITER])
175
+ harness = build(
176
+ document,
177
+ script=[ScriptedTurn.tool(WRITER, {"query": "hello"}), ScriptedTurn.answer("done")],
178
+ tools=[tool],
179
+ )
180
+
181
+ with pytest.raises(ToolPermissionError) as raised:
182
+ await harness.runtime.run("solo", "do the thing")
183
+
184
+ assert calls == []
185
+ assert "denies this principal" in raised.value.reason
186
+
187
+
188
+ async def test_the_runtime_defaults_to_the_anonymous_principal() -> None:
189
+ """A default that is authenticated is a silent authorization bug, so it is not one."""
190
+ assert Principal().authenticated is False
191
+ assert Principal().roles == frozenset()
192
+ assert Principal().scopes == frozenset()
193
+
194
+
156
195
  async def test_an_undecidable_auth_policy_is_a_denial() -> None:
157
196
  """A policy the evaluator cannot answer must not degrade into a permit."""
158
197
  tool, calls = counting_tool(WRITER)