aid-runtime-python 0.1.111__tar.gz → 0.1.112__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.111 → aid_runtime_python-0.1.112}/PKG-INFO +1 -1
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/pyproject.toml +1 -1
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/__init__.py +1 -1
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/agents/deep_agents.py +3 -3
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/agents/guardrails.py +21 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/agents/ir.py +51 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/agents/loop.py +12 -10
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime_python.egg-info/PKG-INFO +1 -1
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_guardrails.py +45 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/README.md +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/setup.cfg +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/agents/__init__.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/agents/chat_model.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/agents/engine.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/agents/managed.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/agents/memory.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/agents/policy.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/agents/state.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/cache.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/concurrency.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/control.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/cost.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/decisions.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/errors.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/evals/__init__.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/evals/dataset.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/evals/gate.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/evals/metrics.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/evals/predicate.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/evals/runner.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/gateway.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/local_trace.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/pipeline.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/prompts.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/providers/__init__.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/providers/anthropic.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/providers/base.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/providers/bedrock.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/providers/fake.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/providers/gemini.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/providers/gemini_wire.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/providers/http.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/providers/vertex.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/py.typed +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/__init__.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/chunking.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/citations.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/connectors.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/embedding.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/gate.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/hybrid.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/knowledge_base.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/metrics.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/pgvector.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/rerank.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/retriever.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/stores.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/types.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/steps.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/structured.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/tools.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/tracing.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/types.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime_python.egg-info/SOURCES.txt +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime_python.egg-info/dependency_links.txt +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime_python.egg-info/requires.txt +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime_python.egg-info/top_level.txt +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_agents_budget.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_agents_deep_agents.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_agents_hitl.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_agents_loop.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_agents_memory.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_anthropic_provider.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_bedrock_provider.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_cache.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_concurrency.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_control.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_cost.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_dataset.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_decisions.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_evals.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_evals_assert_gate.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_evals_decision.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_evals_gate.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_evals_predicate.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_gateway.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_gemini_provider.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_guardrails_managed.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_guardrails_model_armor.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_http_provider.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_local_trace.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_package.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_pipeline.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_prompts.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_retrieval_chunking.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_retrieval_citations.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_retrieval_connectors.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_retrieval_embedding.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_retrieval_gate.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_retrieval_hybrid.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_retrieval_knowledge_base.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_retrieval_metrics.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_retrieval_rerank.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_retrieval_stores.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_retrieval_types.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_steps.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_streaming.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_structured.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_tool_permissions.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_tools.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_tracing.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_types.py +0 -0
- {aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/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.112
|
|
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.112"
|
|
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"
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/agents/deep_agents.py
RENAMED
|
@@ -114,7 +114,7 @@ class DeepAgentsEngine:
|
|
|
114
114
|
check_engine(agent)
|
|
115
115
|
if not frame.input_checked:
|
|
116
116
|
frame.input_checked = True
|
|
117
|
-
paused = self._runtime._guardrail_text(
|
|
117
|
+
paused = await self._runtime._guardrail_text(
|
|
118
118
|
_GUARDRAIL_INPUT, frame, memory_key, span=span, rewrite=True
|
|
119
119
|
)
|
|
120
120
|
if paused is not None:
|
|
@@ -430,7 +430,7 @@ class DeepAgentsEngine:
|
|
|
430
430
|
self, frame: _Frame, result: Any, *, memory_key: str, span: Span
|
|
431
431
|
) -> _Outcome:
|
|
432
432
|
"""Apply the output guardrail, record memory, and report the answer."""
|
|
433
|
-
released = self._runtime._guardrail_answer(
|
|
433
|
+
released = await self._runtime._guardrail_answer(
|
|
434
434
|
frame, self._answer(result), memory_key, span=span
|
|
435
435
|
)
|
|
436
436
|
if isinstance(released, _Outcome):
|
|
@@ -536,7 +536,7 @@ class _Guardrails(AgentMiddleware):
|
|
|
536
536
|
# branch only has to open the delegate's span.
|
|
537
537
|
return await self._delegate_in_span(request, handler, call)
|
|
538
538
|
runtime._authorize(self._frame.agent, call, self._principal)
|
|
539
|
-
guarded, halted = runtime._guardrail_tool_calls(
|
|
539
|
+
guarded, halted = await runtime._guardrail_tool_calls(
|
|
540
540
|
self._frame, [call], self._memory_key, span=self._record_span
|
|
541
541
|
)
|
|
542
542
|
if halted is not None:
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/agents/guardrails.py
RENAMED
|
@@ -588,6 +588,19 @@ class GuardrailEngine:
|
|
|
588
588
|
) -> GuardrailVerdict:
|
|
589
589
|
return self._check("tool-call", guardrails, dict(arguments), tool_id=tool_id)
|
|
590
590
|
|
|
591
|
+
async def check_tool_call_async(
|
|
592
|
+
self,
|
|
593
|
+
guardrails: Sequence[GuardrailDefinition],
|
|
594
|
+
tool_id: str,
|
|
595
|
+
arguments: Mapping[str, Any],
|
|
596
|
+
) -> GuardrailVerdict:
|
|
597
|
+
"""The ``tool-call`` stage when a guardrail needs a round trip.
|
|
598
|
+
|
|
599
|
+
A managed engine can apply at this stage, and the loop always uses this
|
|
600
|
+
variant: awaiting when no guardrail needs it costs nothing.
|
|
601
|
+
"""
|
|
602
|
+
return await self._check_async("tool-call", guardrails, dict(arguments), tool_id=tool_id)
|
|
603
|
+
|
|
591
604
|
def _check(
|
|
592
605
|
self,
|
|
593
606
|
stage: GuardrailStage,
|
|
@@ -612,6 +625,14 @@ class GuardrailEngine:
|
|
|
612
625
|
stage,
|
|
613
626
|
f"guardrail uses engine {guardrail.engine!r}, which needs the async check",
|
|
614
627
|
)
|
|
628
|
+
if guardrail.decision is not None:
|
|
629
|
+
# Same rule as a managed engine: a synchronous caller cannot await the
|
|
630
|
+
# decision, and skipping it would be an allow nobody declared.
|
|
631
|
+
raise GuardrailBlockedError(
|
|
632
|
+
guardrail.id,
|
|
633
|
+
stage,
|
|
634
|
+
f"guardrail asks decision {guardrail.decision!r}, which needs the async check",
|
|
635
|
+
)
|
|
615
636
|
policies = _firing_policies(guardrail, stage, payload)
|
|
616
637
|
if not policies:
|
|
617
638
|
continue
|
|
@@ -248,6 +248,9 @@ class RuntimeSpec:
|
|
|
248
248
|
tools: Mapping[str, ToolSpec]
|
|
249
249
|
agents: Mapping[str, AgentDefinition]
|
|
250
250
|
guardrails: Mapping[str, GuardrailDefinition] = field(default_factory=dict)
|
|
251
|
+
#: The decisions a guardrail's ``decision`` may name, keyed by id. Resolved here
|
|
252
|
+
#: so the loop's engine can answer one without reading the document again.
|
|
253
|
+
decisions: Mapping[str, DecisionDefinition] = field(default_factory=dict)
|
|
251
254
|
#: The single concurrency cap, read from the IR's ``deployments[].concurrency``.
|
|
252
255
|
#: ``None`` means unbounded: the runtime only shares a limiter when a deployment
|
|
253
256
|
#: declares one, which keeps plain request/response usage free of surprises.
|
|
@@ -330,6 +333,11 @@ def from_ir(document: Mapping[str, Any]) -> RuntimeSpec:
|
|
|
330
333
|
for guardrail_id, entry in _by_id(document.get("guardrails"), "guardrails").items()
|
|
331
334
|
}
|
|
332
335
|
|
|
336
|
+
decisions = {
|
|
337
|
+
decision_id: _decision(decision_id, entry)
|
|
338
|
+
for decision_id, entry in _by_id(document.get("decisions"), "decisions").items()
|
|
339
|
+
}
|
|
340
|
+
|
|
333
341
|
fallbacks: dict[str, tuple[str, ...]] = {}
|
|
334
342
|
for model_id, entry in raw_models.items():
|
|
335
343
|
fallbacks[model_id] = tuple(_str_list(entry.get("fallbacks"), f"model {model_id!r}"))
|
|
@@ -350,6 +358,7 @@ def from_ir(document: Mapping[str, Any]) -> RuntimeSpec:
|
|
|
350
358
|
tools=tools,
|
|
351
359
|
agents=agents,
|
|
352
360
|
guardrails=guardrails,
|
|
361
|
+
decisions=decisions,
|
|
353
362
|
concurrency=_concurrency(document.get("deployments")),
|
|
354
363
|
)
|
|
355
364
|
|
|
@@ -414,6 +423,29 @@ def _agent(
|
|
|
414
423
|
)
|
|
415
424
|
|
|
416
425
|
|
|
426
|
+
def _decision(decision_id: str, entry: Mapping[str, Any]) -> DecisionDefinition:
|
|
427
|
+
"""Resolve one IR decision: the model, the question, and the labels in order.
|
|
428
|
+
|
|
429
|
+
A ``choice`` decision's criteria is a label mapping in the emitter, and a ``score``
|
|
430
|
+
decision's is a list; both reduce to the ordered labels a runtime acts on. Sorted
|
|
431
|
+
keys match the TypeScript runtime, so the two never disagree about a label order.
|
|
432
|
+
"""
|
|
433
|
+
where = f"decision {decision_id!r}"
|
|
434
|
+
criteria = entry.get("criteria")
|
|
435
|
+
if criteria is None:
|
|
436
|
+
labels: tuple[str, ...] = ()
|
|
437
|
+
elif isinstance(criteria, Mapping):
|
|
438
|
+
labels = tuple(sorted(str(label) for label in criteria))
|
|
439
|
+
else:
|
|
440
|
+
labels = tuple(_str_list(criteria, f"{where} criteria"))
|
|
441
|
+
return DecisionDefinition(
|
|
442
|
+
id=decision_id,
|
|
443
|
+
model=_required_str(entry, "model", where),
|
|
444
|
+
instructions=_required_str(entry, "instructions", where),
|
|
445
|
+
criteria=labels,
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
|
|
417
449
|
def _guardrail(
|
|
418
450
|
guardrail_id: str,
|
|
419
451
|
entry: Mapping[str, Any],
|
|
@@ -475,6 +507,22 @@ def _guardrail(
|
|
|
475
507
|
if missing:
|
|
476
508
|
raise ConfigurationError(f"{where} names undeclared tools: {missing}")
|
|
477
509
|
|
|
510
|
+
# A decision guardrail asks a classifier instead of running detectors; without
|
|
511
|
+
# the mapping its labels mean nothing, so the two are parsed together.
|
|
512
|
+
decision = _str(entry.get("decision")) or None
|
|
513
|
+
on_decision: tuple[tuple[str, str], ...] = ()
|
|
514
|
+
min_confidence = 0.0
|
|
515
|
+
if decision is not None:
|
|
516
|
+
raw_map = entry.get("onDecision")
|
|
517
|
+
if raw_map is not None and not isinstance(raw_map, Mapping):
|
|
518
|
+
raise ConfigurationError(f"{where} onDecision must be a mapping of strings")
|
|
519
|
+
on_decision = tuple(
|
|
520
|
+
(label, outcome)
|
|
521
|
+
for label, outcome in (raw_map or {}).items()
|
|
522
|
+
if isinstance(label, str) and isinstance(outcome, str)
|
|
523
|
+
)
|
|
524
|
+
min_confidence = _optional_float(entry.get("minConfidence")) or 0.0
|
|
525
|
+
|
|
478
526
|
on_fail = entry.get("onFail")
|
|
479
527
|
if not isinstance(on_fail, Mapping):
|
|
480
528
|
raise ConfigurationError(f"{where} needs an onFail object")
|
|
@@ -488,6 +536,9 @@ def _guardrail(
|
|
|
488
536
|
message=_required_str(on_fail, "message", f"{where} onFail"),
|
|
489
537
|
fallback_prompt=_str(on_fail.get("fallbackPrompt")),
|
|
490
538
|
log=on_fail.get("log") is True,
|
|
539
|
+
decision=decision,
|
|
540
|
+
on_decision=on_decision,
|
|
541
|
+
min_confidence=min_confidence,
|
|
491
542
|
engine=engine,
|
|
492
543
|
bedrock=bedrock,
|
|
493
544
|
)
|
|
@@ -201,7 +201,7 @@ class AgentRuntime:
|
|
|
201
201
|
memory_store if memory_store is not None else InProcessMemoryStore()
|
|
202
202
|
)
|
|
203
203
|
self._tracer = tracer
|
|
204
|
-
self._guardrails = GuardrailEngine(spec.guardrails)
|
|
204
|
+
self._guardrails = GuardrailEngine(spec.guardrails, decisions=spec.decisions)
|
|
205
205
|
self._tools_by_name: dict[str, ToolSpec] = {
|
|
206
206
|
definition.name: definition for definition in spec.tools.values()
|
|
207
207
|
}
|
|
@@ -451,7 +451,7 @@ class AgentRuntime:
|
|
|
451
451
|
|
|
452
452
|
if not frame.input_checked:
|
|
453
453
|
frame.input_checked = True
|
|
454
|
-
paused = self._guardrail_text(
|
|
454
|
+
paused = await self._guardrail_text(
|
|
455
455
|
_GUARDRAIL_INPUT, frame, memory_key, span=span, rewrite=True
|
|
456
456
|
)
|
|
457
457
|
if paused is not None:
|
|
@@ -475,7 +475,7 @@ class AgentRuntime:
|
|
|
475
475
|
response = generation.response
|
|
476
476
|
|
|
477
477
|
if not response.tool_calls:
|
|
478
|
-
answer = self._guardrail_answer(frame, response.text, memory_key, span=span)
|
|
478
|
+
answer = await self._guardrail_answer(frame, response.text, memory_key, span=span)
|
|
479
479
|
if isinstance(answer, _Outcome):
|
|
480
480
|
return answer
|
|
481
481
|
frame.messages.append(Message.assistant(answer))
|
|
@@ -501,7 +501,7 @@ class AgentRuntime:
|
|
|
501
501
|
|
|
502
502
|
record.kind = StepKind.TOOLS
|
|
503
503
|
record.tool_names = tuple(call.name for call in response.tool_calls)
|
|
504
|
-
guarded, paused = self._guardrail_tool_calls(
|
|
504
|
+
guarded, paused = await self._guardrail_tool_calls(
|
|
505
505
|
frame, response.tool_calls, memory_key, span=span
|
|
506
506
|
)
|
|
507
507
|
if paused is not None:
|
|
@@ -528,7 +528,7 @@ class AgentRuntime:
|
|
|
528
528
|
|
|
529
529
|
frame.messages.extend(await self._observe(agent, guarded, principal))
|
|
530
530
|
|
|
531
|
-
def _guardrail_text(
|
|
531
|
+
async def _guardrail_text(
|
|
532
532
|
self,
|
|
533
533
|
stage: str,
|
|
534
534
|
frame: _Frame,
|
|
@@ -545,7 +545,9 @@ class AgentRuntime:
|
|
|
545
545
|
"""
|
|
546
546
|
index = _last_user_index(frame.messages)
|
|
547
547
|
text = "" if index is None else frame.messages[index].content
|
|
548
|
-
verdict = self._guardrails.
|
|
548
|
+
verdict = await self._guardrails.check_input_async(
|
|
549
|
+
frame.agent.stage_guardrails(stage), text
|
|
550
|
+
)
|
|
549
551
|
self._record_guardrails(frame, verdict, span)
|
|
550
552
|
deciding = verdict.deciding
|
|
551
553
|
if verdict.action == ACTION_BLOCK and deciding is not None:
|
|
@@ -556,7 +558,7 @@ class AgentRuntime:
|
|
|
556
558
|
frame.messages[index] = Message.user(verdict.text)
|
|
557
559
|
return None
|
|
558
560
|
|
|
559
|
-
def _guardrail_answer(
|
|
561
|
+
async def _guardrail_answer(
|
|
560
562
|
self,
|
|
561
563
|
frame: _Frame,
|
|
562
564
|
text: str,
|
|
@@ -570,7 +572,7 @@ class AgentRuntime:
|
|
|
570
572
|
the checkpoint carries the text, so approving it releases this exact answer
|
|
571
573
|
without paying for a second generation.
|
|
572
574
|
"""
|
|
573
|
-
verdict = self._guardrails.
|
|
575
|
+
verdict = await self._guardrails.check_output_async(
|
|
574
576
|
frame.agent.stage_guardrails(_GUARDRAIL_OUTPUT), text
|
|
575
577
|
)
|
|
576
578
|
self._record_guardrails(frame, verdict, span)
|
|
@@ -581,7 +583,7 @@ class AgentRuntime:
|
|
|
581
583
|
return self._guardrail_pause(frame, verdict, memory_key, (), span=span, text=text)
|
|
582
584
|
return verdict.text if verdict.action == ACTION_REDACT else text
|
|
583
585
|
|
|
584
|
-
def _guardrail_tool_calls(
|
|
586
|
+
async def _guardrail_tool_calls(
|
|
585
587
|
self,
|
|
586
588
|
frame: _Frame,
|
|
587
589
|
calls: Sequence[ToolCall],
|
|
@@ -602,7 +604,7 @@ class AgentRuntime:
|
|
|
602
604
|
for call in calls:
|
|
603
605
|
definition = self._tools_by_name.get(call.name)
|
|
604
606
|
tool_id = definition.id if definition is not None else call.name
|
|
605
|
-
verdict = self._guardrails.
|
|
607
|
+
verdict = await self._guardrails.check_tool_call_async(
|
|
606
608
|
frame.agent.stage_guardrails(_GUARDRAIL_TOOL), tool_id, call.arguments
|
|
607
609
|
)
|
|
608
610
|
self._record_guardrails(frame, verdict, span)
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/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.112
|
|
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
|
|
@@ -34,6 +34,7 @@ from aid_runtime.agents import (
|
|
|
34
34
|
RuntimeSpec,
|
|
35
35
|
detect,
|
|
36
36
|
)
|
|
37
|
+
from aid_runtime.agents import guardrails as guardrails_module
|
|
37
38
|
from aid_runtime.agents.ir import from_ir
|
|
38
39
|
from aid_runtime.decisions import DecisionAnswer, DecisionResponse
|
|
39
40
|
from aid_runtime.errors import ConfigurationError
|
|
@@ -1064,3 +1065,47 @@ async def test_policies_run_before_the_decision_so_a_match_costs_no_tokens() ->
|
|
|
1064
1065
|
assert verdict.deciding is not None
|
|
1065
1066
|
assert verdict.deciding.policies == ("prompt-injection",)
|
|
1066
1067
|
assert client.calls == []
|
|
1068
|
+
|
|
1069
|
+
|
|
1070
|
+
# --- the decision seam inside the loop -------------------------------------------
|
|
1071
|
+
|
|
1072
|
+
|
|
1073
|
+
async def test_the_loop_asks_a_decision_and_refuses_before_the_model_runs(
|
|
1074
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
1075
|
+
) -> None:
|
|
1076
|
+
"""The loop, not just the generated pipeline, must consult a decision guardrail.
|
|
1077
|
+
|
|
1078
|
+
Regression pin: the loop used to build its engine without the document's
|
|
1079
|
+
``decisions`` and take the synchronous path, where a decision guardrail was
|
|
1080
|
+
scheduled for a raise but never asked — an allow nobody declared.
|
|
1081
|
+
"""
|
|
1082
|
+
client = FakeDecisionClient(label="off_topic")
|
|
1083
|
+
monkeypatch.setattr(guardrails_module, "DecisionClient", lambda: client)
|
|
1084
|
+
|
|
1085
|
+
doc = solo(
|
|
1086
|
+
guardrail_specs=[
|
|
1087
|
+
guardrail_def(
|
|
1088
|
+
"relevance",
|
|
1089
|
+
policies=(),
|
|
1090
|
+
decision="topical",
|
|
1091
|
+
on_decision=(("product", "allow"), ("off_topic", "block")),
|
|
1092
|
+
min_confidence=0.5,
|
|
1093
|
+
message="This request is outside the assistant scope.",
|
|
1094
|
+
)
|
|
1095
|
+
],
|
|
1096
|
+
decisions=[
|
|
1097
|
+
{
|
|
1098
|
+
"id": "topical",
|
|
1099
|
+
"model": "jev-1.14.0",
|
|
1100
|
+
"instructions": "Is this message about our product",
|
|
1101
|
+
"criteria": ["off_topic", "product"],
|
|
1102
|
+
}
|
|
1103
|
+
],
|
|
1104
|
+
)
|
|
1105
|
+
harness = build(doc, script=[ScriptedTurn.answer("never reached")])
|
|
1106
|
+
|
|
1107
|
+
with pytest.raises(GuardrailBlockedError, match="outside the assistant scope"):
|
|
1108
|
+
await harness.runtime.run("solo", CLEAN)
|
|
1109
|
+
|
|
1110
|
+
assert [call["state"] for call in client.calls] == [CLEAN]
|
|
1111
|
+
assert harness.provider.calls == []
|
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/agents/__init__.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/agents/chat_model.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/evals/predicate.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/providers/__init__.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/providers/anthropic.py
RENAMED
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/providers/bedrock.py
RENAMED
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/providers/gemini.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/providers/gemini_wire.py
RENAMED
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/providers/vertex.py
RENAMED
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/__init__.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/chunking.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/citations.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/connectors.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/embedding.py
RENAMED
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/hybrid.py
RENAMED
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/metrics.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/pgvector.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/rerank.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/retriever.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/stores.py
RENAMED
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/src/aid_runtime/retrieval/types.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_guardrails_model_armor.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_retrieval_connectors.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aid_runtime_python-0.1.111 → aid_runtime_python-0.1.112}/tests/test_retrieval_knowledge_base.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|