aid-runtime-python 0.1.157__tar.gz → 0.1.159__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 (126) hide show
  1. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/PKG-INFO +1 -1
  2. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/pyproject.toml +1 -1
  3. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/__init__.py +21 -1
  4. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/evals/__init__.py +9 -0
  5. aid_runtime_python-0.1.159/src/aid_runtime/evals/agent_runner.py +282 -0
  6. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/evals/dataset.py +37 -2
  7. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/evals/metrics.py +156 -0
  8. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/evals/trajectory.py +45 -4
  9. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/providers/__init__.py +15 -1
  10. aid_runtime_python-0.1.159/src/aid_runtime/providers/recorded.py +342 -0
  11. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime_python.egg-info/PKG-INFO +1 -1
  12. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime_python.egg-info/SOURCES.txt +4 -0
  13. aid_runtime_python-0.1.159/tests/test_agent_eval_runner.py +507 -0
  14. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_dataset.py +13 -0
  15. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_evals_trajectory.py +168 -0
  16. aid_runtime_python-0.1.159/tests/test_recorded_provider.py +246 -0
  17. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/README.md +0 -0
  18. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/setup.cfg +0 -0
  19. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/agents/__init__.py +0 -0
  20. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/agents/chat_model.py +0 -0
  21. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/agents/deep_agents.py +0 -0
  22. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/agents/engine.py +0 -0
  23. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/agents/guardrails.py +0 -0
  24. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/agents/ir.py +0 -0
  25. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/agents/loop.py +0 -0
  26. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/agents/managed.py +0 -0
  27. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/agents/memory.py +0 -0
  28. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/agents/policy.py +0 -0
  29. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/agents/state.py +0 -0
  30. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/cache.py +0 -0
  31. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/concurrency.py +0 -0
  32. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/control.py +0 -0
  33. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/cost.py +0 -0
  34. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/decisions.py +0 -0
  35. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/errors.py +0 -0
  36. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/evals/gate.py +0 -0
  37. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/evals/predicate.py +0 -0
  38. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/evals/runner.py +0 -0
  39. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/gateway.py +0 -0
  40. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/local_trace.py +0 -0
  41. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/metrics.py +0 -0
  42. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/pipeline.py +0 -0
  43. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/prompts.py +0 -0
  44. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/providers/anthropic.py +0 -0
  45. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/providers/base.py +0 -0
  46. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/providers/bedrock.py +0 -0
  47. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/providers/fake.py +0 -0
  48. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/providers/gemini.py +0 -0
  49. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/providers/gemini_wire.py +0 -0
  50. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/providers/http.py +0 -0
  51. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/providers/vertex.py +0 -0
  52. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/py.typed +0 -0
  53. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/retrieval/__init__.py +0 -0
  54. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/retrieval/chunking.py +0 -0
  55. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/retrieval/citations.py +0 -0
  56. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/retrieval/connectors.py +0 -0
  57. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/retrieval/embedding.py +0 -0
  58. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/retrieval/filters.py +0 -0
  59. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/retrieval/gate.py +0 -0
  60. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/retrieval/hybrid.py +0 -0
  61. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/retrieval/knowledge_base.py +0 -0
  62. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/retrieval/metrics.py +0 -0
  63. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/retrieval/pgvector.py +0 -0
  64. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/retrieval/rerank.py +0 -0
  65. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/retrieval/retriever.py +0 -0
  66. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/retrieval/stores.py +0 -0
  67. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/retrieval/types.py +0 -0
  68. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/steps.py +0 -0
  69. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/structured.py +0 -0
  70. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/telemetry.py +0 -0
  71. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/tools.py +0 -0
  72. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/tracing.py +0 -0
  73. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime/types.py +0 -0
  74. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime_python.egg-info/dependency_links.txt +0 -0
  75. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime_python.egg-info/requires.txt +0 -0
  76. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/src/aid_runtime_python.egg-info/top_level.txt +0 -0
  77. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_agents_budget.py +0 -0
  78. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_agents_deep_agents.py +0 -0
  79. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_agents_hitl.py +0 -0
  80. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_agents_loop.py +0 -0
  81. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_agents_memory.py +0 -0
  82. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_anthropic_provider.py +0 -0
  83. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_bedrock_provider.py +0 -0
  84. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_cache.py +0 -0
  85. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_concurrency.py +0 -0
  86. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_control.py +0 -0
  87. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_cost.py +0 -0
  88. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_decisions.py +0 -0
  89. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_evals.py +0 -0
  90. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_evals_assert_gate.py +0 -0
  91. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_evals_budgets.py +0 -0
  92. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_evals_decision.py +0 -0
  93. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_evals_gate.py +0 -0
  94. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_evals_predicate.py +0 -0
  95. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_gateway.py +0 -0
  96. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_gemini_provider.py +0 -0
  97. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_guardrails.py +0 -0
  98. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_guardrails_managed.py +0 -0
  99. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_guardrails_model_armor.py +0 -0
  100. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_http_provider.py +0 -0
  101. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_local_trace.py +0 -0
  102. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_metrics.py +0 -0
  103. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_package.py +0 -0
  104. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_pipeline.py +0 -0
  105. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_prompts.py +0 -0
  106. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_retrieval_chunking.py +0 -0
  107. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_retrieval_citations.py +0 -0
  108. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_retrieval_connectors.py +0 -0
  109. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_retrieval_embedding.py +0 -0
  110. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_retrieval_filters.py +0 -0
  111. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_retrieval_gate.py +0 -0
  112. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_retrieval_hybrid.py +0 -0
  113. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_retrieval_knowledge_base.py +0 -0
  114. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_retrieval_metrics.py +0 -0
  115. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_retrieval_rerank.py +0 -0
  116. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_retrieval_stores.py +0 -0
  117. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_retrieval_types.py +0 -0
  118. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_steps.py +0 -0
  119. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_streaming.py +0 -0
  120. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_structured.py +0 -0
  121. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_telemetry.py +0 -0
  122. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_tool_permissions.py +0 -0
  123. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_tools.py +0 -0
  124. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_tracing.py +0 -0
  125. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/tests/test_types.py +0 -0
  126. {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.159}/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.157
