aid-runtime-python 0.1.164__tar.gz → 0.1.165__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.165}/PKG-INFO +1 -1
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/pyproject.toml +1 -1
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/__init__.py +3 -2
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/agents/chat_model.py +34 -1
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/agents/deep_agents.py +9 -2
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/agents/ir.py +22 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/agents/loop.py +78 -9
- aid_runtime_python-0.1.165/src/aid_runtime/redaction.py +92 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime_python.egg-info/PKG-INFO +1 -1
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime_python.egg-info/SOURCES.txt +1 -0
- aid_runtime_python-0.1.165/tests/test_agents_redaction.py +167 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/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.165}/README.md +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/setup.cfg +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/agents/__init__.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/agents/engine.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/agents/guardrails.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/agents/managed.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/agents/memory.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/agents/policy.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/agents/resume.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/agents/state.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/cache.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/concurrency.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/control.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/cost.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/decisions.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/errors.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/evals/__init__.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/evals/agent_runner.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/evals/dataset.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/evals/gate.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/evals/metrics.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/evals/predicate.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/evals/runner.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/evals/trajectory.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/gateway.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/local_trace.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/metrics.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/pipeline.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/prompts.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/providers/__init__.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/providers/anthropic.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/providers/base.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/providers/bedrock.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/providers/fake.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/providers/gemini.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/providers/gemini_wire.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/providers/http.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/providers/recorded.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/providers/vertex.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/py.typed +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/retrieval/__init__.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/retrieval/chunking.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/retrieval/citations.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/retrieval/connectors.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/retrieval/embedding.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/retrieval/filters.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/retrieval/gate.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/retrieval/hybrid.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/retrieval/knowledge_base.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/retrieval/metrics.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/retrieval/pgvector.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/retrieval/rerank.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/retrieval/retriever.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/retrieval/stores.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/retrieval/types.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/steps.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/structured.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/telemetry.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/tools.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/tracing.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime/types.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime_python.egg-info/dependency_links.txt +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime_python.egg-info/requires.txt +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime_python.egg-info/top_level.txt +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_agent_eval_runner.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_agents_budget.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_agents_checkpoint_integrity.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_agents_deep_agents.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_agents_hitl.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_agents_loop.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_agents_memory.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_anthropic_provider.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_bedrock_provider.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_cache.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_concurrency.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_control.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_cost.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_dataset.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_decisions.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_evals.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_evals_assert_gate.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_evals_budgets.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_evals_decision.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_evals_gate.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_evals_predicate.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_evals_trajectory.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_gateway.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_gemini_provider.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_guardrails.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_guardrails_managed.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_guardrails_model_armor.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_http_provider.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_local_trace.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_metrics.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_package.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_pipeline.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_prompts.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_recorded_provider.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_retrieval_chunking.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_retrieval_citations.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_retrieval_connectors.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_retrieval_embedding.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_retrieval_filters.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_retrieval_gate.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_retrieval_hybrid.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_retrieval_knowledge_base.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_retrieval_metrics.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_retrieval_rerank.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_retrieval_stores.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_retrieval_types.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_steps.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_streaming.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_structured.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_telemetry.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_tool_permissions.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_tools.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_tracing.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/tests/test_types.py +0 -0
- {aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/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.165
|
|
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.165"
|
|
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"
|
|
@@ -207,7 +207,7 @@ from aid_runtime.providers import (
|
|
|
207
207
|
default_bedrock_base_url,
|
|
208
208
|
default_vertex_base_url,
|
|
209
209
|
)
|
|
210
|
-
from aid_runtime.redaction import REDACTED_FORMAT, redact_values
|
|
210
|
+
from aid_runtime.redaction import REDACTED_FORMAT, bind_redactions, redact_values
|
|
211
211
|
from aid_runtime.retrieval import (
|
|
212
212
|
DEFAULT_CANDIDATE_FACTOR,
|
|
213
213
|
DEFAULT_SYNC_TIMEOUT_SECONDS,
|
|
@@ -356,7 +356,7 @@ from aid_runtime.types import (
|
|
|
356
356
|
)
|
|
357
357
|
|
|
358
358
|
#: Kept in sync with ``pyproject.toml`` by a test, so the two cannot drift.
|
|
359
|
-
__version__ = "0.1.
|
|
359
|
+
__version__ = "0.1.165"
|
|
360
360
|
|
|
361
361
|
__all__ = [
|
|
362
362
|
"AGENT_LABEL",
|
|
@@ -596,6 +596,7 @@ __all__ = [
|
|
|
596
596
|
"agent_span",
|
|
597
597
|
"aid_attributes",
|
|
598
598
|
"assemble_context",
|
|
599
|
+
"bind_redactions",
|
|
599
600
|
"binding_from_managed_spec",
|
|
600
601
|
"binding_from_spec",
|
|
601
602
|
"bm25_scores",
|
{aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/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.165}/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
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""Value-bound redaction for recorded traces.
|
|
2
|
+
|
|
3
|
+
``observability.redact`` names *fields*, and a field name cannot be stripped out of
|
|
4
|
+
prose. What can be stripped is a **value**: the moment a prompt is rendered, the
|
|
5
|
+
runtime knows which variable supplied which substring, so a name in the redact set
|
|
6
|
+
becomes an exact value to remove from the copy that is written to a trace.
|
|
7
|
+
|
|
8
|
+
Redaction applies to the recorded copy only. The model still receives what the
|
|
9
|
+
application sent, because editing a request would change the answer and a framework
|
|
10
|
+
that silently rewrote one could not honestly report what it ran.
|
|
11
|
+
|
|
12
|
+
An agent run has no render, so it has no interpolation to learn values from. It binds
|
|
13
|
+
them from the structured records it handles instead -- see :func:`bind_redactions` --
|
|
14
|
+
and the loop hands the result to the gateway, which is the one place that writes model
|
|
15
|
+
text to a trace. Free text the caller sent carries no field name, so a value that
|
|
16
|
+
appears only there is not bound and the limit is stated wherever the guarantee is.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from collections.abc import Iterable, Mapping, Sequence
|
|
22
|
+
from typing import Any
|
|
23
|
+
|
|
24
|
+
__all__ = ["REDACTED_FORMAT", "bind_redactions", "redact_values"]
|
|
25
|
+
|
|
26
|
+
#: What replaces a stripped value. The field name, not the value, so a trace reader
|
|
27
|
+
#: can still see that a field was present and which one it was.
|
|
28
|
+
REDACTED_FORMAT = "[redacted:{name}]"
|
|
29
|
+
|
|
30
|
+
#: One ``(name, value)`` pair bound when a prompt was rendered.
|
|
31
|
+
Redaction = tuple[str, str]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _usable(pairs: Iterable[Redaction]) -> list[Redaction]:
|
|
35
|
+
"""The pairs that can be applied at all.
|
|
36
|
+
|
|
37
|
+
A blank value is dropped rather than replaced: ``str.replace("", marker)``
|
|
38
|
+
inserts a marker at every position, so an empty variable would destroy the
|
|
39
|
+
text it was meant to protect instead of protecting it.
|
|
40
|
+
"""
|
|
41
|
+
return [(name, value) for name, value in pairs if value.strip() != ""]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def bind_redactions(names: Iterable[str], payload: Any) -> tuple[Redaction, ...]:
|
|
45
|
+
"""Bind declared field names to the string values a structured payload carries.
|
|
46
|
+
|
|
47
|
+
This is the agent path's equivalent of a render. A pipeline learns a value from the
|
|
48
|
+
variables it interpolated; an agent loop has no interpolation, so it learns values
|
|
49
|
+
from the structured records it handles -- the arguments of the tool calls the model
|
|
50
|
+
composed, recursing into nested objects and lists. What comes back is the same
|
|
51
|
+
``(name, value)`` pair the gateway already knows how to strip from a recorded copy.
|
|
52
|
+
|
|
53
|
+
Only strings are bound. A field holding a number or a boolean has no text to match
|
|
54
|
+
in prose, and binding ``"1"`` would rewrite every digit in the transcript instead of
|
|
55
|
+
protecting one field.
|
|
56
|
+
|
|
57
|
+
A name may bind more than one value. Two customers' addresses in one long run are
|
|
58
|
+
two pairs with the same name, and both are stripped: keeping only the first would
|
|
59
|
+
leave the second in every copy recorded after it appeared.
|
|
60
|
+
"""
|
|
61
|
+
wanted = frozenset(names)
|
|
62
|
+
if not wanted:
|
|
63
|
+
return ()
|
|
64
|
+
bound: list[Redaction] = []
|
|
65
|
+
_bind_into(wanted, payload, bound)
|
|
66
|
+
return tuple(bound)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _bind_into(wanted: frozenset[str], payload: Any, bound: list[Redaction]) -> None:
|
|
70
|
+
if isinstance(payload, Mapping):
|
|
71
|
+
for key, value in payload.items():
|
|
72
|
+
if isinstance(key, str) and key in wanted and isinstance(value, str):
|
|
73
|
+
pair = (key, value)
|
|
74
|
+
if value.strip() != "" and pair not in bound:
|
|
75
|
+
bound.append(pair)
|
|
76
|
+
else:
|
|
77
|
+
_bind_into(wanted, value, bound)
|
|
78
|
+
elif isinstance(payload, (list, tuple)):
|
|
79
|
+
for item in payload:
|
|
80
|
+
_bind_into(wanted, item, bound)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def redact_values(text: str, pairs: Sequence[Redaction]) -> str:
|
|
84
|
+
"""Replace every occurrence of a bound value with ``[redacted:name]``."""
|
|
85
|
+
if not text or not pairs:
|
|
86
|
+
return text
|
|
87
|
+
redacted = text
|
|
88
|
+
# Longest value first: where one value contains another, the shorter pass would
|
|
89
|
+
# otherwise leave a fragment of the longer one on either side of its marker.
|
|
90
|
+
for name, value in sorted(_usable(pairs), key=lambda pair: len(pair[1]), reverse=True):
|
|
91
|
+
redacted = redacted.replace(value, REDACTED_FORMAT.format(name=name))
|
|
92
|
+
return redacted
|
{aid_runtime_python-0.1.164 → aid_runtime_python-0.1.165}/src/aid_runtime_python.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aid-runtime-python
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.165
|
|
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
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"""Redacting an agent run: the boundary the loop does not have, and the one it does.
|
|
2
|
+
|
|
3
|
+
A pipeline redacts where it renders. An agent run never renders, so the loop binds the
|
|
4
|
+
same field names somewhere else: every tool call arrives as a mapping keyed by declared
|
|
5
|
+
argument names, and the gateway -- the only code that writes model text to a span --
|
|
6
|
+
redacts the copy it records with whatever bindings the request carries.
|
|
7
|
+
|
|
8
|
+
These assertions are about the *recorded* copy. The model must keep receiving the real
|
|
9
|
+
value, because redaction is a recording decision; and a value that enters only through
|
|
10
|
+
free text is recorded as written, because no field name matches prose. That second
|
|
11
|
+
assertion is the limit, tested rather than described, so it cannot quietly turn into a
|
|
12
|
+
claim that nothing leaks.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
import pytest
|
|
20
|
+
from opentelemetry.sdk.trace import TracerProvider
|
|
21
|
+
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
|
|
22
|
+
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
|
|
23
|
+
from opentelemetry.trace import Tracer
|
|
24
|
+
|
|
25
|
+
from agent_support import ADMIN_ONLY, build, solo, tool_def
|
|
26
|
+
from aid_runtime import ATTRIBUTES, ScriptedTurn, Tool
|
|
27
|
+
from aid_runtime.agents import HumanDecision, Principal, RunStatus
|
|
28
|
+
from aid_runtime.tracing import CONTENT_ENV
|
|
29
|
+
|
|
30
|
+
EMAIL = "ada@example.com"
|
|
31
|
+
QUESTION = "Refund this order."
|
|
32
|
+
|
|
33
|
+
#: A tool whose single argument is named after the field the document withholds. The name
|
|
34
|
+
#: is what binds: the loop reads it off the call, not off the tool.
|
|
35
|
+
EMAIL_SCHEMA: dict[str, Any] = {
|
|
36
|
+
"type": "object",
|
|
37
|
+
"properties": {"email": {"type": "string"}},
|
|
38
|
+
"required": ["email"],
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _email_tool() -> Tool:
|
|
43
|
+
def handler(email: str = "") -> str:
|
|
44
|
+
return f"notified:{email}"
|
|
45
|
+
|
|
46
|
+
return Tool.of("notify", handler, description="notify a customer", parameters=EMAIL_SCHEMA)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _document(*, hitl: bool = False) -> dict[str, Any]:
|
|
50
|
+
agent_fields: dict[str, Any] = {"tools": ["t1"]}
|
|
51
|
+
if hitl:
|
|
52
|
+
agent_fields["hitl"] = {"when": ADMIN_ONLY, "channel": "ops"}
|
|
53
|
+
doc = solo(
|
|
54
|
+
prompt="You are a helpful assistant.",
|
|
55
|
+
tool_specs=[tool_def("t1", "notify")],
|
|
56
|
+
**agent_fields,
|
|
57
|
+
)
|
|
58
|
+
doc["observability"] = {"redact": ["email"]}
|
|
59
|
+
return doc
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@pytest.fixture
|
|
63
|
+
def captured(monkeypatch: pytest.MonkeyPatch) -> InMemorySpanExporter:
|
|
64
|
+
"""Record payloads, and route the gateway's spans into this test's exporter.
|
|
65
|
+
|
|
66
|
+
Content is off by default and the gateway resolves a process-wide tracer, so both
|
|
67
|
+
have to be arranged for a test that is about what a span keeps.
|
|
68
|
+
"""
|
|
69
|
+
monkeypatch.setenv(CONTENT_ENV, "1")
|
|
70
|
+
exporter = InMemorySpanExporter()
|
|
71
|
+
provider = TracerProvider()
|
|
72
|
+
provider.add_span_processor(SimpleSpanProcessor(exporter))
|
|
73
|
+
tracer: Tracer = provider.get_tracer("aid-runtime-tests")
|
|
74
|
+
monkeypatch.setattr("aid_runtime.gateway.get_tracer", lambda name=None: tracer)
|
|
75
|
+
return exporter
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _recorded_content(exporter: InMemorySpanExporter) -> list[str]:
|
|
79
|
+
"""Every recorded payload, as the trace wrote it."""
|
|
80
|
+
texts: list[str] = []
|
|
81
|
+
for span in exporter.get_finished_spans():
|
|
82
|
+
attributes = dict(span.attributes or {})
|
|
83
|
+
texts.append(str(attributes.get(ATTRIBUTES["input_text"], "")))
|
|
84
|
+
texts.append(str(attributes.get(ATTRIBUTES["output_text"], "")))
|
|
85
|
+
return [text for text in texts if text]
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
async def test_a_tool_argument_is_withheld_from_the_recorded_copy(
|
|
89
|
+
captured: InMemorySpanExporter,
|
|
90
|
+
) -> None:
|
|
91
|
+
"""The value travels through a declared argument name, so the loop can bind it."""
|
|
92
|
+
harness = build(
|
|
93
|
+
_document(),
|
|
94
|
+
tools=[_email_tool()],
|
|
95
|
+
script=[
|
|
96
|
+
ScriptedTurn.tool("notify", {"email": EMAIL}),
|
|
97
|
+
ScriptedTurn.answer("notified"),
|
|
98
|
+
],
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
result = await harness.runtime.run("solo", QUESTION)
|
|
102
|
+
|
|
103
|
+
assert result.status is RunStatus.COMPLETED
|
|
104
|
+
recorded = _recorded_content(captured)
|
|
105
|
+
assert recorded, "the run recorded no content, so nothing was tested"
|
|
106
|
+
assert all(EMAIL not in text for text in recorded)
|
|
107
|
+
assert any("[redacted:email]" in text for text in recorded)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
async def test_the_model_still_receives_the_value_it_must_act_on() -> None:
|
|
111
|
+
"""Redaction is a recording decision: the provider call is untouched."""
|
|
112
|
+
harness = build(
|
|
113
|
+
_document(),
|
|
114
|
+
tools=[_email_tool()],
|
|
115
|
+
script=[
|
|
116
|
+
ScriptedTurn.tool("notify", {"email": EMAIL}),
|
|
117
|
+
ScriptedTurn.answer("notified"),
|
|
118
|
+
],
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
await harness.runtime.run("solo", QUESTION)
|
|
122
|
+
|
|
123
|
+
# The second request replays the tool call, which is where the value appears.
|
|
124
|
+
replayed = harness.provider.calls[1].messages
|
|
125
|
+
call = next(message for message in replayed if message.tool_calls).tool_calls[0]
|
|
126
|
+
assert call.arguments == {"email": EMAIL}
|
|
127
|
+
assert harness.provider.calls[1].redactions == (("email", EMAIL),)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
async def test_a_value_that_appears_only_in_free_text_is_recorded_as_written(
|
|
131
|
+
captured: InMemorySpanExporter,
|
|
132
|
+
) -> None:
|
|
133
|
+
"""The stated limit, asserted: no declared name matches prose, so nothing binds."""
|
|
134
|
+
harness = build(
|
|
135
|
+
_document(),
|
|
136
|
+
tools=[_email_tool()],
|
|
137
|
+
script=[ScriptedTurn.answer("noted")],
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
await harness.runtime.run("solo", f"the customer is {EMAIL}")
|
|
141
|
+
|
|
142
|
+
assert harness.provider.calls[0].redactions == ()
|
|
143
|
+
assert any(EMAIL in text for text in _recorded_content(captured))
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
async def test_a_resumed_run_relearns_bindings_from_the_checkpoint_transcript(
|
|
147
|
+
captured: InMemorySpanExporter,
|
|
148
|
+
) -> None:
|
|
149
|
+
"""A pause hands the caller a checkpoint, so the bindings must be re-derived."""
|
|
150
|
+
admin = Principal(roles=frozenset({"admin"}))
|
|
151
|
+
harness = build(
|
|
152
|
+
_document(hitl=True),
|
|
153
|
+
tools=[_email_tool()],
|
|
154
|
+
script=[
|
|
155
|
+
ScriptedTurn.tool("notify", {"email": EMAIL}),
|
|
156
|
+
ScriptedTurn.answer("notified"),
|
|
157
|
+
],
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
paused = await harness.runtime.run("solo", QUESTION, principal=admin)
|
|
161
|
+
assert paused.checkpoint is not None
|
|
162
|
+
resumed = await harness.runtime.resume(paused.checkpoint, HumanDecision.APPROVE)
|
|
163
|
+
|
|
164
|
+
assert resumed.status is RunStatus.COMPLETED
|
|
165
|
+
recorded = _recorded_content(captured)
|
|
166
|
+
assert recorded, "the resume recorded no content, so nothing was tested"
|
|
167
|
+
assert all(EMAIL not in text for text in recorded)
|