aid-runtime-python 0.1.157__tar.gz → 0.1.158__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.
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/PKG-INFO +1 -1
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/pyproject.toml +1 -1
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/__init__.py +15 -1
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/evals/__init__.py +3 -0
- aid_runtime_python-0.1.158/src/aid_runtime/evals/agent_runner.py +213 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/evals/dataset.py +37 -2
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/providers/__init__.py +15 -1
- aid_runtime_python-0.1.158/src/aid_runtime/providers/recorded.py +342 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime_python.egg-info/PKG-INFO +1 -1
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime_python.egg-info/SOURCES.txt +4 -0
- aid_runtime_python-0.1.158/tests/test_agent_eval_runner.py +407 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_dataset.py +13 -0
- aid_runtime_python-0.1.158/tests/test_recorded_provider.py +246 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/README.md +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/setup.cfg +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/agents/__init__.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/agents/chat_model.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/agents/deep_agents.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/agents/engine.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/agents/guardrails.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/agents/ir.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/agents/loop.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/agents/managed.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/agents/memory.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/agents/policy.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/agents/state.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/cache.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/concurrency.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/control.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/cost.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/decisions.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/errors.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/evals/gate.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/evals/metrics.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/evals/predicate.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/evals/runner.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/evals/trajectory.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/gateway.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/local_trace.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/metrics.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/pipeline.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/prompts.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/providers/anthropic.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/providers/base.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/providers/bedrock.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/providers/fake.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/providers/gemini.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/providers/gemini_wire.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/providers/http.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/providers/vertex.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/py.typed +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/retrieval/__init__.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/retrieval/chunking.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/retrieval/citations.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/retrieval/connectors.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/retrieval/embedding.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/retrieval/filters.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/retrieval/gate.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/retrieval/hybrid.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/retrieval/knowledge_base.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/retrieval/metrics.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/retrieval/pgvector.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/retrieval/rerank.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/retrieval/retriever.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/retrieval/stores.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/retrieval/types.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/steps.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/structured.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/telemetry.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/tools.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/tracing.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/types.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime_python.egg-info/dependency_links.txt +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime_python.egg-info/requires.txt +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime_python.egg-info/top_level.txt +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_agents_budget.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_agents_deep_agents.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_agents_hitl.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_agents_loop.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_agents_memory.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_anthropic_provider.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_bedrock_provider.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_cache.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_concurrency.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_control.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_cost.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_decisions.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_evals.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_evals_assert_gate.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_evals_budgets.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_evals_decision.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_evals_gate.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_evals_predicate.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_evals_trajectory.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_gateway.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_gemini_provider.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_guardrails.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_guardrails_managed.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_guardrails_model_armor.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_http_provider.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_local_trace.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_metrics.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_package.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_pipeline.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_prompts.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_retrieval_chunking.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_retrieval_citations.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_retrieval_connectors.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_retrieval_embedding.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_retrieval_filters.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_retrieval_gate.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_retrieval_hybrid.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_retrieval_knowledge_base.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_retrieval_metrics.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_retrieval_rerank.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_retrieval_stores.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_retrieval_types.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_steps.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_streaming.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_structured.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_telemetry.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_tool_permissions.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_tools.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_tracing.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/tests/test_types.py +0 -0
- {aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/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.
|
|
3
|
+
Version: 0.1.158
|
|
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.
|
|
7
|
+
version = "0.1.158"
|
|
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,8 @@ from aid_runtime.errors import (
|
|
|
114
114
|
UnknownModelAliasError,
|
|
115
115
|
)
|
|
116
116
|
from aid_runtime.evals import (
|
|
117
|
+
AgentEvalRunner,
|
|
118
|
+
ApprovalPolicy,
|
|
117
119
|
BaselineGate,
|
|
118
120
|
CaseOutcome,
|
|
119
121
|
CostCeiling,
|
|
@@ -184,7 +186,12 @@ from aid_runtime.providers import (
|
|
|
184
186
|
GeminiProvider,
|
|
185
187
|
OpenAICompatibleProvider,
|
|
186
188
|
Provider,
|
|
189
|
+
RecordedProvider,
|
|
190
|
+
RecordingProvider,
|
|
191
|
+
ReplayDivergenceError,
|
|
187
192
|
ScriptedTurn,
|
|
193
|
+
Transcript,
|
|
194
|
+
TranscriptEntry,
|
|
188
195
|
VertexProvider,
|
|
189
196
|
default_bedrock_base_url,
|
|
190
197
|
default_vertex_base_url,
|
|
@@ -337,7 +344,7 @@ from aid_runtime.types import (
|
|
|
337
344
|
)
|
|
338
345
|
|
|
339
346
|
#: Kept in sync with ``pyproject.toml`` by a test, so the two cannot drift.
|
|
340
|
-
__version__ = "0.1.
|
|
347
|
+
__version__ = "0.1.158"
|
|
341
348
|
|
|
342
349
|
__all__ = [
|
|
343
350
|
"AGENT_LABEL",
|
|
@@ -378,11 +385,13 @@ __all__ = [
|
|
|
378
385
|
"AgentBudgetDegradedError",
|
|
379
386
|
"AgentCheckpoint",
|
|
380
387
|
"AgentDefinition",
|
|
388
|
+
"AgentEvalRunner",
|
|
381
389
|
"AgentHandoffUnsupportedError",
|
|
382
390
|
"AgentRuntime",
|
|
383
391
|
"AgentTransferCycleError",
|
|
384
392
|
"AidRuntimeError",
|
|
385
393
|
"AnthropicProvider",
|
|
394
|
+
"ApprovalPolicy",
|
|
386
395
|
"BaselineGate",
|
|
387
396
|
"BedrockProvider",
|
|
388
397
|
"Budget",
|
|
@@ -496,10 +505,13 @@ __all__ = [
|
|
|
496
505
|
"ProviderResponseError",
|
|
497
506
|
"RankedId",
|
|
498
507
|
"RecallAtK",
|
|
508
|
+
"RecordedProvider",
|
|
509
|
+
"RecordingProvider",
|
|
499
510
|
"RecursiveChunker",
|
|
500
511
|
"RefreshMode",
|
|
501
512
|
"RefreshSpec",
|
|
502
513
|
"RenderedPrompt",
|
|
514
|
+
"ReplayDivergenceError",
|
|
503
515
|
"RerankSpec",
|
|
504
516
|
"Reranker",
|
|
505
517
|
"RetrievalCase",
|
|
@@ -553,6 +565,8 @@ __all__ = [
|
|
|
553
565
|
"ToolSpec",
|
|
554
566
|
"ToolTrace",
|
|
555
567
|
"Trajectory",
|
|
568
|
+
"Transcript",
|
|
569
|
+
"TranscriptEntry",
|
|
556
570
|
"UnknownModelAliasError",
|
|
557
571
|
"VectorStore",
|
|
558
572
|
"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,
|
|
@@ -45,6 +46,8 @@ from aid_runtime.evals.runner import (
|
|
|
45
46
|
from aid_runtime.evals.trajectory import RunOutput, Trajectory
|
|
46
47
|
|
|
47
48
|
__all__ = [
|
|
49
|
+
"AgentEvalRunner",
|
|
50
|
+
"ApprovalPolicy",
|
|
48
51
|
"AssertMetric",
|
|
49
52
|
"BaselineGate",
|
|
50
53
|
"CaseOutcome",
|
|
@@ -0,0 +1,213 @@
|
|
|
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
|
|
35
|
+
from enum import StrEnum
|
|
36
|
+
|
|
37
|
+
from aid_runtime.agents.loop import AgentRuntime
|
|
38
|
+
from aid_runtime.agents.memory import InProcessMemoryStore
|
|
39
|
+
from aid_runtime.agents.state import HumanDecision, RunResult, RunStatus
|
|
40
|
+
from aid_runtime.errors import ConfigurationError, EvalError
|
|
41
|
+
from aid_runtime.evals.dataset import EvalCase
|
|
42
|
+
from aid_runtime.evals.trajectory import RunOutput, Trajectory
|
|
43
|
+
from aid_runtime.providers.base import Provider
|
|
44
|
+
from aid_runtime.tools import Tool
|
|
45
|
+
|
|
46
|
+
__all__ = ["AgentEvalRunner", "ApprovalPolicy"]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class ApprovalPolicy(StrEnum):
|
|
50
|
+
"""How the harness answers when a run pauses for a person.
|
|
51
|
+
|
|
52
|
+
``FROM_CASE`` is the default and the only policy that claims to model approval: every
|
|
53
|
+
pause consumes the next decision the case declared. The other two exist for datasets
|
|
54
|
+
whose subject is something else, and they are explicit so a reader is not left
|
|
55
|
+
guessing whether a paused case was approved or merely allowed through.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
#: Take each decision from ``EvalCase.approvals``; refuse when the case runs out.
|
|
59
|
+
FROM_CASE = "from-case"
|
|
60
|
+
#: Approve every pause. Only for a case that is not about approval.
|
|
61
|
+
APPROVE = "approve"
|
|
62
|
+
#: Reject every pause.
|
|
63
|
+
REJECT = "reject"
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
#: How many pauses one case may resume through before the runner calls it a loop. The
|
|
67
|
+
#: agent's own ``maxSteps`` bounds the run; this bounds the *harness*, so a case that
|
|
68
|
+
#: keeps supplying decisions to a run that keeps pausing cannot spin forever.
|
|
69
|
+
_DEFAULT_MAX_RESUMES = 8
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class AgentEvalRunner:
|
|
73
|
+
"""Turns an :class:`~aid_runtime.evals.dataset.EvalCase` into a :class:`RunOutput`.
|
|
74
|
+
|
|
75
|
+
Constructed once per eval and called once per case. The runtime is rebuilt per case
|
|
76
|
+
rather than reused, because the cost ledger, the step counter, and the memory store
|
|
77
|
+
are per-run state: a shared runtime would charge case two for case one's tokens and
|
|
78
|
+
let a later case see an earlier case's thread memory.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
def __init__(
|
|
82
|
+
self,
|
|
83
|
+
document: Mapping[str, object],
|
|
84
|
+
agent_id: str,
|
|
85
|
+
*,
|
|
86
|
+
providers: Mapping[str, Provider],
|
|
87
|
+
tools: Iterable[Tool] = (),
|
|
88
|
+
approval_policy: ApprovalPolicy | str = ApprovalPolicy.FROM_CASE,
|
|
89
|
+
max_resumes: int = _DEFAULT_MAX_RESUMES,
|
|
90
|
+
) -> None:
|
|
91
|
+
if not providers:
|
|
92
|
+
raise ConfigurationError(
|
|
93
|
+
"an agent eval needs at least one provider: an agent run is model calls, and "
|
|
94
|
+
"a runner with no provider would report an empty trajectory as a real one"
|
|
95
|
+
)
|
|
96
|
+
if max_resumes < 0:
|
|
97
|
+
raise ConfigurationError("max_resumes cannot be negative")
|
|
98
|
+
declared = _declared_agents(document)
|
|
99
|
+
if agent_id not in declared:
|
|
100
|
+
raise ConfigurationError(
|
|
101
|
+
f"no agent {agent_id!r} in the eval's document; declared agents: {sorted(declared)}"
|
|
102
|
+
)
|
|
103
|
+
self._document = document
|
|
104
|
+
self._agent_id = agent_id
|
|
105
|
+
self._providers = dict(providers)
|
|
106
|
+
self._tools = tuple(tools)
|
|
107
|
+
self._policy = ApprovalPolicy(approval_policy)
|
|
108
|
+
self._max_resumes = max_resumes
|
|
109
|
+
#: Cumulative model spend, which is what ``evaluate_once`` differences to charge
|
|
110
|
+
#: each case. Read from the ledger of the most recent run.
|
|
111
|
+
self._cost_usd = 0.0
|
|
112
|
+
self._last: RunResult | None = None
|
|
113
|
+
|
|
114
|
+
@property
|
|
115
|
+
def agent_id(self) -> str:
|
|
116
|
+
return self._agent_id
|
|
117
|
+
|
|
118
|
+
@property
|
|
119
|
+
def approval_policy(self) -> ApprovalPolicy:
|
|
120
|
+
return self._policy
|
|
121
|
+
|
|
122
|
+
@property
|
|
123
|
+
def cost_usd(self) -> float:
|
|
124
|
+
"""Total spend across every case so far, so a caller can difference it."""
|
|
125
|
+
return self._cost_usd
|
|
126
|
+
|
|
127
|
+
@property
|
|
128
|
+
def last_result(self) -> RunResult | None:
|
|
129
|
+
"""The most recent run, for a caller that needs more than the trajectory.
|
|
130
|
+
|
|
131
|
+
``evaluate_once`` only hands a metric the trajectory, so this exists for the
|
|
132
|
+
direct caller -- a walkthrough, a report, or a test -- that wants the status and
|
|
133
|
+
the steps. Metrics do not reach through it.
|
|
134
|
+
"""
|
|
135
|
+
return self._last
|
|
136
|
+
|
|
137
|
+
async def __call__(self, case: EvalCase) -> RunOutput:
|
|
138
|
+
runtime = self._runtime()
|
|
139
|
+
before = runtime.gateway.ledger.cost_usd
|
|
140
|
+
try:
|
|
141
|
+
result = await runtime.run(self._agent_id, case.input)
|
|
142
|
+
result = await self._settle(runtime, case, result)
|
|
143
|
+
finally:
|
|
144
|
+
# Charged even when the run raised: a case stopped by a guardrail was billed,
|
|
145
|
+
# and a cost series that only saw completed cases would under-report exactly
|
|
146
|
+
# when the guardrails fire.
|
|
147
|
+
self._cost_usd += max(runtime.gateway.ledger.cost_usd - before, 0.0)
|
|
148
|
+
self._last = result
|
|
149
|
+
return RunOutput(text=result.answer, trajectory=Trajectory.from_run(result))
|
|
150
|
+
|
|
151
|
+
def _runtime(self) -> AgentRuntime:
|
|
152
|
+
# A fresh memory store per case, for the same reason as the fresh ledger: ``run``
|
|
153
|
+
# keys thread memory on the agent id when the caller passes no ``memory_key``, so a
|
|
154
|
+
# shared store would hand case two the first case's conversation.
|
|
155
|
+
return AgentRuntime.from_ir(
|
|
156
|
+
self._document,
|
|
157
|
+
providers=self._providers,
|
|
158
|
+
tools=self._tools,
|
|
159
|
+
memory_store=InProcessMemoryStore(),
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
async def _settle(self, runtime: AgentRuntime, case: EvalCase, result: RunResult) -> RunResult:
|
|
163
|
+
"""Resume through every pause the case has decisions for."""
|
|
164
|
+
decisions = iter(case.approvals)
|
|
165
|
+
resumes = 0
|
|
166
|
+
while result.status is RunStatus.PAUSED:
|
|
167
|
+
checkpoint = result.checkpoint
|
|
168
|
+
if checkpoint is None:
|
|
169
|
+
raise EvalError(
|
|
170
|
+
f"case {case.id!r} is paused but its run carries no checkpoint, so it "
|
|
171
|
+
"cannot be resumed; the loop must record one before reporting a pause"
|
|
172
|
+
)
|
|
173
|
+
decision = self._decision(case, decisions)
|
|
174
|
+
resumes += 1
|
|
175
|
+
if resumes > self._max_resumes:
|
|
176
|
+
raise EvalError(
|
|
177
|
+
f"case {case.id!r} paused {self._max_resumes} times and is still asking; "
|
|
178
|
+
"the case is supplying decisions to a run that is not converging, and "
|
|
179
|
+
"resuming it again would only multiply the spend"
|
|
180
|
+
)
|
|
181
|
+
result = await runtime.resume(checkpoint, decision)
|
|
182
|
+
return result
|
|
183
|
+
|
|
184
|
+
def _decision(self, case: EvalCase, decisions: Iterator[str]) -> HumanDecision:
|
|
185
|
+
if self._policy is ApprovalPolicy.APPROVE:
|
|
186
|
+
return HumanDecision.APPROVE
|
|
187
|
+
if self._policy is ApprovalPolicy.REJECT:
|
|
188
|
+
return HumanDecision.REJECT
|
|
189
|
+
for decision in decisions:
|
|
190
|
+
return HumanDecision(decision)
|
|
191
|
+
raise EvalError(
|
|
192
|
+
f"case {case.id!r} paused for approval and declared no decision for it: add "
|
|
193
|
+
"`approvals` to the case (in order, one per pause) to say what the reviewer "
|
|
194
|
+
"answered, or construct the runner with ApprovalPolicy.APPROVE when this eval "
|
|
195
|
+
"is not about approval"
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _declared_agents(document: Mapping[str, object]) -> set[str]:
|
|
200
|
+
"""The ids the document declares, read structurally so a typo fails before case one.
|
|
201
|
+
|
|
202
|
+
The full IR parser would answer this too, but it wants the tools registered, and a
|
|
203
|
+
caller that mistyped the agent id should hear about it at construction -- not after a
|
|
204
|
+
fifty-case dataset has charged the budget.
|
|
205
|
+
"""
|
|
206
|
+
entries = document.get("agents")
|
|
207
|
+
if not isinstance(entries, list):
|
|
208
|
+
return set()
|
|
209
|
+
return {
|
|
210
|
+
entry["id"]
|
|
211
|
+
for entry in entries
|
|
212
|
+
if isinstance(entry, Mapping) and isinstance(entry.get("id"), str)
|
|
213
|
+
}
|
|
@@ -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
|
-
|
|
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
|
{aid_runtime_python-0.1.157 → aid_runtime_python-0.1.158}/src/aid_runtime/providers/__init__.py
RENAMED
|
@@ -6,7 +6,9 @@ Converse API, and Gemini's ``generateContent`` -- which the Vertex AI adapter
|
|
|
6
6
|
serves over an OAuth2 bearer token and the Gemini API adapter serves with one API
|
|
7
7
|
key. Bedrock is signed with SigV4 and Vertex is OAuth2-bearer, which is why
|
|
8
8
|
neither can be an OpenAI-compatible base URL. A sixth, deterministic fake serves
|
|
9
|
-
tests and the eval
|
|
9
|
+
tests and builds the scripted side of an eval case. A seventh, ``recorded``,
|
|
10
|
+
replays a committed transcript so an agent eval can be gated without calling a
|
|
11
|
+
vendor; it has no fall-through to a live model, by design.
|
|
10
12
|
"""
|
|
11
13
|
|
|
12
14
|
from __future__ import annotations
|
|
@@ -30,6 +32,13 @@ from aid_runtime.providers.gemini import (
|
|
|
30
32
|
GeminiProvider,
|
|
31
33
|
)
|
|
32
34
|
from aid_runtime.providers.http import DEFAULT_BASE_URL, OpenAICompatibleProvider
|
|
35
|
+
from aid_runtime.providers.recorded import (
|
|
36
|
+
RecordedProvider,
|
|
37
|
+
RecordingProvider,
|
|
38
|
+
ReplayDivergenceError,
|
|
39
|
+
Transcript,
|
|
40
|
+
TranscriptEntry,
|
|
41
|
+
)
|
|
33
42
|
from aid_runtime.providers.vertex import (
|
|
34
43
|
DEFAULT_VERTEX_LOCATION,
|
|
35
44
|
METADATA_TOKEN_URL,
|
|
@@ -54,7 +63,12 @@ __all__ = [
|
|
|
54
63
|
"GeminiProvider",
|
|
55
64
|
"OpenAICompatibleProvider",
|
|
56
65
|
"Provider",
|
|
66
|
+
"RecordedProvider",
|
|
67
|
+
"RecordingProvider",
|
|
68
|
+
"ReplayDivergenceError",
|
|
57
69
|
"ScriptedTurn",
|
|
70
|
+
"Transcript",
|
|
71
|
+
"TranscriptEntry",
|
|
58
72
|
"VertexProvider",
|
|
59
73
|
"default_bedrock_base_url",
|
|
60
74
|
"default_vertex_base_url",
|