3
+ Version: 0.1.159
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.157"
7
+ version = "0.1.159"
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"
@@ -114,6 +114,9 @@ from aid_runtime.errors import (
114
114
  UnknownModelAliasError,
115
115
  )
116
116
  from aid_runtime.evals import (
117
+ AgentEvalRunner,
118
+ ApprovalPolicy,
119
+ ApprovalRespected,
117
120
  BaselineGate,
118
121
  CaseOutcome,
119
122
  CostCeiling,
@@ -123,6 +126,7 @@ from aid_runtime.evals import (
123
126
  EvalCase,
124
127
  EvalRun,
125
128
  ExactMatch,
129
+ ForbiddenTool,
126
130
  GateResult,
127
131
  GatewayRunner,
128
132
  JsonSchemaValid,
@@ -138,6 +142,7 @@ from aid_runtime.evals import (
138
142
  RunContext,
139
143
  Runner,
140
144
  RunOutput,
145
+ StepCount,
141
146
  Threshold,
142
147
  ToolTrace,
143
148
  Trajectory,
@@ -184,7 +189,12 @@ from aid_runtime.providers import (
184
189
  GeminiProvider,
185
190
  OpenAICompatibleProvider,
186
191
  Provider,
192
+ RecordedProvider,
193
+ RecordingProvider,
194
+ ReplayDivergenceError,
187
195
  ScriptedTurn,
196
+ Transcript,
197
+ TranscriptEntry,
188
198
  VertexProvider,
189
199
  default_bedrock_base_url,
190
200
  default_vertex_base_url,
@@ -337,7 +347,7 @@ from aid_runtime.types import (
337
347
  )
338
348
 
339
349
  #: Kept in sync with ``pyproject.toml`` by a test, so the two cannot drift.
340
- __version__ = "0.1.157"
350
+ __version__ = "0.1.159"
341
351
 
342
352
  __all__ = [
343
353
  "AGENT_LABEL",
@@ -378,11 +388,14 @@ __all__ = [
378
388
  "AgentBudgetDegradedError",
379
389
  "AgentCheckpoint",
380
390
  "AgentDefinition",
391
+ "AgentEvalRunner",
381
392
  "AgentHandoffUnsupportedError",
382
393
  "AgentRuntime",
383
394
  "AgentTransferCycleError",
384
395
  "AidRuntimeError",
385
396
  "AnthropicProvider",
397
+ "ApprovalPolicy",
398
+ "ApprovalRespected",
386
399
  "BaselineGate",
387
400
  "BedrockProvider",
388
401
  "Budget",
@@ -436,6 +449,7 @@ __all__ = [
436
449
  "FileMemoryStore",
437
450
  "FinishReason",
438
451
  "FixedChunker",
452
+ "ForbiddenTool",
439
453
  "GateConfigurationError",
440
454
  "GateResult",
441
455
  "GatewayRunner",
@@ -496,10 +510,13 @@ __all__ = [
496
510
  "ProviderResponseError",
497
511
  "RankedId",
498
512
  "RecallAtK",
513
+ "RecordedProvider",
514
+ "RecordingProvider",
499
515
  "RecursiveChunker",
500
516
  "RefreshMode",
501
517
  "RefreshSpec",
502
518
  "RenderedPrompt",
519
+ "ReplayDivergenceError",
503
520
  "RerankSpec",
504
521
  "Reranker",
505
522
  "RetrievalCase",
@@ -528,6 +545,7 @@ __all__ = [
528
545
  "SourceSpec",
529
546
  "SpendSummary",
530
547
  "Step",
548
+ "StepCount",
531
549
  "StepKind",
532
550
  "StepRecord",
533
551
  "StepResult",
@@ -553,6 +571,8 @@ __all__ = [
553
571
  "ToolSpec",
554
572
  "ToolTrace",
555
573
  "Trajectory",
574
+ "Transcript",
575
+ "TranscriptEntry",
556
576
  "UnknownModelAliasError",
557
577
  "VectorStore",
558
578
  "VectorStoreSpec",
@@ -2,6 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ from aid_runtime.evals.agent_runner import AgentEvalRunner, ApprovalPolicy
5
6
  from aid_runtime.evals.dataset import Dataset, EvalCase
6
7
  from aid_runtime.evals.gate import (
7
8
  BaselineGate,
@@ -16,10 +17,12 @@ from aid_runtime.evals.gate import (
16
17
  z_critical,
17
18
  )
18
19
  from aid_runtime.evals.metrics import (
20
+ ApprovalRespected,
19
21
  AssertMetric,
20
22
  CostCeiling,
21
23
  DecisionScore,
22
24
  ExactMatch,
25
+ ForbiddenTool,
23
26
  JsonSchemaValid,
24
27
  JudgeVerdict,
25
28
  LatencyCeiling,
@@ -28,6 +31,7 @@ from aid_runtime.evals.metrics import (
28
31
  MetricResult,
29
32
  NormalizedContains,
30
33
  RunContext,
34
+ StepCount,
31
35
  ToolTrace,
32
36
  default_metrics,
33
37
  metric_names,
@@ -45,6 +49,9 @@ from aid_runtime.evals.runner import (
45
49
  from aid_runtime.evals.trajectory import RunOutput, Trajectory
46
50
 
47
51
  __all__ = [
52
+ "AgentEvalRunner",
53
+ "ApprovalPolicy",
54
+ "ApprovalRespected",
48
55
  "AssertMetric",
49
56
  "BaselineGate",
50
57
  "CaseOutcome",
@@ -56,6 +63,7 @@ __all__ = [
56
63
  "EvalCase",
57
64
  "EvalRun",
58
65
  "ExactMatch",
66
+ "ForbiddenTool",
59
67
  "GateResult",
60
68
  "GatewayRunner",
61
69
  "JsonSchemaValid",
@@ -71,6 +79,7 @@ __all__ = [
71
79
  "RunContext",
72
80
  "RunOutput",
73
81
  "Runner",
82
+ "StepCount",
74
83
  "Threshold",
75
84
  "ToolTrace",
76
85
  "Trajectory",
@@ -0,0 +1,282 @@
1
+ """An agent as an eval subject: run it, and score what it did.
2
+
3
+ The runner is the seam between a dataset and the agent loop, and it exists so that the
4
+ loop does not have to know it is being evaluated. A case goes in, an answer plus the
5
+ trajectory comes out, and ``tool-trace`` can then ask whether the run looked the order up
6
+ before issuing the refund.
7
+
8
+ Two things this runner is careful about, because getting either wrong makes an agent eval
9
+ say something it cannot back:
10
+
11
+ **It reports the trajectory or it says nothing.** ``RunOutput.trajectory`` is read off the
12
+ steps the loop recorded, so a run that paused at an approval still reports the calls that
13
+ asked for it. A runner that returned a bare string would satisfy every text metric and
14
+ fail every ``tool-trace`` one, which is the correct outcome: refusing beats passing on
15
+ evidence that was never collected.
16
+
17
+ **It does not answer on the reviewer's behalf.** A run pauses because the spec said a
18
+ person must decide. The decisions come from the case (``EvalCase.approvals``), and a case
19
+ that pauses without supplying one is refused. The one exception is deliberate and opt-in:
20
+ ``ApprovalPolicy.APPROVE``/``REJECT`` exist for datasets that are testing something other
21
+ than the approval, and they are named so a reader of the eval sees the scripted answer.
22
+
23
+ What this measures is worth stating plainly, since the module is named after the eval and
24
+ not the model. When the provider is a recorded transcript or a scripted fake, the model's
25
+ choices are fixed input: the run verifies that the machinery around the model obeys the
26
+ spec -- the step ceiling stops the run, an interior tool stays interior, a rejected
27
+ approval blocks the call, the spend is attributed to the case. It does not measure whether
28
+ a model chooses those calls, because no model is consulted. Verifying model behaviour
29
+ needs a pinned provider and belongs with the baselines, not with a gate.
30
+ """
31
+
32
+ from __future__ import annotations
33
+
34
+ from collections.abc import Iterable, Iterator, Mapping, Sequence
35
+ from dataclasses import dataclass
36
+ from enum import StrEnum
37
+
38
+ from aid_runtime.agents.loop import AgentRuntime
39
+ from aid_runtime.agents.memory import InProcessMemoryStore
40
+ from aid_runtime.agents.state import HumanDecision, RunResult, RunStatus
41
+ from aid_runtime.errors import ConfigurationError, EvalError
42
+ from aid_runtime.evals.dataset import EvalCase
43
+ from aid_runtime.evals.trajectory import RunOutput, Trajectory
44
+ from aid_runtime.providers.base import Provider
45
+ from aid_runtime.tools import Tool
46
+
47
+ __all__ = ["AgentEvalRunner", "ApprovalPolicy"]
48
+
49
+
50
+ class ApprovalPolicy(StrEnum):
51
+ """How the harness answers when a run pauses for a person.
52
+
53
+ ``FROM_CASE`` is the default and the only policy that claims to model approval: every
54
+ pause consumes the next decision the case declared. The other two exist for datasets
55
+ whose subject is something else, and they are explicit so a reader is not left
56
+ guessing whether a paused case was approved or merely allowed through.
57
+ """
58
+
59
+ #: Take each decision from ``EvalCase.approvals``; refuse when the case runs out.
60
+ FROM_CASE = "from-case"
61
+ #: Approve every pause. Only for a case that is not about approval.
62
+ APPROVE = "approve"
63
+ #: Reject every pause.
64
+ REJECT = "reject"
65
+
66
+
67
+ #: How many pauses one case may resume through before the runner calls it a loop. The
68
+ #: agent's own ``maxSteps`` bounds the run; this bounds the *harness*, so a case that
69
+ #: keeps supplying decisions to a run that keeps pausing cannot spin forever.
70
+ _DEFAULT_MAX_RESUMES = 8
71
+
72
+
73
+ class AgentEvalRunner:
74
+ """Turns an :class:`~aid_runtime.evals.dataset.EvalCase` into a :class:`RunOutput`.
75
+
76
+ Constructed once per eval and called once per case. The runtime is rebuilt per case
77
+ rather than reused, because the cost ledger, the step counter, and the memory store
78
+ are per-run state: a shared runtime would charge case two for case one's tokens and
79
+ let a later case see an earlier case's thread memory.
80
+ """
81
+
82
+ def __init__(
83
+ self,
84
+ document: Mapping[str, object],
85
+ agent_id: str,
86
+ *,
87
+ providers: Mapping[str, Provider],
88
+ tools: Iterable[Tool] = (),
89
+ approval_policy: ApprovalPolicy | str = ApprovalPolicy.FROM_CASE,
90
+ max_resumes: int = _DEFAULT_MAX_RESUMES,
91
+ ) -> None:
92
+ if not providers:
93
+ raise ConfigurationError(
94
+ "an agent eval needs at least one provider: an agent run is model calls, and "
95
+ "a runner with no provider would report an empty trajectory as a real one"
96
+ )
97
+ if max_resumes < 0:
98
+ raise ConfigurationError("max_resumes cannot be negative")
99
+ declared = _declared_agents(document)
100
+ if agent_id not in declared:
101
+ raise ConfigurationError(
102
+ f"no agent {agent_id!r} in the eval's document; declared agents: {sorted(declared)}"
103
+ )
104
+ self._document = document
105
+ self._agent_id = agent_id
106
+ self._providers = dict(providers)
107
+ self._tools = tuple(tools)
108
+ self._policy = ApprovalPolicy(approval_policy)
109
+ self._max_resumes = max_resumes
110
+ #: Cumulative model spend, which is what ``evaluate_once`` differences to charge
111
+ #: each case. Read from the ledger of the most recent run.
112
+ self._cost_usd = 0.0
113
+ self._last: RunResult | None = None
114
+
115
+ @property
116
+ def agent_id(self) -> str:
117
+ return self._agent_id
118
+
119
+ @property
120
+ def approval_policy(self) -> ApprovalPolicy:
121
+ return self._policy
122
+
123
+ @property
124
+ def cost_usd(self) -> float:
125
+ """Total spend across every case so far, so a caller can difference it."""
126
+ return self._cost_usd
127
+
128
+ @property
129
+ def last_result(self) -> RunResult | None:
130
+ """The most recent run, for a caller that needs more than the trajectory.
131
+
132
+ ``evaluate_once`` only hands a metric the trajectory, so this exists for the
133
+ direct caller -- a walkthrough, a report, or a test -- that wants the status and
134
+ the steps. Metrics do not reach through it.
135
+ """
136
+ return self._last
137
+
138
+ async def __call__(self, case: EvalCase) -> RunOutput:
139
+ runtime = self._runtime()
140
+ before = runtime.gateway.ledger.cost_usd
141
+ try:
142
+ result = await runtime.run(self._agent_id, case.input)
143
+ result, approvals = await self._settle(runtime, case, result)
144
+ finally:
145
+ # Charged even when the run raised: a case stopped by a guardrail was billed,
146
+ # and a cost series that only saw completed cases would under-report exactly
147
+ # when the guardrails fire.
148
+ self._cost_usd += max(runtime.gateway.ledger.cost_usd - before, 0.0)
149
+ self._last = result
150
+ return RunOutput(
151
+ text=result.answer,
152
+ trajectory=Trajectory.from_run(
153
+ result,
154
+ pauses=approvals.pauses,
155
+ decisions=approvals.decisions,
156
+ ignored=approvals.ignored,
157
+ ),
158
+ )
159
+
160
+ def _runtime(self) -> AgentRuntime:
161
+ # A fresh memory store per case, for the same reason as the fresh ledger: ``run``
162
+ # keys thread memory on the agent id when the caller passes no ``memory_key``, so a
163
+ # shared store would hand case two the first case's conversation.
164
+ return AgentRuntime.from_ir(
165
+ self._document,
166
+ providers=self._providers,
167
+ tools=self._tools,
168
+ memory_store=InProcessMemoryStore(),
169
+ )
170
+
171
+ async def _settle(
172
+ self, runtime: AgentRuntime, case: EvalCase, result: RunResult
173
+ ) -> tuple[RunResult, _Approvals]:
174
+ """Resume through every pause the case has decisions for, and record what happened."""
175
+ decisions = iter(case.approvals)
176
+ applied: list[str] = []
177
+ rejections: list[_Rejection] = []
178
+ pauses = 0
179
+ while result.status is RunStatus.PAUSED:
180
+ checkpoint = result.checkpoint
181
+ if checkpoint is None:
182
+ raise EvalError(
183
+ f"case {case.id!r} is paused but its run carries no checkpoint, so it "
184
+ "cannot be resumed; the loop must record one before reporting a pause"
185
+ )
186
+ decision = self._decision(case, decisions)
187
+ pauses += 1
188
+ if pauses > self._max_resumes:
189
+ raise EvalError(
190
+ f"case {case.id!r} paused {self._max_resumes} times and is still asking; "
191
+ "the case is supplying decisions to a run that is not converging, and "
192
+ "resuming it again would only multiply the spend"
193
+ )
194
+ applied.append(decision.value)
195
+ # The calls this pause is asking about. `Checkpoint.calls` is empty when the
196
+ # pause came from a guardrail releasing an answer rather than a tool call, so
197
+ # a rejection there blocks nothing and records no boundary.
198
+ names = frozenset(call.name for call in checkpoint.calls)
199
+ if decision is HumanDecision.REJECT:
200
+ rejections.append(_Rejection(boundary=len(result.steps), names=names))
201
+ else:
202
+ # A later approval of the same calls lifts the earlier rejection, so the
203
+ # only names left to check at the end are the ones nobody ever approved.
204
+ rejections = [
205
+ _Rejection(boundary=rejection.boundary, names=rejection.names - names)
206
+ for rejection in rejections
207
+ ]
208
+ result = await runtime.resume(checkpoint, decision)
209
+ return result, _Approvals(
210
+ pauses=pauses,
211
+ decisions=tuple(applied),
212
+ ignored=_ignored_calls(result, [r for r in rejections if r.names]),
213
+ )
214
+
215
+ def _decision(self, case: EvalCase, decisions: Iterator[str]) -> HumanDecision:
216
+ if self._policy is ApprovalPolicy.APPROVE:
217
+ return HumanDecision.APPROVE
218
+ if self._policy is ApprovalPolicy.REJECT:
219
+ return HumanDecision.REJECT
220
+ for decision in decisions:
221
+ return HumanDecision(decision)
222
+ raise EvalError(
223
+ f"case {case.id!r} paused for approval and declared no decision for it: add "
224
+ "`approvals` to the case (in order, one per pause) to say what the reviewer "
225
+ "answered, or construct the runner with ApprovalPolicy.APPROVE when this eval "
226
+ "is not about approval"
227
+ )
228
+
229
+
230
+ @dataclass(frozen=True)
231
+ class _Approvals:
232
+ """What the harness observed about a case's approvals, for the trajectory to carry."""
233
+
234
+ pauses: int = 0
235
+ decisions: tuple[str, ...] = ()
236
+ ignored: tuple[str, ...] = ()
237
+
238
+
239
+ @dataclass(frozen=True)
240
+ class _Rejection:
241
+ """One rejection, and where in the run's steps it was answered.
242
+
243
+ ``boundary`` is the number of steps recorded when the rejection was given. Steps only
244
+ ever append -- a resume restores the ones the checkpoint holds and continues from
245
+ there -- so the same index slices the final run and yields exactly what happened
246
+ after the answer, which is the only place a call could ignore it.
247
+ """
248
+
249
+ boundary: int
250
+ names: frozenset[str]
251
+
252
+
253
+ def _ignored_calls(result: RunResult, rejections: Sequence[_Rejection]) -> tuple[str, ...]:
254
+ """Names of rejected tools that nonetheless ran after the rejection.
255
+
256
+ A rejection tells the run that a call did not happen. A call that happens anyway is
257
+ the one safety finding this metric reports: everything else it checks is a mismatch
258
+ between what a case scripted and what the run did, but this one is a bound the spec
259
+ promised a person that the machinery then crossed.
260
+ """
261
+ found: set[str] = set()
262
+ for rejection in rejections:
263
+ for step in result.steps[rejection.boundary :]:
264
+ found.update(name for name in step.tool_names if name in rejection.names)
265
+ return tuple(sorted(found))
266
+
267
+
268
+ def _declared_agents(document: Mapping[str, object]) -> set[str]:
269
+ """The ids the document declares, read structurally so a typo fails before case one.
270
+
271
+ The full IR parser would answer this too, but it wants the tools registered, and a
272
+ caller that mistyped the agent id should hear about it at construction -- not after a
273
+ fifty-case dataset has charged the budget.
274
+ """
275
+ entries = document.get("agents")
276
+ if not isinstance(entries, list):
277
+ return set()
278
+ return {
279
+ entry["id"]
280
+ for entry in entries
281
+ if isinstance(entry, Mapping) and isinstance(entry.get("id"), str)
282
+ }
@@ -27,6 +27,28 @@ class EvalCase(BaseModel):
27
27
  expected: str | None = None
28
28
  tags: tuple[str, ...] = ()
29
29
  metadata: dict[str, str] = Field(default_factory=dict)
30
+ #: What a person answers, in order, each time the run pauses for approval. An
31
+ #: agent case that pauses and supplies no answer here is refused rather than
32
+ #: auto-approved: the harness must not stand in for the reviewer it is modelling.
33
+ approvals: tuple[str, ...] = ()
34
+
35
+ @field_validator("approvals", mode="before")
36
+ @classmethod
37
+ def _coerce_approvals(cls, value: object) -> object:
38
+ if isinstance(value, str):
39
+ return (value,)
40
+ return value
41
+
42
+ @field_validator("approvals")
43
+ @classmethod
44
+ def _check_approvals(cls, value: tuple[str, ...]) -> tuple[str, ...]:
45
+ allowed = {"approve", "reject"}
46
+ for decision in value:
47
+ if decision not in allowed:
48
+ raise ValueError(
49
+ f"a case's approvals may only be 'approve' or 'reject', not {decision!r}"
50
+ )
51
+ return value
30
52
 
31
53
 
32
54
  class Dataset(BaseModel):
@@ -73,5 +95,18 @@ class Dataset(BaseModel):
73
95
  return cls.from_json(Path(path).read_text(encoding="utf-8"))
74
96
 
75
97
  def to_json(self) -> str:
76
- """Canonical JSON: sorted keys, so a dataset diff is reviewable."""
77
- return json.dumps(self.model_dump(mode="json"), indent=2, sort_keys=True) + "\n"
98
+ """Canonical JSON: sorted keys, so a dataset diff is reviewable.
99
+
100
+ ``approvals`` is omitted when a case declared none, so adding approval-aware
101
+ trajectory evals did not rewrite every dataset already in a repository. A case
102
+ that does declare decisions writes them, because a reader has to be able to see
103
+ what the reviewer answered.
104
+ """
105
+ return json.dumps(self._dumped(), indent=2, sort_keys=True) + "\n"
106
+
107
+ def _dumped(self) -> dict[str, object]:
108
+ payload = self.model_dump(mode="json")
109
+ for case in payload.get("cases", ()):
110
+ if not case.get("approvals"):
111
+ case.pop("approvals", None)
112
+ return payload
@@ -25,10 +25,12 @@ from aid_runtime.evals.trajectory import Trajectory
25
25
  from aid_runtime.structured import run_structured
26
26
 
27
27
  __all__ = [
28
+ "ApprovalRespected",
28
29
  "AssertMetric",
29
30
  "CostCeiling",
30
31
  "DecisionScore",
31
32
  "ExactMatch",
33
+ "ForbiddenTool",
32
34
  "JsonSchemaValid",
33
35
  "JudgeVerdict",
34
36
  "LatencyCeiling",
@@ -37,6 +39,7 @@ __all__ = [
37
39
  "MetricResult",
38
40
  "NormalizedContains",
39
41
  "RunContext",
42
+ "StepCount",
40
43
  "ToolTrace",
41
44
  "default_metrics",
42
45
  "metric_names",
@@ -588,6 +591,159 @@ def _tool_list(names: Sequence[str]) -> str:
588
591
  return ", ".join(names) if names else "no tools"
589
592
 
590
593
 
594
+ class StepCount(_Ceiling):
595
+ """Whether a run finished inside a declared ceiling on model calls.
596
+
597
+ The agent's own ``maxSteps`` already bounds a run, so this is not a second safety
598
+ net -- it is the eval asserting the bound held for *this* case. A case expected to
599
+ take three steps that takes nine is a run that looped, and the answer it eventually
600
+ produced is not the run the case described.
601
+
602
+ Refuses a trajectory that reports no steps rather than passing one: an agent run is
603
+ model calls, so a count of zero means nobody counted, and a ceiling over an
604
+ uncounted run would pass every case by accident.
605
+ """
606
+
607
+ _quantity = "took"
608
+
609
+ def __init__(self, *, max_steps: int, name: str = "step-count") -> None:
610
+ if max_steps <= 0:
611
+ raise ConfigurationError(f"a step ceiling must be above zero, got {max_steps}")
612
+ super().__init__(name=name)
613
+ self._max = max_steps
614
+
615
+ def _limit(self) -> float:
616
+ return float(self._max)
617
+
618
+ def _measure(self, case: EvalCase, context: RunContext | None) -> float:
619
+ if context is None or context.trajectory is None:
620
+ raise EvalError(
621
+ f"case {case.id!r} carries a step ceiling, but its runner reported no "
622
+ "trajectory, so there is no step count to compare against it"
623
+ )
624
+ if context.trajectory.steps == 0:
625
+ raise EvalError(
626
+ f"case {case.id!r} carries a step ceiling, but its trajectory records no "
627
+ "steps; an agent run is at least one model call, so a count of zero means "
628
+ "the count was never taken and the ceiling would pass over it"
629
+ )
630
+ return float(context.trajectory.steps)
631
+
632
+ def _format(self, value: float) -> str:
633
+ return f"{value:.0f} steps"
634
+
635
+
636
+ class ForbiddenTool:
637
+ """Whether a run reached for a tool it was told not to use.
638
+
639
+ The inverse of ``ToolTrace``: that one asks whether the run did a thing, this asks
640
+ whether it crossed a line. A run that calls no tools at all passes, because "did not
641
+ use the forbidden tool" is true of it -- but a runner that reports no trajectory is
642
+ refused, since silence about tool calls is not evidence that none were made.
643
+ """
644
+
645
+ def __init__(self, *, forbid: Sequence[str], name: str = "forbidden-tool") -> None:
646
+ if not forbid:
647
+ raise ConfigurationError("a forbidden-tool metric must name at least one tool")
648
+ self._name = name
649
+ self._forbid = tuple(forbid)
650
+
651
+ @property
652
+ def name(self) -> str:
653
+ return self._name
654
+
655
+ @property
656
+ def deterministic(self) -> bool:
657
+ return True
658
+
659
+ async def score(
660
+ self, case: EvalCase, prediction: str, *, context: RunContext | None = None
661
+ ) -> MetricResult:
662
+ if context is None or context.trajectory is None:
663
+ raise EvalError(
664
+ f"case {case.id!r} carries a forbidden-tool metric, but its runner reported "
665
+ "no tool calls, so there is nothing to clear the run of"
666
+ )
667
+ hit = tuple(sorted(set(self._forbid).intersection(context.trajectory.calls)))
668
+ ok = not hit
669
+ return MetricResult(
670
+ metric=self.name,
671
+ score=1.0 if ok else 0.0,
672
+ passed=ok,
673
+ detail=(
674
+ f"called none of {_tool_list(self._forbid)}"
675
+ if ok
676
+ else f"called forbidden {_tool_list(hit)}"
677
+ ),
678
+ )
679
+
680
+
681
+ class ApprovalRespected:
682
+ """Whether a run paused when a person had to decide, and obeyed the answer.
683
+
684
+ Three findings, and a case passes only when none of them fires. They are separate
685
+ because they mean different things to whoever reads the failure:
686
+
687
+ ``pause-missed`` is a case that scripted a decision the run never asked for, so the
688
+ decision was never tested. ``pause-unexpected`` is a pause the case supplied no
689
+ decision for -- the run stopped where the dataset said nothing would. Both are
690
+ mismatches between the dataset and the machinery.
691
+
692
+ ``decision-ignored`` is the safety finding: a call ran after a reviewer rejected it.
693
+ It fails the case even when the answer matches what the case expected, because a
694
+ correct answer reached by crossing an approval is not a correct answer.
695
+
696
+ The counts come from the runner, since no metric can recover them from an answer.
697
+ A trajectory that carries none of them is refused when the case scripted a decision;
698
+ an unrecorded approval is not a respected one.
699
+ """
700
+
701
+ def __init__(self, *, name: str = "approval-respected") -> None:
702
+ self._name = name
703
+
704
+ @property
705
+ def name(self) -> str:
706
+ return self._name
707
+
708
+ @property
709
+ def deterministic(self) -> bool:
710
+ return True
711
+
712
+ async def score(
713
+ self, case: EvalCase, prediction: str, *, context: RunContext | None = None
714
+ ) -> MetricResult:
715
+ if context is None or context.trajectory is None:
716
+ raise EvalError(
717
+ f"case {case.id!r} carries an approval-respected metric, but its runner "
718
+ "reported no trajectory, so there is no approval record to judge"
719
+ )
720
+ trajectory = context.trajectory
721
+ findings: list[str] = []
722
+ if case.approvals and trajectory.pauses == 0:
723
+ findings.append("pause-missed: the case supplies a decision the run never asked for")
724
+ if not case.approvals and trajectory.pauses > 0:
725
+ findings.append(
726
+ f"pause-unexpected: the run paused {trajectory.pauses} time(s) and the case "
727
+ "supplies no decision"
728
+ )
729
+ if trajectory.ignored:
730
+ findings.append(
731
+ f"decision-ignored: {_tool_list(trajectory.ignored)} ran after a rejection"
732
+ )
733
+ ok = not findings
734
+ return MetricResult(
735
+ metric=self.name,
736
+ score=1.0 if ok else 0.0,
737
+ passed=ok,
738
+ detail=(
739
+ f"respected {len(trajectory.decisions)} decision(s) across "
740
+ f"{trajectory.pauses} pause(s)"
741
+ if ok
742
+ else "; ".join(findings)
743
+ ),
744
+ )
745
+
746
+
591
747
  def default_metrics() -> tuple[Metric, ...]:
592
748
  """The deterministic gate metrics: everything that needs no model call."""
593
749
  return (ExactMatch(), NormalizedContains(), JsonSchemaValid())