aid-runtime-python 0.1.151__tar.gz → 0.1.153__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.151 → aid_runtime_python-0.1.153}/PKG-INFO +1 -1
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/pyproject.toml +1 -1
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/__init__.py +27 -1
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/agents/loop.py +42 -13
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/evals/__init__.py +11 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/evals/metrics.py +233 -7
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/evals/runner.py +94 -10
- aid_runtime_python-0.1.153/src/aid_runtime/evals/trajectory.py +69 -0
- aid_runtime_python-0.1.153/src/aid_runtime/metrics.py +133 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/retrieval/gate.py +15 -1
- aid_runtime_python-0.1.153/src/aid_runtime/telemetry.py +338 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime_python.egg-info/PKG-INFO +1 -1
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime_python.egg-info/SOURCES.txt +5 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_agents_budget.py +58 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_evals.py +29 -0
- aid_runtime_python-0.1.153/tests/test_evals_budgets.py +138 -0
- aid_runtime_python-0.1.153/tests/test_evals_trajectory.py +192 -0
- aid_runtime_python-0.1.153/tests/test_metrics.py +127 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_retrieval_gate.py +52 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_telemetry.py +189 -1
- aid_runtime_python-0.1.151/src/aid_runtime/telemetry.py +0 -184
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/README.md +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/setup.cfg +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/agents/__init__.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/agents/chat_model.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/agents/deep_agents.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/agents/engine.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/agents/guardrails.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/agents/ir.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/agents/managed.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/agents/memory.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/agents/policy.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/agents/state.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/cache.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/concurrency.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/control.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/cost.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/decisions.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/errors.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/evals/dataset.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/evals/gate.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/evals/predicate.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/gateway.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/local_trace.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/pipeline.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/prompts.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/providers/__init__.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/providers/anthropic.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/providers/base.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/providers/bedrock.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/providers/fake.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/providers/gemini.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/providers/gemini_wire.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/providers/http.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/providers/vertex.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/py.typed +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/retrieval/__init__.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/retrieval/chunking.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/retrieval/citations.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/retrieval/connectors.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/retrieval/embedding.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/retrieval/filters.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/retrieval/hybrid.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/retrieval/knowledge_base.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/retrieval/metrics.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/retrieval/pgvector.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/retrieval/rerank.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/retrieval/retriever.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/retrieval/stores.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/retrieval/types.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/steps.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/structured.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/tools.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/tracing.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime/types.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime_python.egg-info/dependency_links.txt +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime_python.egg-info/requires.txt +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/src/aid_runtime_python.egg-info/top_level.txt +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_agents_deep_agents.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_agents_hitl.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_agents_loop.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_agents_memory.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_anthropic_provider.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_bedrock_provider.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_cache.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_concurrency.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_control.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_cost.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_dataset.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_decisions.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_evals_assert_gate.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_evals_decision.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_evals_gate.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_evals_predicate.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_gateway.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_gemini_provider.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_guardrails.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_guardrails_managed.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_guardrails_model_armor.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_http_provider.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_local_trace.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_package.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_pipeline.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_prompts.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_retrieval_chunking.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_retrieval_citations.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_retrieval_connectors.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_retrieval_embedding.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_retrieval_filters.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_retrieval_hybrid.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_retrieval_knowledge_base.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_retrieval_metrics.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_retrieval_rerank.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_retrieval_stores.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_retrieval_types.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_steps.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_streaming.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_structured.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_tool_permissions.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_tools.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_tracing.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/tests/test_types.py +0 -0
- {aid_runtime_python-0.1.151 → aid_runtime_python-0.1.153}/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.153
|
|
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.153"
|
|
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"
|
|
@@ -116,6 +116,7 @@ from aid_runtime.errors import (
|
|
|
116
116
|
from aid_runtime.evals import (
|
|
117
117
|
BaselineGate,
|
|
118
118
|
CaseOutcome,
|
|
119
|
+
CostCeiling,
|
|
119
120
|
Dataset,
|
|
120
121
|
DatasetRun,
|
|
121
122
|
EvalBaseline,
|
|
@@ -126,6 +127,7 @@ from aid_runtime.evals import (
|
|
|
126
127
|
GatewayRunner,
|
|
127
128
|
JsonSchemaValid,
|
|
128
129
|
JudgeVerdict,
|
|
130
|
+
LatencyCeiling,
|
|
129
131
|
LlmJudge,
|
|
130
132
|
Metric,
|
|
131
133
|
MetricBaseline,
|
|
@@ -133,8 +135,12 @@ from aid_runtime.evals import (
|
|
|
133
135
|
MetricResult,
|
|
134
136
|
MetricRun,
|
|
135
137
|
NormalizedContains,
|
|
138
|
+
RunContext,
|
|
136
139
|
Runner,
|
|
140
|
+
RunOutput,
|
|
137
141
|
Threshold,
|
|
142
|
+
ToolTrace,
|
|
143
|
+
Trajectory,
|
|
138
144
|
default_metrics,
|
|
139
145
|
evaluate_once,
|
|
140
146
|
gate_from_config,
|
|
@@ -146,6 +152,13 @@ from aid_runtime.evals import (
|
|
|
146
152
|
)
|
|
147
153
|
from aid_runtime.gateway import ModelGateway, estimate_usage
|
|
148
154
|
from aid_runtime.local_trace import TRACE_DIR_ENV, local_trace_enabled
|
|
155
|
+
from aid_runtime.metrics import (
|
|
156
|
+
AGENT_LABEL,
|
|
157
|
+
EVAL_LABEL,
|
|
158
|
+
METRIC_NAMES,
|
|
159
|
+
record_agent_run,
|
|
160
|
+
record_eval_case,
|
|
161
|
+
)
|
|
149
162
|
from aid_runtime.pipeline import (
|
|
150
163
|
STEPS_KEY,
|
|
151
164
|
Pipeline,
|
|
@@ -287,6 +300,7 @@ from aid_runtime.telemetry import (
|
|
|
287
300
|
ExportReason,
|
|
288
301
|
ExportStatus,
|
|
289
302
|
configure_export,
|
|
303
|
+
configure_metrics,
|
|
290
304
|
)
|
|
291
305
|
from aid_runtime.tools import Tool, ToolExecutor
|
|
292
306
|
from aid_runtime.tracing import (
|
|
@@ -323,9 +337,10 @@ from aid_runtime.types import (
|
|
|
323
337
|
)
|
|
324
338
|
|
|
325
339
|
#: Kept in sync with ``pyproject.toml`` by a test, so the two cannot drift.
|
|
326
|
-
__version__ = "0.1.
|
|
340
|
+
__version__ = "0.1.153"
|
|
327
341
|
|
|
328
342
|
__all__ = [
|
|
343
|
+
"AGENT_LABEL",
|
|
329
344
|
"ANTHROPIC_VERSION",
|
|
330
345
|
"ATTRIBUTES",
|
|
331
346
|
"BEDROCK_SERVICE",
|
|
@@ -339,6 +354,7 @@ __all__ = [
|
|
|
339
354
|
"DEFAULT_VERTEX_LOCATION",
|
|
340
355
|
"DEPTH_KEY",
|
|
341
356
|
"EMITTED_KEY",
|
|
357
|
+
"EVAL_LABEL",
|
|
342
358
|
"EXPORT_KINDS",
|
|
343
359
|
"GEMINI_API_KEY_ENV",
|
|
344
360
|
"GEN_AI_OPERATION_CHAT",
|
|
@@ -349,6 +365,7 @@ __all__ = [
|
|
|
349
365
|
"LIMITER_KEY",
|
|
350
366
|
"MAX_STEP_DEPTH",
|
|
351
367
|
"METADATA_TOKEN_URL",
|
|
368
|
+
"METRIC_NAMES",
|
|
352
369
|
"OTLP_EXTRA",
|
|
353
370
|
"PRINCIPAL_KEY",
|
|
354
371
|
"REDUCED_KEY",
|
|
@@ -386,6 +403,7 @@ __all__ = [
|
|
|
386
403
|
"ConcurrencyLimiter",
|
|
387
404
|
"ConfigurationError",
|
|
388
405
|
"Connector",
|
|
406
|
+
"CostCeiling",
|
|
389
407
|
"CostLedger",
|
|
390
408
|
"CostProfile",
|
|
391
409
|
"Dataset",
|
|
@@ -439,6 +457,7 @@ __all__ = [
|
|
|
439
457
|
"KnowledgeDataSourceKind",
|
|
440
458
|
"KnowledgeDataSourceSpec",
|
|
441
459
|
"KnowledgeVectorStoreSpec",
|
|
460
|
+
"LatencyCeiling",
|
|
442
461
|
"LedgerEntry",
|
|
443
462
|
"LexicalReranker",
|
|
444
463
|
"LlmJudge",
|
|
@@ -494,6 +513,8 @@ __all__ = [
|
|
|
494
513
|
"RetrieverSeam",
|
|
495
514
|
"RetrieverSpec",
|
|
496
515
|
"Role",
|
|
516
|
+
"RunContext",
|
|
517
|
+
"RunOutput",
|
|
497
518
|
"RunResult",
|
|
498
519
|
"RunStatus",
|
|
499
520
|
"Runner",
|
|
@@ -530,6 +551,8 @@ __all__ = [
|
|
|
530
551
|
"ToolPermissionError",
|
|
531
552
|
"ToolResult",
|
|
532
553
|
"ToolSpec",
|
|
554
|
+
"ToolTrace",
|
|
555
|
+
"Trajectory",
|
|
533
556
|
"UnknownModelAliasError",
|
|
534
557
|
"VectorStore",
|
|
535
558
|
"VectorStoreSpec",
|
|
@@ -549,6 +572,7 @@ __all__ = [
|
|
|
549
572
|
"chunker_for",
|
|
550
573
|
"cite",
|
|
551
574
|
"configure_export",
|
|
575
|
+
"configure_metrics",
|
|
552
576
|
"create_store",
|
|
553
577
|
"decision_cost_usd",
|
|
554
578
|
"decision_key",
|
|
@@ -581,8 +605,10 @@ __all__ = [
|
|
|
581
605
|
"parallel",
|
|
582
606
|
"parse_structured",
|
|
583
607
|
"pinned_embedding",
|
|
608
|
+
"record_agent_run",
|
|
584
609
|
"record_attributes",
|
|
585
610
|
"record_cost",
|
|
611
|
+
"record_eval_case",
|
|
586
612
|
"record_exception",
|
|
587
613
|
"record_hitl",
|
|
588
614
|
"record_usage",
|
|
@@ -89,6 +89,7 @@ from aid_runtime.errors import (
|
|
|
89
89
|
ToolPermissionError,
|
|
90
90
|
)
|
|
91
91
|
from aid_runtime.gateway import ModelGateway
|
|
92
|
+
from aid_runtime.metrics import record_agent_run
|
|
92
93
|
from aid_runtime.providers.base import Provider
|
|
93
94
|
from aid_runtime.tools import Tool, ToolExecutor
|
|
94
95
|
from aid_runtime.tracing import agent_span, record_attributes, record_guardrail, record_hitl
|
|
@@ -274,11 +275,17 @@ class AgentRuntime:
|
|
|
274
275
|
)
|
|
275
276
|
start_cost = self._gateway.ledger.cost_usd
|
|
276
277
|
start_tokens = self._gateway.ledger.total_tokens
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
278
|
+
try:
|
|
279
|
+
outcome = await self._drive(
|
|
280
|
+
frame,
|
|
281
|
+
principal=principal if principal is not None else Principal(),
|
|
282
|
+
memory_key=key,
|
|
283
|
+
)
|
|
284
|
+
except BaseException:
|
|
285
|
+
# A run stopped by a guardrail or an exhausted ceiling was already billed.
|
|
286
|
+
# The refusal is re-raised unchanged: publishing the spend is not a recovery.
|
|
287
|
+
self._publish_spend(agent.id, start_cost, start_tokens)
|
|
288
|
+
raise
|
|
282
289
|
return self._wrap(outcome, start_cost, start_tokens)
|
|
283
290
|
|
|
284
291
|
async def resume(
|
|
@@ -293,11 +300,16 @@ class AgentRuntime:
|
|
|
293
300
|
self._restore_ledger(checkpoint)
|
|
294
301
|
start_cost = self._gateway.ledger.cost_usd
|
|
295
302
|
start_tokens = self._gateway.ledger.total_tokens
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
303
|
+
try:
|
|
304
|
+
outcome = await self._resume(
|
|
305
|
+
checkpoint,
|
|
306
|
+
resolved,
|
|
307
|
+
principal if principal is not None else Principal(),
|
|
308
|
+
)
|
|
309
|
+
except BaseException:
|
|
310
|
+
# Same rule as `run`: a resumed run that fails has been billed too.
|
|
311
|
+
self._publish_spend(checkpoint.agent_id, start_cost, start_tokens)
|
|
312
|
+
raise
|
|
301
313
|
return self._wrap(outcome, start_cost, start_tokens)
|
|
302
314
|
|
|
303
315
|
async def _resume(
|
|
@@ -1238,19 +1250,36 @@ class AgentRuntime:
|
|
|
1238
1250
|
)
|
|
1239
1251
|
|
|
1240
1252
|
def _wrap(self, outcome: _Outcome, start_cost: float, start_tokens: int) -> RunResult:
|
|
1241
|
-
|
|
1253
|
+
cost_usd, total_tokens = self._publish_spend(outcome.agent_id, start_cost, start_tokens)
|
|
1242
1254
|
return RunResult(
|
|
1243
1255
|
status=outcome.status,
|
|
1244
1256
|
agent_id=outcome.agent_id,
|
|
1245
1257
|
answer=outcome.answer,
|
|
1246
1258
|
steps=tuple(outcome.steps),
|
|
1247
1259
|
path=outcome.path,
|
|
1248
|
-
cost_usd=
|
|
1249
|
-
total_tokens=
|
|
1260
|
+
cost_usd=cost_usd,
|
|
1261
|
+
total_tokens=total_tokens,
|
|
1250
1262
|
checkpoint=outcome.checkpoint,
|
|
1251
1263
|
guardrails=outcome.guardrails,
|
|
1252
1264
|
)
|
|
1253
1265
|
|
|
1266
|
+
def _publish_spend(
|
|
1267
|
+
self, agent_id: str, start_cost: float, start_tokens: int
|
|
1268
|
+
) -> tuple[float, int]:
|
|
1269
|
+
"""Record what a run spent since ``start_*`` and return the same figures.
|
|
1270
|
+
|
|
1271
|
+
Every run is assembled here, on both engines, so this is the one place a run's
|
|
1272
|
+
spend is published without counting a turn twice. It is called from the exception
|
|
1273
|
+
paths as well: a run stopped by a guardrail or an exhausted budget has already
|
|
1274
|
+
been billed, and a budget alarm that only saw successful runs would under-report
|
|
1275
|
+
exactly when guardrails are firing.
|
|
1276
|
+
"""
|
|
1277
|
+
ledger = self._gateway.ledger
|
|
1278
|
+
cost_usd = round(max(ledger.cost_usd - start_cost, 0.0), 6)
|
|
1279
|
+
total_tokens = max(ledger.total_tokens - start_tokens, 0)
|
|
1280
|
+
record_agent_run(agent_id=agent_id, cost_usd=cost_usd, tokens=total_tokens)
|
|
1281
|
+
return cost_usd, total_tokens
|
|
1282
|
+
|
|
1254
1283
|
|
|
1255
1284
|
def _budget_of(thread: ThreadMemory) -> int:
|
|
1256
1285
|
return thread.token_budget if thread.token_budget is not None else 0
|
|
@@ -17,14 +17,18 @@ from aid_runtime.evals.gate import (
|
|
|
17
17
|
)
|
|
18
18
|
from aid_runtime.evals.metrics import (
|
|
19
19
|
AssertMetric,
|
|
20
|
+
CostCeiling,
|
|
20
21
|
DecisionScore,
|
|
21
22
|
ExactMatch,
|
|
22
23
|
JsonSchemaValid,
|
|
23
24
|
JudgeVerdict,
|
|
25
|
+
LatencyCeiling,
|
|
24
26
|
LlmJudge,
|
|
25
27
|
Metric,
|
|
26
28
|
MetricResult,
|
|
27
29
|
NormalizedContains,
|
|
30
|
+
RunContext,
|
|
31
|
+
ToolTrace,
|
|
28
32
|
default_metrics,
|
|
29
33
|
metric_names,
|
|
30
34
|
normalize,
|
|
@@ -38,11 +42,13 @@ from aid_runtime.evals.runner import (
|
|
|
38
42
|
gateway_judge,
|
|
39
43
|
run_evaluation,
|
|
40
44
|
)
|
|
45
|
+
from aid_runtime.evals.trajectory import RunOutput, Trajectory
|
|
41
46
|
|
|
42
47
|
__all__ = [
|
|
43
48
|
"AssertMetric",
|
|
44
49
|
"BaselineGate",
|
|
45
50
|
"CaseOutcome",
|
|
51
|
+
"CostCeiling",
|
|
46
52
|
"Dataset",
|
|
47
53
|
"DatasetRun",
|
|
48
54
|
"DecisionScore",
|
|
@@ -54,6 +60,7 @@ __all__ = [
|
|
|
54
60
|
"GatewayRunner",
|
|
55
61
|
"JsonSchemaValid",
|
|
56
62
|
"JudgeVerdict",
|
|
63
|
+
"LatencyCeiling",
|
|
57
64
|
"LlmJudge",
|
|
58
65
|
"Metric",
|
|
59
66
|
"MetricBaseline",
|
|
@@ -61,8 +68,12 @@ __all__ = [
|
|
|
61
68
|
"MetricResult",
|
|
62
69
|
"MetricRun",
|
|
63
70
|
"NormalizedContains",
|
|
71
|
+
"RunContext",
|
|
72
|
+
"RunOutput",
|
|
64
73
|
"Runner",
|
|
65
74
|
"Threshold",
|
|
75
|
+
"ToolTrace",
|
|
76
|
+
"Trajectory",
|
|
66
77
|
"default_metrics",
|
|
67
78
|
"evaluate_once",
|
|
68
79
|
"gate_from_config",
|
|
@@ -21,18 +21,23 @@ from aid_runtime.decisions import DecisionClient, DecisionQuestion, DecisionResp
|
|
|
21
21
|
from aid_runtime.errors import ConfigurationError, EvalError
|
|
22
22
|
from aid_runtime.evals.dataset import EvalCase
|
|
23
23
|
from aid_runtime.evals.predicate import evaluate_predicate
|
|
24
|
+
from aid_runtime.evals.trajectory import Trajectory
|
|
24
25
|
from aid_runtime.structured import run_structured
|
|
25
26
|
|
|
26
27
|
__all__ = [
|
|
27
28
|
"AssertMetric",
|
|
29
|
+
"CostCeiling",
|
|
28
30
|
"DecisionScore",
|
|
29
31
|
"ExactMatch",
|
|
30
32
|
"JsonSchemaValid",
|
|
31
33
|
"JudgeVerdict",
|
|
34
|
+
"LatencyCeiling",
|
|
32
35
|
"LlmJudge",
|
|
33
36
|
"Metric",
|
|
34
37
|
"MetricResult",
|
|
35
38
|
"NormalizedContains",
|
|
39
|
+
"RunContext",
|
|
40
|
+
"ToolTrace",
|
|
36
41
|
"default_metrics",
|
|
37
42
|
"metric_names",
|
|
38
43
|
"normalize",
|
|
@@ -52,6 +57,33 @@ class MetricResult(BaseModel):
|
|
|
52
57
|
detail: str = ""
|
|
53
58
|
|
|
54
59
|
|
|
60
|
+
class RunContext(BaseModel):
|
|
61
|
+
"""What the harness measured about the run a prediction came from.
|
|
62
|
+
|
|
63
|
+
A prediction on its own cannot answer "what did this case cost" or "how long did
|
|
64
|
+
it take", and those are numbers the harness already has. They travel beside the
|
|
65
|
+
prediction so a ceiling metric can read them without the runner having to smuggle
|
|
66
|
+
them through the answer text. A metric that only inspects text ignores this and
|
|
67
|
+
behaves exactly as it did before.
|
|
68
|
+
|
|
69
|
+
``metered`` is deliberately separate from ``cost_usd``. An unmetered runner reports
|
|
70
|
+
a real ``0.0`` -- "does not meter" and "spent nothing" are the same number -- so a
|
|
71
|
+
cost ceiling has to be told which one it is looking at, or it would pass forever
|
|
72
|
+
over a run nobody measured.
|
|
73
|
+
|
|
74
|
+
``trajectory`` is ``None`` when the runner said nothing about tool calls, and that is
|
|
75
|
+
distinguishable from a run that called no tools: the second is an empty trajectory,
|
|
76
|
+
the first is a runner that only ever returned its answer text.
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
model_config = ConfigDict(frozen=True, extra="forbid")
|
|
80
|
+
|
|
81
|
+
cost_usd: float = Field(default=0.0, ge=0.0)
|
|
82
|
+
latency_ms: float = Field(default=0.0, ge=0.0)
|
|
83
|
+
metered: bool = False
|
|
84
|
+
trajectory: Trajectory | None = None
|
|
85
|
+
|
|
86
|
+
|
|
55
87
|
@runtime_checkable
|
|
56
88
|
class Metric(Protocol):
|
|
57
89
|
"""Scores a single prediction."""
|
|
@@ -71,7 +103,9 @@ class Metric(Protocol):
|
|
|
71
103
|
"""
|
|
72
104
|
...
|
|
73
105
|
|
|
74
|
-
async def score(
|
|
106
|
+
async def score(
|
|
107
|
+
self, case: EvalCase, prediction: str, *, context: RunContext | None = None
|
|
108
|
+
) -> MetricResult: ...
|
|
75
109
|
|
|
76
110
|
|
|
77
111
|
def normalize(text: str) -> str:
|
|
@@ -94,7 +128,9 @@ class ExactMatch:
|
|
|
94
128
|
def deterministic(self) -> bool:
|
|
95
129
|
return True
|
|
96
130
|
|
|
97
|
-
async def score(
|
|
131
|
+
async def score(
|
|
132
|
+
self, case: EvalCase, prediction: str, *, context: RunContext | None = None
|
|
133
|
+
) -> MetricResult:
|
|
98
134
|
if case.expected is None:
|
|
99
135
|
raise EvalError(f"case {case.id!r} has no expected value for {self.name}")
|
|
100
136
|
ok = normalize(prediction) == normalize(case.expected)
|
|
@@ -120,7 +156,9 @@ class NormalizedContains:
|
|
|
120
156
|
def deterministic(self) -> bool:
|
|
121
157
|
return True
|
|
122
158
|
|
|
123
|
-
async def score(
|
|
159
|
+
async def score(
|
|
160
|
+
self, case: EvalCase, prediction: str, *, context: RunContext | None = None
|
|
161
|
+
) -> MetricResult:
|
|
124
162
|
if case.expected is None:
|
|
125
163
|
raise EvalError(f"case {case.id!r} has no expected value for {self.name}")
|
|
126
164
|
ok = normalize(case.expected) in normalize(prediction)
|
|
@@ -150,7 +188,9 @@ class JsonSchemaValid:
|
|
|
150
188
|
def deterministic(self) -> bool:
|
|
151
189
|
return True
|
|
152
190
|
|
|
153
|
-
async def score(
|
|
191
|
+
async def score(
|
|
192
|
+
self, case: EvalCase, prediction: str, *, context: RunContext | None = None
|
|
193
|
+
) -> MetricResult:
|
|
154
194
|
schema = case.metadata.get("json_schema")
|
|
155
195
|
try:
|
|
156
196
|
parsed = json.loads(prediction)
|
|
@@ -198,7 +238,9 @@ class AssertMetric:
|
|
|
198
238
|
def deterministic(self) -> bool:
|
|
199
239
|
return True
|
|
200
240
|
|
|
201
|
-
async def score(
|
|
241
|
+
async def score(
|
|
242
|
+
self, case: EvalCase, prediction: str, *, context: RunContext | None = None
|
|
243
|
+
) -> MetricResult:
|
|
202
244
|
ok = evaluate_predicate(self._expr, case=case, prediction=prediction)
|
|
203
245
|
return MetricResult(
|
|
204
246
|
metric=self.name,
|
|
@@ -251,7 +293,9 @@ class LlmJudge:
|
|
|
251
293
|
def deterministic(self) -> bool:
|
|
252
294
|
return False
|
|
253
295
|
|
|
254
|
-
async def score(
|
|
296
|
+
async def score(
|
|
297
|
+
self, case: EvalCase, prediction: str, *, context: RunContext | None = None
|
|
298
|
+
) -> MetricResult:
|
|
255
299
|
prompt = self._build_prompt(case, prediction)
|
|
256
300
|
try:
|
|
257
301
|
verdict = await run_structured(self._call, JudgeVerdict, prompt, retries=self._retries)
|
|
@@ -324,7 +368,9 @@ class DecisionScore:
|
|
|
324
368
|
def deterministic(self) -> bool:
|
|
325
369
|
return False
|
|
326
370
|
|
|
327
|
-
async def score(
|
|
371
|
+
async def score(
|
|
372
|
+
self, case: EvalCase, prediction: str, *, context: RunContext | None = None
|
|
373
|
+
) -> MetricResult:
|
|
328
374
|
response = await self._ask(prediction)
|
|
329
375
|
answer = response.answers.get(self._decision.id)
|
|
330
376
|
if answer is None or answer.score is None:
|
|
@@ -362,6 +408,186 @@ class DecisionScore:
|
|
|
362
408
|
)
|
|
363
409
|
|
|
364
410
|
|
|
411
|
+
class _Ceiling:
|
|
412
|
+
"""Shared shape for the two metrics that read a number off the run context.
|
|
413
|
+
|
|
414
|
+
Both refuse rather than pass when the number they are asked to bound was never
|
|
415
|
+
measured: a ceiling that passes over an unmeasured run is a gate that cannot fail,
|
|
416
|
+
which is worse than no gate at all because it looks like coverage.
|
|
417
|
+
"""
|
|
418
|
+
|
|
419
|
+
_quantity = "value"
|
|
420
|
+
|
|
421
|
+
def __init__(self, *, name: str) -> None:
|
|
422
|
+
self._name = name
|
|
423
|
+
|
|
424
|
+
@property
|
|
425
|
+
def name(self) -> str:
|
|
426
|
+
return self._name
|
|
427
|
+
|
|
428
|
+
@property
|
|
429
|
+
def deterministic(self) -> bool:
|
|
430
|
+
return True
|
|
431
|
+
|
|
432
|
+
def _measure(self, case: EvalCase, context: RunContext | None) -> float:
|
|
433
|
+
raise NotImplementedError
|
|
434
|
+
|
|
435
|
+
async def score(
|
|
436
|
+
self, case: EvalCase, prediction: str, *, context: RunContext | None = None
|
|
437
|
+
) -> MetricResult:
|
|
438
|
+
ceiling = self._limit()
|
|
439
|
+
measured = self._measure(case, context)
|
|
440
|
+
ok = measured <= ceiling
|
|
441
|
+
return MetricResult(
|
|
442
|
+
metric=self.name,
|
|
443
|
+
score=1.0 if ok else 0.0,
|
|
444
|
+
passed=ok,
|
|
445
|
+
detail=f"{self._quantity} {self._format(measured)}, ceiling {self._format(ceiling)}",
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
def _limit(self) -> float:
|
|
449
|
+
raise NotImplementedError
|
|
450
|
+
|
|
451
|
+
def _format(self, value: float) -> str:
|
|
452
|
+
return f"{value:.4f}"
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
class CostCeiling(_Ceiling):
|
|
456
|
+
"""Whether one case stayed inside a declared per-case spend.
|
|
457
|
+
|
|
458
|
+
Costs money to find out, so it is opt-in: an eval declares it and the generator
|
|
459
|
+
maps it. The harness reads spend from the gateway ledger, which only exists for a
|
|
460
|
+
runner that meters, so an unmetered runner is refused, not scored.
|
|
461
|
+
"""
|
|
462
|
+
|
|
463
|
+
_quantity = "spent"
|
|
464
|
+
|
|
465
|
+
def __init__(self, *, max_usd: float, name: str = "cost") -> None:
|
|
466
|
+
if max_usd <= 0:
|
|
467
|
+
raise ConfigurationError(f"a cost ceiling must be above zero, got {max_usd:g}")
|
|
468
|
+
super().__init__(name=name)
|
|
469
|
+
self._max = max_usd
|
|
470
|
+
|
|
471
|
+
def _limit(self) -> float:
|
|
472
|
+
return self._max
|
|
473
|
+
|
|
474
|
+
def _measure(self, case: EvalCase, context: RunContext | None) -> float:
|
|
475
|
+
if context is None or not context.metered:
|
|
476
|
+
raise EvalError(
|
|
477
|
+
f"case {case.id!r} carries a cost ceiling, but its runner does not meter "
|
|
478
|
+
"spend, so the ceiling would pass over a run nobody measured"
|
|
479
|
+
)
|
|
480
|
+
return context.cost_usd
|
|
481
|
+
|
|
482
|
+
def _format(self, value: float) -> str:
|
|
483
|
+
return f"${value:.4f}"
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
class LatencyCeiling(_Ceiling):
|
|
487
|
+
"""Whether one case finished inside a declared wall-clock budget.
|
|
488
|
+
|
|
489
|
+
Measured by the harness around the runner call, so it is available for every
|
|
490
|
+
runner rather than only the metering ones.
|
|
491
|
+
"""
|
|
492
|
+
|
|
493
|
+
_quantity = "took"
|
|
494
|
+
|
|
495
|
+
def __init__(self, *, max_ms: float, name: str = "latency") -> None:
|
|
496
|
+
if max_ms <= 0:
|
|
497
|
+
raise ConfigurationError(f"a latency ceiling must be above zero, got {max_ms:g}")
|
|
498
|
+
super().__init__(name=name)
|
|
499
|
+
self._max = max_ms
|
|
500
|
+
|
|
501
|
+
def _limit(self) -> float:
|
|
502
|
+
return self._max
|
|
503
|
+
|
|
504
|
+
def _measure(self, case: EvalCase, context: RunContext | None) -> float:
|
|
505
|
+
if context is None:
|
|
506
|
+
raise EvalError(
|
|
507
|
+
f"case {case.id!r} carries a latency ceiling, but it was scored outside a "
|
|
508
|
+
"measured run, so there is no elapsed time to compare against it"
|
|
509
|
+
)
|
|
510
|
+
return context.latency_ms
|
|
511
|
+
|
|
512
|
+
def _format(self, value: float) -> str:
|
|
513
|
+
return f"{value:.0f}ms"
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
class ToolTrace:
|
|
517
|
+
"""Whether a run called the tools it was expected to, in the order it was told.
|
|
518
|
+
|
|
519
|
+
``ordered`` is the whole semantics, and it is the reason this metric needs a
|
|
520
|
+
decision rather than a default: ``True`` means ``expect`` has to appear as a
|
|
521
|
+
*subsequence* of the calls made, ``False`` means every expected tool has to appear
|
|
522
|
+
at least once, in any order. Extra calls are tolerated either way -- a run that
|
|
523
|
+
looked one more thing up on the way did more than the minimum, and failing it would
|
|
524
|
+
benchmark one exact transcript rather than a capability. A run that calls an
|
|
525
|
+
expected tool twice passes too; the metric asks whether the tool was called, not how
|
|
526
|
+
often, because "how often" is a budget question and ``cost`` answers it.
|
|
527
|
+
|
|
528
|
+
Refuses rather than passes when the runner reported no trajectory: a trace assertion
|
|
529
|
+
over an answer-only runner would pass on every case by having nothing to compare,
|
|
530
|
+
which is coverage that does not exist.
|
|
531
|
+
"""
|
|
532
|
+
|
|
533
|
+
def __init__(
|
|
534
|
+
self,
|
|
535
|
+
*,
|
|
536
|
+
expect: Sequence[str],
|
|
537
|
+
ordered: bool = False,
|
|
538
|
+
name: str = "tool-trace",
|
|
539
|
+
) -> None:
|
|
540
|
+
if not expect:
|
|
541
|
+
raise ConfigurationError("a tool-trace metric must expect at least one tool")
|
|
542
|
+
self._name = name
|
|
543
|
+
self._expect = tuple(expect)
|
|
544
|
+
self._ordered = ordered
|
|
545
|
+
|
|
546
|
+
@property
|
|
547
|
+
def name(self) -> str:
|
|
548
|
+
return self._name
|
|
549
|
+
|
|
550
|
+
@property
|
|
551
|
+
def deterministic(self) -> bool:
|
|
552
|
+
return True
|
|
553
|
+
|
|
554
|
+
async def score(
|
|
555
|
+
self, case: EvalCase, prediction: str, *, context: RunContext | None = None
|
|
556
|
+
) -> MetricResult:
|
|
557
|
+
if context is None or context.trajectory is None:
|
|
558
|
+
raise EvalError(
|
|
559
|
+
f"case {case.id!r} carries a tool-trace metric, but its runner reported no "
|
|
560
|
+
"tool calls, so there is nothing to compare the expectation against"
|
|
561
|
+
)
|
|
562
|
+
calls = context.trajectory.calls
|
|
563
|
+
ok = self._satisfied_by(calls)
|
|
564
|
+
return MetricResult(
|
|
565
|
+
metric=self.name,
|
|
566
|
+
score=1.0 if ok else 0.0,
|
|
567
|
+
passed=ok,
|
|
568
|
+
detail=(
|
|
569
|
+
f"called {_tool_list(calls)}"
|
|
570
|
+
if ok
|
|
571
|
+
else (
|
|
572
|
+
f"expected {_tool_list(self._expect)}"
|
|
573
|
+
f"{' in order' if self._ordered else ''}, called {_tool_list(calls)}"
|
|
574
|
+
)
|
|
575
|
+
),
|
|
576
|
+
)
|
|
577
|
+
|
|
578
|
+
def _satisfied_by(self, calls: Sequence[str]) -> bool:
|
|
579
|
+
if not self._ordered:
|
|
580
|
+
return set(self._expect) <= set(calls)
|
|
581
|
+
# Walking the calls once with a cursor is the subsequence test: `in` on an
|
|
582
|
+
# iterator advances it, so each expected tool has to be found after the last one.
|
|
583
|
+
remaining = iter(calls)
|
|
584
|
+
return all(tool in remaining for tool in self._expect)
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
def _tool_list(names: Sequence[str]) -> str:
|
|
588
|
+
return ", ".join(names) if names else "no tools"
|
|
589
|
+
|
|
590
|
+
|
|
365
591
|
def default_metrics() -> tuple[Metric, ...]:
|
|
366
592
|
"""The deterministic gate metrics: everything that needs no model call."""
|
|
367
593
|
return (ExactMatch(), NormalizedContains(), JsonSchemaValid())
|