aid-runtime-python 0.1.164__tar.gz → 0.1.166__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.164 → aid_runtime_python-0.1.166}/PKG-INFO +1 -1
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/pyproject.toml +1 -1
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/__init__.py +5 -2
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/agents/chat_model.py +34 -1
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/agents/deep_agents.py +9 -2
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/agents/ir.py +22 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/agents/loop.py +78 -9
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/providers/__init__.py +2 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/providers/recorded.py +115 -33
- aid_runtime_python-0.1.166/src/aid_runtime/redaction.py +92 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime_python.egg-info/PKG-INFO +1 -1
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime_python.egg-info/SOURCES.txt +1 -0
- aid_runtime_python-0.1.166/tests/test_agents_redaction.py +167 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_recorded_provider.py +69 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_redaction.py +51 -1
- aid_runtime_python-0.1.164/src/aid_runtime/redaction.py +0 -46
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/README.md +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/setup.cfg +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/agents/__init__.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/agents/engine.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/agents/guardrails.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/agents/managed.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/agents/memory.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/agents/policy.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/agents/resume.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/agents/state.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/cache.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/concurrency.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/control.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/cost.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/decisions.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/errors.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/evals/__init__.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/evals/agent_runner.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/evals/dataset.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/evals/gate.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/evals/metrics.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/evals/predicate.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/evals/runner.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/evals/trajectory.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/gateway.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/local_trace.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/metrics.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/pipeline.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/prompts.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/providers/anthropic.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/providers/base.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/providers/bedrock.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/providers/fake.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/providers/gemini.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/providers/gemini_wire.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/providers/http.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/providers/vertex.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/py.typed +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/retrieval/__init__.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/retrieval/chunking.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/retrieval/citations.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/retrieval/connectors.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/retrieval/embedding.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/retrieval/filters.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/retrieval/gate.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/retrieval/hybrid.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/retrieval/knowledge_base.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/retrieval/metrics.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/retrieval/pgvector.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/retrieval/rerank.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/retrieval/retriever.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/retrieval/stores.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/retrieval/types.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/steps.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/structured.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/telemetry.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/tools.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/tracing.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/types.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime_python.egg-info/dependency_links.txt +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime_python.egg-info/requires.txt +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime_python.egg-info/top_level.txt +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_agent_eval_runner.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_agents_budget.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_agents_checkpoint_integrity.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_agents_deep_agents.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_agents_hitl.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_agents_loop.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_agents_memory.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_anthropic_provider.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_bedrock_provider.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_cache.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_concurrency.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_control.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_cost.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_dataset.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_decisions.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_evals.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_evals_assert_gate.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_evals_budgets.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_evals_decision.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_evals_gate.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_evals_predicate.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_evals_trajectory.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_gateway.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_gemini_provider.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_guardrails.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_guardrails_managed.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_guardrails_model_armor.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_http_provider.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_local_trace.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_metrics.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_package.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_pipeline.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_prompts.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_retrieval_chunking.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_retrieval_citations.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_retrieval_connectors.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_retrieval_embedding.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_retrieval_filters.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_retrieval_gate.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_retrieval_hybrid.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_retrieval_knowledge_base.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_retrieval_metrics.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_retrieval_rerank.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_retrieval_stores.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_retrieval_types.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_steps.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_streaming.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_structured.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_telemetry.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_tool_permissions.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_tools.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_tracing.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/tests/test_types.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/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.166
|
|
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.166"
|
|
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"
|
|
@@ -199,6 +199,7 @@ from aid_runtime.providers import (
|
|
|
199
199
|
Provider,
|
|
200
200
|
RecordedProvider,
|
|
201
201
|
RecordingProvider,
|
|
202
|
+
RecordingProviders,
|
|
202
203
|
ReplayDivergenceError,
|
|
203
204
|
ScriptedTurn,
|
|
204
205
|
Transcript,
|
|
@@ -207,7 +208,7 @@ from aid_runtime.providers import (
|
|
|
207
208
|
default_bedrock_base_url,
|
|
208
209
|
default_vertex_base_url,
|
|
209
210
|
)
|
|
210
|
-
from aid_runtime.redaction import REDACTED_FORMAT, redact_values
|
|
211
|
+
from aid_runtime.redaction import REDACTED_FORMAT, bind_redactions, redact_values
|
|
211
212
|
from aid_runtime.retrieval import (
|
|
212
213
|
DEFAULT_CANDIDATE_FACTOR,
|
|
213
214
|
DEFAULT_SYNC_TIMEOUT_SECONDS,
|
|
@@ -356,7 +357,7 @@ from aid_runtime.types import (
|
|
|
356
357
|
)
|
|
357
358
|
|
|
358
359
|
#: Kept in sync with ``pyproject.toml`` by a test, so the two cannot drift.
|
|
359
|
-
__version__ = "0.1.
|
|
360
|
+
__version__ = "0.1.166"
|
|
360
361
|
|
|
361
362
|
__all__ = [
|
|
362
363
|
"AGENT_LABEL",
|
|
@@ -526,6 +527,7 @@ __all__ = [
|
|
|
526
527
|
"RecallAtK",
|
|
527
528
|
"RecordedProvider",
|
|
528
529
|
"RecordingProvider",
|
|
530
|
+
"RecordingProviders",
|
|
529
531
|
"RecursiveChunker",
|
|
530
532
|
"RefreshMode",
|
|
531
533
|
"RefreshSpec",
|
|
@@ -596,6 +598,7 @@ __all__ = [
|
|
|
596
598
|
"agent_span",
|
|
597
599
|
"aid_attributes",
|
|
598
600
|
"assemble_context",
|
|
601
|
+
"bind_redactions",
|
|
599
602
|
"binding_from_managed_spec",
|
|
600
603
|
"binding_from_spec",
|
|
601
604
|
"bm25_scores",
|
{aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/agents/chat_model.py
RENAMED
|
@@ -51,6 +51,7 @@ from pydantic import Field
|
|
|
51
51
|
from aid_runtime.cost import Budget
|
|
52
52
|
from aid_runtime.errors import DeepAgentsEngineError, DeepAgentsMaxStepsError
|
|
53
53
|
from aid_runtime.gateway import ModelGateway
|
|
54
|
+
from aid_runtime.redaction import bind_redactions
|
|
54
55
|
from aid_runtime.types import CompletionRequest, Message, ToolCall, ToolDefinition
|
|
55
56
|
|
|
56
57
|
__all__ = [
|
|
@@ -80,6 +81,14 @@ class GatewayChatModel(BaseChatModel):
|
|
|
80
81
|
#: harness's own limiter completes the run with a synthetic answer instead of
|
|
81
82
|
#: failing. ``None`` disables the counter (used by the offline fixtures).
|
|
82
83
|
max_calls: int | None = None
|
|
84
|
+
#: ``observability.redact``: the fields the recorded copy of each generation must
|
|
85
|
+
#: not carry. The harness hands this adapter a conversation, not a render, so the
|
|
86
|
+
#: values are bound from the tool calls in that conversation -- the same source the
|
|
87
|
+
#: native loop uses.
|
|
88
|
+
redact: tuple[str, ...] = ()
|
|
89
|
+
#: The ``(name, value)`` pairs learned so far. Kept because the harness may trim the
|
|
90
|
+
#: conversation it hands back, and a value learned once stays withheld.
|
|
91
|
+
redactions: tuple[tuple[str, str], ...] = ()
|
|
83
92
|
#: What ``bind_tools`` last admitted. Read by tests, never by the harness.
|
|
84
93
|
bound_tools: tuple[ToolDefinition, ...] = ()
|
|
85
94
|
#: Every generation this model produced, in order. The proof that the harness
|
|
@@ -125,6 +134,28 @@ class GatewayChatModel(BaseChatModel):
|
|
|
125
134
|
"accounting path. Use ainvoke."
|
|
126
135
|
)
|
|
127
136
|
|
|
137
|
+
def _withhold(self, conversation: Sequence[Message]) -> tuple[tuple[str, str], ...]:
|
|
138
|
+
"""Learn what to withhold from the tool calls the harness handed back.
|
|
139
|
+
|
|
140
|
+
Called before every generation, so a value that entered the conversation one
|
|
141
|
+
call ago is withheld from the moment it appears. Only declared field names are
|
|
142
|
+
bound and only string values -- the same rule as the native loop, and it carries
|
|
143
|
+
the same limit: a value the model mentions in free text has no field name to
|
|
144
|
+
match, so ``observability.redact`` cannot reach it.
|
|
145
|
+
"""
|
|
146
|
+
if not self.redact:
|
|
147
|
+
return ()
|
|
148
|
+
known = list(self.redactions)
|
|
149
|
+
for message in conversation:
|
|
150
|
+
for call in message.tool_calls:
|
|
151
|
+
for pair in bind_redactions(self.redact, call.arguments):
|
|
152
|
+
if pair not in known:
|
|
153
|
+
known.append(pair)
|
|
154
|
+
learned = tuple(known)
|
|
155
|
+
if learned != self.redactions:
|
|
156
|
+
self.redactions = learned
|
|
157
|
+
return learned
|
|
158
|
+
|
|
128
159
|
async def _agenerate(
|
|
129
160
|
self,
|
|
130
161
|
messages: list[BaseMessage],
|
|
@@ -139,9 +170,11 @@ class GatewayChatModel(BaseChatModel):
|
|
|
139
170
|
breach is raised, not returned: the harness must not be able to continue
|
|
140
171
|
past a budget the ledger already refused.
|
|
141
172
|
"""
|
|
173
|
+
conversation = to_aid_messages(messages)
|
|
142
174
|
request = CompletionRequest(
|
|
143
|
-
messages=
|
|
175
|
+
messages=conversation,
|
|
144
176
|
tools=self.bound_tools,
|
|
177
|
+
redactions=self._withhold(conversation),
|
|
145
178
|
)
|
|
146
179
|
if self.max_calls is not None and len(self.calls) >= self.max_calls:
|
|
147
180
|
# Refused before the call, not after: an agent that has spent its step
|
{aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/agents/deep_agents.py
RENAMED
|
@@ -225,6 +225,7 @@ class DeepAgentsEngine:
|
|
|
225
225
|
budget=budget,
|
|
226
226
|
allowed_tools=frozenset(allowed),
|
|
227
227
|
max_calls=max(agent.max_steps - frame.step, 0),
|
|
228
|
+
redact=self._runtime.spec.redact,
|
|
228
229
|
)
|
|
229
230
|
models.append((agent.id, model))
|
|
230
231
|
return model
|
|
@@ -311,12 +312,18 @@ class DeepAgentsEngine:
|
|
|
311
312
|
definition = self._runtime._executor.definition(spec.name)
|
|
312
313
|
|
|
313
314
|
async def _call(
|
|
314
|
-
_agent: AgentDefinition = agent,
|
|
315
|
+
_agent: AgentDefinition = agent,
|
|
316
|
+
_name: str = spec.name,
|
|
317
|
+
_frame: _Frame = frame,
|
|
318
|
+
**kwargs: Any,
|
|
315
319
|
) -> str:
|
|
316
320
|
# The id is derived, not random: the harness pairs a result with its
|
|
317
321
|
# call by id, and a random one would make two identical runs differ.
|
|
318
322
|
call = ToolCall(id=f"{_agent.id}:{_name}", name=_name, arguments=kwargs)
|
|
319
|
-
|
|
323
|
+
# The run's frame, so the value a tool call carries is bound for
|
|
324
|
+
# redaction exactly as it is under the native engine; `agent` keeps
|
|
325
|
+
# the delegate's own grant in force for a delegated call.
|
|
326
|
+
observations = await self._runtime._observe(_frame, [call], principal, agent=_agent)
|
|
320
327
|
return observations[0].content
|
|
321
328
|
|
|
322
329
|
tools.append(
|
|
@@ -260,6 +260,13 @@ class RuntimeSpec:
|
|
|
260
260
|
#: ``None`` means unbounded: the runtime only shares a limiter when a deployment
|
|
261
261
|
#: declares one, which keeps plain request/response usage free of surprises.
|
|
262
262
|
concurrency: int | None = None
|
|
263
|
+
#: ``observability.redact``: the fields a recorded trace must not carry. A pipeline
|
|
264
|
+
#: binds them when it renders a prompt; the loop binds them from the structured
|
|
265
|
+
#: records it handles (tool-call arguments) and from any the caller supplies, and
|
|
266
|
+
#: the gateway strips them from the copy it writes. An agent run has no render, so
|
|
267
|
+
#: a value that appears only in free text is not bound -- the limit is documented
|
|
268
|
+
#: where the declaration is.
|
|
269
|
+
redact: tuple[str, ...] = ()
|
|
263
270
|
|
|
264
271
|
def agent(self, agent_id: str) -> AgentDefinition:
|
|
265
272
|
try:
|
|
@@ -365,6 +372,7 @@ def from_ir(document: Mapping[str, Any]) -> RuntimeSpec:
|
|
|
365
372
|
guardrails=guardrails,
|
|
366
373
|
decisions=decisions,
|
|
367
374
|
concurrency=_concurrency(document.get("deployments")),
|
|
375
|
+
redact=_document_redact(document),
|
|
368
376
|
)
|
|
369
377
|
|
|
370
378
|
|
|
@@ -760,6 +768,20 @@ def _concurrency(raw: Any) -> int | None:
|
|
|
760
768
|
return max(declared) if declared else None
|
|
761
769
|
|
|
762
770
|
|
|
771
|
+
def _document_redact(document: Mapping[str, Any]) -> tuple[str, ...]:
|
|
772
|
+
"""``observability.redact``, the fields a recorded trace must not carry.
|
|
773
|
+
|
|
774
|
+
Read rather than re-derived: the IR already lowered the set, including the fields
|
|
775
|
+
its sensitive-name rule added, and a second derivation here would be a policy the
|
|
776
|
+
gates never saw. An absent block is an empty set, not an error -- the runtime runs
|
|
777
|
+
documents the shipped templates emit, and they declare nothing to withhold.
|
|
778
|
+
"""
|
|
779
|
+
observability = document.get("observability")
|
|
780
|
+
if not isinstance(observability, Mapping):
|
|
781
|
+
return ()
|
|
782
|
+
return tuple(_str_list(observability.get("redact"), "observability.redact"))
|
|
783
|
+
|
|
784
|
+
|
|
763
785
|
def _memory(memory_id: str, entry: Mapping[str, Any]) -> MemoryDefinition:
|
|
764
786
|
where = f"memory {memory_id!r}"
|
|
765
787
|
token_budget = entry.get("tokenBudget")
|
|
@@ -96,6 +96,7 @@ from aid_runtime.errors import (
|
|
|
96
96
|
from aid_runtime.gateway import ModelGateway
|
|
97
97
|
from aid_runtime.metrics import record_agent_run
|
|
98
98
|
from aid_runtime.providers.base import Provider
|
|
99
|
+
from aid_runtime.redaction import Redaction, bind_redactions
|
|
99
100
|
from aid_runtime.tools import Tool, ToolExecutor
|
|
100
101
|
from aid_runtime.tracing import agent_span, record_attributes, record_guardrail, record_hitl
|
|
101
102
|
from aid_runtime.types import (
|
|
@@ -170,6 +171,12 @@ class _Frame:
|
|
|
170
171
|
# the input stage already ran.
|
|
171
172
|
input_checked: bool = False
|
|
172
173
|
guardrails: list[GuardrailRecord] = field(default_factory=list)
|
|
174
|
+
# `(name, value)` pairs the declared redact set can strip from the *recorded* copy
|
|
175
|
+
# of every model call this frame makes. Seeded from what the caller supplied and
|
|
176
|
+
# from the tool-call arguments already in the transcript, and grown as the model
|
|
177
|
+
# composes more calls: an agent run has no render, so this is where its bindings
|
|
178
|
+
# come from. The live transcript is never edited -- see `aid_runtime.redaction`.
|
|
179
|
+
redactions: list[Redaction] = field(default_factory=list)
|
|
173
180
|
|
|
174
181
|
|
|
175
182
|
@dataclass(slots=True)
|
|
@@ -274,8 +281,17 @@ class AgentRuntime:
|
|
|
274
281
|
principal: Principal | None = None,
|
|
275
282
|
memory_key: str | None = None,
|
|
276
283
|
conversation: Sequence[Message] = (),
|
|
284
|
+
redactions: Sequence[Redaction] = (),
|
|
277
285
|
) -> RunResult:
|
|
278
|
-
"""Run ``agent_id`` to a stop condition on one user message.
|
|
286
|
+
"""Run ``agent_id`` to a stop condition on one user message.
|
|
287
|
+
|
|
288
|
+
``redactions`` is the caller's ``(name, value)`` bindings for the fields
|
|
289
|
+
``observability.redact`` withholds. A pipeline binds them when it renders a
|
|
290
|
+
prompt; an agent run has no render, so an application that already holds the
|
|
291
|
+
values -- a typed request, a database row -- supplies them here, and the loop
|
|
292
|
+
adds every value it learns from the tool calls the model composes. They are
|
|
293
|
+
applied to the *recorded* copy only: the model still receives the real text.
|
|
294
|
+
"""
|
|
279
295
|
agent = self._spec.agent(agent_id)
|
|
280
296
|
self._require_engine(agent)
|
|
281
297
|
key = memory_key or agent.id
|
|
@@ -289,6 +305,7 @@ class AgentRuntime:
|
|
|
289
305
|
path=(agent.id,),
|
|
290
306
|
memory_key=key,
|
|
291
307
|
)
|
|
308
|
+
frame.redactions[0:0] = list(redactions)
|
|
292
309
|
start_cost = self._gateway.ledger.cost_usd
|
|
293
310
|
start_tokens = self._gateway.ledger.total_tokens
|
|
294
311
|
try:
|
|
@@ -367,7 +384,7 @@ class AgentRuntime:
|
|
|
367
384
|
frame.messages.append(Message.assistant(answer))
|
|
368
385
|
await self._remember(agent, answer, checkpoint.memory_key)
|
|
369
386
|
return self._guardrail_completed(frame, answer)
|
|
370
|
-
frame.messages.extend(await self._observe(
|
|
387
|
+
frame.messages.extend(await self._observe(frame, checkpoint.calls, principal))
|
|
371
388
|
elif escalation is not None:
|
|
372
389
|
# A person declined to release what the guardrail flagged. That is a
|
|
373
390
|
# decision, not an error, and the run stops here with the guardrail's
|
|
@@ -567,7 +584,7 @@ class AgentRuntime:
|
|
|
567
584
|
guardrails=tuple(frame.guardrails),
|
|
568
585
|
)
|
|
569
586
|
|
|
570
|
-
frame.messages.extend(await self._observe(
|
|
587
|
+
frame.messages.extend(await self._observe(frame, guarded, principal))
|
|
571
588
|
|
|
572
589
|
async def _guardrail_text(
|
|
573
590
|
self,
|
|
@@ -837,7 +854,12 @@ class AgentRuntime:
|
|
|
837
854
|
)
|
|
838
855
|
|
|
839
856
|
async def _observe(
|
|
840
|
-
self,
|
|
857
|
+
self,
|
|
858
|
+
frame: _Frame,
|
|
859
|
+
calls: Sequence[ToolCall],
|
|
860
|
+
principal: Principal,
|
|
861
|
+
*,
|
|
862
|
+
agent: AgentDefinition | None = None,
|
|
841
863
|
) -> list[Message]:
|
|
842
864
|
"""Turn calls into observations, in the order the model asked for them.
|
|
843
865
|
|
|
@@ -851,10 +873,15 @@ class AgentRuntime:
|
|
|
851
873
|
The grant is the agent's declared tool list, and a side-effecting tool
|
|
852
874
|
additionally needs an ``auth`` policy that holds for this principal. A
|
|
853
875
|
model cannot repair either: the spec is what is wrong.
|
|
876
|
+
|
|
877
|
+
``agent`` defaults to the agent the frame is running. The harness engine
|
|
878
|
+
passes it explicitly, because a delegate's tool body executes inside the
|
|
879
|
+
delegate's grant while the run itself continues in the caller's frame.
|
|
854
880
|
"""
|
|
881
|
+
owner = agent if agent is not None else frame.agent
|
|
855
882
|
known = [call for call in calls if call.name in self._executor.names]
|
|
856
883
|
for call in known:
|
|
857
|
-
self._authorize(
|
|
884
|
+
self._authorize(owner, call, principal)
|
|
858
885
|
executed = {result.call_id: result for result in await self._executor.execute_all(known)}
|
|
859
886
|
observations: list[Message] = []
|
|
860
887
|
for call in calls:
|
|
@@ -868,7 +895,10 @@ class AgentRuntime:
|
|
|
868
895
|
)
|
|
869
896
|
)
|
|
870
897
|
continue
|
|
871
|
-
observations.append(Message.tool(
|
|
898
|
+
observations.append(Message.tool(call.id, result.content, name=result.name))
|
|
899
|
+
# Bound after execution: a call this agent may not make raises, and a denied
|
|
900
|
+
# call's arguments are not something the run went on to act on.
|
|
901
|
+
self._bind_calls(frame, calls)
|
|
872
902
|
return observations
|
|
873
903
|
|
|
874
904
|
def _authorize(self, agent: AgentDefinition, call: ToolCall, principal: Principal) -> None:
|
|
@@ -935,7 +965,14 @@ class AgentRuntime:
|
|
|
935
965
|
messages = frame.memory.thread.trim(messages)
|
|
936
966
|
if frame.memory.context:
|
|
937
967
|
messages = (messages[0], Message.system(frame.memory.context), *messages[1:])
|
|
938
|
-
return CompletionRequest(
|
|
968
|
+
return CompletionRequest(
|
|
969
|
+
messages=messages,
|
|
970
|
+
tools=self._tool_definitions(frame.agent),
|
|
971
|
+
# The gateway is the one place that writes model text to a trace, and this
|
|
972
|
+
# is the same pair list a rendered prompt hands it. The provider receives
|
|
973
|
+
# `messages` untouched; only the recorded copy is stripped.
|
|
974
|
+
redactions=tuple(frame.redactions),
|
|
975
|
+
)
|
|
939
976
|
|
|
940
977
|
def _tool_definitions(self, agent: AgentDefinition) -> tuple[ToolDefinition, ...]:
|
|
941
978
|
definitions = [
|
|
@@ -1145,7 +1182,7 @@ class AgentRuntime:
|
|
|
1145
1182
|
self._require_engine(agent)
|
|
1146
1183
|
memory = await self._memory_state(agent, memory_key)
|
|
1147
1184
|
ledger = self._gateway.ledger
|
|
1148
|
-
|
|
1185
|
+
frame = _Frame(
|
|
1149
1186
|
agent=agent,
|
|
1150
1187
|
messages=list(messages),
|
|
1151
1188
|
alias=agent.model,
|
|
@@ -1155,11 +1192,13 @@ class AgentRuntime:
|
|
|
1155
1192
|
cost_anchor=ledger.cost_usd,
|
|
1156
1193
|
token_anchor=ledger.total_tokens,
|
|
1157
1194
|
)
|
|
1195
|
+
self._bind_message_calls(frame)
|
|
1196
|
+
return frame
|
|
1158
1197
|
|
|
1159
1198
|
async def _frame_from(self, checkpoint: AgentCheckpoint) -> _Frame:
|
|
1160
1199
|
agent = self._spec.agent(checkpoint.agent_id)
|
|
1161
1200
|
memory = await self._memory_state(agent, checkpoint.memory_key)
|
|
1162
|
-
|
|
1201
|
+
frame = _Frame(
|
|
1163
1202
|
agent=agent,
|
|
1164
1203
|
messages=list(checkpoint.messages),
|
|
1165
1204
|
alias=checkpoint.alias or agent.model,
|
|
@@ -1177,6 +1216,36 @@ class AgentRuntime:
|
|
|
1177
1216
|
input_checked=True,
|
|
1178
1217
|
guardrails=list(checkpoint.guardrails),
|
|
1179
1218
|
)
|
|
1219
|
+
# The checkpoint carries the transcript, and the transcript carries the calls,
|
|
1220
|
+
# so the resumed frame re-learns its bindings instead of holding state the
|
|
1221
|
+
# checkpoint would have to duplicate -- and duplicate *unredacted*.
|
|
1222
|
+
self._bind_message_calls(frame)
|
|
1223
|
+
return frame
|
|
1224
|
+
|
|
1225
|
+
def _bind_message_calls(self, frame: _Frame) -> None:
|
|
1226
|
+
"""Bind the declared names against every tool call the transcript carries."""
|
|
1227
|
+
if not self._spec.redact:
|
|
1228
|
+
return
|
|
1229
|
+
for message in frame.messages:
|
|
1230
|
+
self._bind_calls(frame, message.tool_calls)
|
|
1231
|
+
|
|
1232
|
+
def _bind_calls(self, frame: _Frame, calls: Sequence[ToolCall]) -> None:
|
|
1233
|
+
"""Grow the frame's bindings from the arguments the model composed.
|
|
1234
|
+
|
|
1235
|
+
A tool call's arguments are keyed by field name, which is exactly what a redact
|
|
1236
|
+
set names and what prose cannot supply. Pairs already bound are left alone, but a
|
|
1237
|
+
*new* value for an already-bound name is added: two customers' addresses in one
|
|
1238
|
+
run are two values to strip, and keeping only the first would leave the second
|
|
1239
|
+
in every copy recorded after it appeared.
|
|
1240
|
+
"""
|
|
1241
|
+
if not self._spec.redact:
|
|
1242
|
+
return
|
|
1243
|
+
known = set(frame.redactions)
|
|
1244
|
+
for call in calls:
|
|
1245
|
+
for pair in bind_redactions(self._spec.redact, call.arguments):
|
|
1246
|
+
if pair not in known:
|
|
1247
|
+
frame.redactions.append(pair)
|
|
1248
|
+
known.add(pair)
|
|
1180
1249
|
|
|
1181
1250
|
async def _memory_state(self, agent: AgentDefinition, memory_key: str) -> _MemoryState:
|
|
1182
1251
|
thread: ThreadMemory | None = None
|
{aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/providers/__init__.py
RENAMED
|
@@ -35,6 +35,7 @@ from aid_runtime.providers.http import DEFAULT_BASE_URL, OpenAICompatibleProvide
|
|
|
35
35
|
from aid_runtime.providers.recorded import (
|
|
36
36
|
RecordedProvider,
|
|
37
37
|
RecordingProvider,
|
|
38
|
+
RecordingProviders,
|
|
38
39
|
ReplayDivergenceError,
|
|
39
40
|
Transcript,
|
|
40
41
|
TranscriptEntry,
|
|
@@ -65,6 +66,7 @@ __all__ = [
|
|
|
65
66
|
"Provider",
|
|
66
67
|
"RecordedProvider",
|
|
67
68
|
"RecordingProvider",
|
|
69
|
+
"RecordingProviders",
|
|
68
70
|
"ReplayDivergenceError",
|
|
69
71
|
"ScriptedTurn",
|
|
70
72
|
"Transcript",
|
{aid_runtime_python-0.1.164 → aid_runtime_python-0.1.166}/src/aid_runtime/providers/recorded.py
RENAMED
|
@@ -18,13 +18,21 @@ the request it is handed. A prompt edit, a changed tool result or a reordered st
|
|
|
18
18
|
that digest, and the run stops with the call index and the first differing message instead
|
|
19
19
|
of quietly serving an answer to a question nobody asked. The alternative -- matching on
|
|
20
20
|
content -- would turn a diverged run into a permissive one.
|
|
21
|
+
|
|
22
|
+
Recording is the other half, and it is never automatic: a suite that recorded itself would
|
|
23
|
+
gate the build on whatever the model did on the day it ran, so capture happens only when a
|
|
24
|
+
run is asked to capture. :class:`RecordingProvider` wraps one live provider;
|
|
25
|
+
:class:`RecordingProviders` wraps the whole provider mapping, because the gateway picks a
|
|
26
|
+
provider per model and a run that fell back between vendors would otherwise leave the
|
|
27
|
+
fallback out of the file. Either way what is written is a :class:`Transcript` -- the same
|
|
28
|
+
shape replay reads, so there is one format and one digest, not two.
|
|
21
29
|
"""
|
|
22
30
|
|
|
23
31
|
from __future__ import annotations
|
|
24
32
|
|
|
25
33
|
import hashlib
|
|
26
34
|
import json
|
|
27
|
-
from collections.abc import AsyncIterator, Sequence
|
|
35
|
+
from collections.abc import AsyncIterator, Mapping, Sequence
|
|
28
36
|
from pathlib import Path
|
|
29
37
|
from typing import Any
|
|
30
38
|
|
|
@@ -46,6 +54,7 @@ from aid_runtime.types import (
|
|
|
46
54
|
__all__ = [
|
|
47
55
|
"RecordedProvider",
|
|
48
56
|
"RecordingProvider",
|
|
57
|
+
"RecordingProviders",
|
|
49
58
|
"ReplayDivergenceError",
|
|
50
59
|
"Transcript",
|
|
51
60
|
"TranscriptEntry",
|
|
@@ -107,6 +116,8 @@ class Transcript(BaseModel):
|
|
|
107
116
|
model_config = ConfigDict(frozen=True, extra="forbid")
|
|
108
117
|
|
|
109
118
|
provider: str
|
|
119
|
+
#: One vendor, or several comma-joined when the capture spanned a fallback. `model`
|
|
120
|
+
#: follows the same rule, because one run can answer under more than one model.
|
|
110
121
|
model: str
|
|
111
122
|
#: The spec version the recording was made under. A transcript is evidence about a
|
|
112
123
|
#: particular document, so a bump that changes what an eval runs should prompt a
|
|
@@ -256,19 +267,65 @@ class RecordedProvider:
|
|
|
256
267
|
)
|
|
257
268
|
|
|
258
269
|
|
|
270
|
+
class _Recorder:
|
|
271
|
+
"""The calls the wrapped providers answered, kept as one transcript.
|
|
272
|
+
|
|
273
|
+
Shared by every provider a :class:`RecordingProviders` wraps. The two names it collects
|
|
274
|
+
are comma-joined rather than last-wins, because a capture that spanned a fallback would
|
|
275
|
+
otherwise describe itself as the one vendor it happened to call last.
|
|
276
|
+
"""
|
|
277
|
+
|
|
278
|
+
def __init__(self, spec_version: str) -> None:
|
|
279
|
+
self.spec_version = spec_version
|
|
280
|
+
self.entries: list[TranscriptEntry] = []
|
|
281
|
+
self._providers: list[str] = []
|
|
282
|
+
self._models: list[str] = []
|
|
283
|
+
|
|
284
|
+
def note(self, *, provider: str, model: str) -> None:
|
|
285
|
+
if provider and provider not in self._providers:
|
|
286
|
+
self._providers.append(provider)
|
|
287
|
+
if model and model not in self._models:
|
|
288
|
+
self._models.append(model)
|
|
289
|
+
|
|
290
|
+
def append(self, entry: TranscriptEntry, *, provider: str, model: str) -> None:
|
|
291
|
+
self.note(provider=provider, model=model)
|
|
292
|
+
self.entries.append(entry)
|
|
293
|
+
|
|
294
|
+
def transcript(self) -> Transcript:
|
|
295
|
+
return Transcript(
|
|
296
|
+
provider=",".join(self._providers),
|
|
297
|
+
model=",".join(self._models),
|
|
298
|
+
spec_version=self.spec_version,
|
|
299
|
+
entries=tuple(self.entries),
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
|
|
259
303
|
class RecordingProvider:
|
|
260
304
|
"""Wraps a live provider and keeps every exchange, so a run can be replayed offline.
|
|
261
305
|
|
|
262
306
|
Recording is opt-in and explicit. Nothing here is enabled by an eval run that merely
|
|
263
307
|
happens to have a network connection: a suite that recorded itself would gate the
|
|
264
308
|
build on whatever the model did on the day it ran.
|
|
309
|
+
|
|
310
|
+
`recorder` shares the capture with the other providers of the same run, which is what
|
|
311
|
+
:class:`RecordingProviders` uses; given one, `spec_version` is the recorder's.
|
|
265
312
|
"""
|
|
266
313
|
|
|
267
|
-
def __init__(
|
|
314
|
+
def __init__(
|
|
315
|
+
self,
|
|
316
|
+
inner: Provider,
|
|
317
|
+
*,
|
|
318
|
+
spec_version: str = "",
|
|
319
|
+
recorder: _Recorder | None = None,
|
|
320
|
+
) -> None:
|
|
268
321
|
self._inner = inner
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
322
|
+
if recorder is None:
|
|
323
|
+
self._recorder = _Recorder(spec_version)
|
|
324
|
+
# Named here rather than only on the first call, so an empty recorder still
|
|
325
|
+
# says what it was going to record.
|
|
326
|
+
self._recorder.note(provider=str(inner.name), model="")
|
|
327
|
+
else:
|
|
328
|
+
self._recorder = recorder
|
|
272
329
|
|
|
273
330
|
@property
|
|
274
331
|
def name(self) -> str:
|
|
@@ -280,27 +337,28 @@ class RecordingProvider:
|
|
|
280
337
|
|
|
281
338
|
@property
|
|
282
339
|
def entries(self) -> tuple[TranscriptEntry, ...]:
|
|
283
|
-
return tuple(self.
|
|
340
|
+
return tuple(self._recorder.entries)
|
|
284
341
|
|
|
285
342
|
def transcript(self) -> Transcript:
|
|
286
|
-
return
|
|
287
|
-
provider=self.name,
|
|
288
|
-
model=self._model,
|
|
289
|
-
spec_version=self._spec_version,
|
|
290
|
-
entries=tuple(self._entries),
|
|
291
|
-
)
|
|
343
|
+
return self._recorder.transcript()
|
|
292
344
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
345
|
+
def _record(
|
|
346
|
+
self, request: CompletionRequest, response: CompletionResponse, *, model: ModelSpec
|
|
347
|
+
) -> None:
|
|
296
348
|
user = next((message.content for message in request.messages if message.role == "user"), "")
|
|
297
|
-
self.
|
|
349
|
+
self._recorder.append(
|
|
298
350
|
TranscriptEntry(
|
|
299
351
|
request_digest=_digest(request.messages),
|
|
300
352
|
response=response,
|
|
301
353
|
prompt_preview=user[:200],
|
|
302
|
-
)
|
|
354
|
+
),
|
|
355
|
+
provider=self.name,
|
|
356
|
+
model=model.name,
|
|
303
357
|
)
|
|
358
|
+
|
|
359
|
+
async def complete(self, request: CompletionRequest, *, model: ModelSpec) -> CompletionResponse:
|
|
360
|
+
response = await self._inner.complete(request, model=model)
|
|
361
|
+
self._record(request, response, model=model)
|
|
304
362
|
return response
|
|
305
363
|
|
|
306
364
|
async def stream(
|
|
@@ -318,25 +376,49 @@ class RecordingProvider:
|
|
|
318
376
|
(chunk.finish_reason for chunk in reversed(chunks) if chunk.finish_reason is not None),
|
|
319
377
|
"stop",
|
|
320
378
|
)
|
|
321
|
-
self.
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
if usage is not None
|
|
332
|
-
else TokenUsage(input_tokens=0, output_tokens=0),
|
|
333
|
-
finish_reason=finish,
|
|
334
|
-
),
|
|
335
|
-
prompt_preview=user[:200],
|
|
336
|
-
)
|
|
379
|
+
self._record(
|
|
380
|
+
request,
|
|
381
|
+
CompletionResponse(
|
|
382
|
+
text=text,
|
|
383
|
+
model=model.name,
|
|
384
|
+
provider=self.name,
|
|
385
|
+
usage=usage if usage is not None else TokenUsage(input_tokens=0, output_tokens=0),
|
|
386
|
+
finish_reason=finish,
|
|
387
|
+
),
|
|
388
|
+
model=model,
|
|
337
389
|
)
|
|
338
390
|
for chunk in chunks:
|
|
339
391
|
yield chunk
|
|
340
392
|
|
|
341
393
|
async def aclose(self) -> None:
|
|
342
394
|
return None
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
class RecordingProviders:
|
|
398
|
+
"""Wraps every provider a run could call, so one capture covers the whole run.
|
|
399
|
+
|
|
400
|
+
`default_providers()` is keyed by provider name because the gateway selects a provider
|
|
401
|
+
per model, so wrapping a single entry would leave a fallback -- or a second agent on a
|
|
402
|
+
different vendor -- uncaptured, and the recording would silently replay as a shorter
|
|
403
|
+
run. This wraps the mapping instead and keys each wrapper the way the gateway expects.
|
|
404
|
+
"""
|
|
405
|
+
|
|
406
|
+
def __init__(self, providers: Mapping[str, Provider], *, spec_version: str = "") -> None:
|
|
407
|
+
if not providers:
|
|
408
|
+
raise EvalError(
|
|
409
|
+
"there is no model provider to record: a capture of nothing would produce a "
|
|
410
|
+
"transcript that replays no call, so point the agent at a model before "
|
|
411
|
+
"recording one"
|
|
412
|
+
)
|
|
413
|
+
self._recorder = _Recorder(spec_version)
|
|
414
|
+
self._wrapped = {
|
|
415
|
+
name: RecordingProvider(provider, recorder=self._recorder)
|
|
416
|
+
for name, provider in providers.items()
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
@property
|
|
420
|
+
def providers(self) -> dict[str, Provider]:
|
|
421
|
+
return dict(self._wrapped)
|
|
422
|
+
|
|
423
|
+
def transcript(self) -> Transcript:
|
|
424
|
+
return self._recorder.transcript()
|