aid-runtime-python 0.1.175__tar.gz → 0.1.177__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.175 → aid_runtime_python-0.1.177}/PKG-INFO +1 -1
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/pyproject.toml +1 -1
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/__init__.py +1 -1
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/agents/__init__.py +4 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/agents/deep_agents.py +22 -8
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/agents/loop.py +47 -20
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/agents/policy.py +6 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/agents/resume.py +208 -43
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/agents/state.py +7 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/evals/metrics.py +0 -2
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime_python.egg-info/PKG-INFO +1 -1
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime_python.egg-info/SOURCES.txt +1 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_agents_checkpoint_integrity.py +8 -2
- aid_runtime_python-0.1.177/tests/test_agents_resume_hardening.py +222 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/README.md +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/setup.cfg +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/agents/chat_model.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/agents/engine.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/agents/guardrails.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/agents/ir.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/agents/managed.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/agents/memory.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/cache.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/concurrency.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/control.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/cost.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/decisions.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/errors.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/evals/__init__.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/evals/agent_runner.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/evals/dataset.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/evals/gate.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/evals/predicate.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/evals/runner.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/evals/trajectory.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/gateway.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/local_trace.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/metrics.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/pipeline.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/prompts.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/providers/__init__.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/providers/anthropic.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/providers/base.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/providers/bedrock.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/providers/fake.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/providers/gemini.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/providers/gemini_wire.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/providers/http.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/providers/recorded.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/providers/vertex.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/py.typed +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/redaction.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/retrieval/__init__.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/retrieval/chunking.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/retrieval/citations.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/retrieval/connectors.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/retrieval/embedding.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/retrieval/filters.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/retrieval/gate.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/retrieval/hybrid.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/retrieval/knowledge_base.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/retrieval/metrics.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/retrieval/pgvector.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/retrieval/rerank.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/retrieval/retriever.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/retrieval/stores.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/retrieval/types.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/steps.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/structured.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/telemetry.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/tools.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/tracing.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/types.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime_python.egg-info/dependency_links.txt +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime_python.egg-info/requires.txt +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime_python.egg-info/top_level.txt +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_agent_eval_runner.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_agents_budget.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_agents_deep_agents.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_agents_hitl.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_agents_loop.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_agents_memory.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_agents_redaction.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_anthropic_provider.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_bedrock_provider.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_cache.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_concurrency.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_control.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_cost.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_dataset.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_decisions.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_evals.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_evals_assert_gate.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_evals_budgets.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_evals_decision.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_evals_gate.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_evals_predicate.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_evals_trajectory.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_gateway.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_gemini_provider.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_guardrails.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_guardrails_managed.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_guardrails_model_armor.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_http_provider.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_local_trace.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_metrics.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_package.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_pipeline.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_prompts.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_recorded_provider.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_redaction.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_retrieval_chunking.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_retrieval_citations.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_retrieval_connectors.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_retrieval_embedding.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_retrieval_filters.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_retrieval_gate.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_retrieval_hybrid.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_retrieval_knowledge_base.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_retrieval_metrics.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_retrieval_rerank.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_retrieval_stores.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_retrieval_types.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_steps.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_streaming.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_structured.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_telemetry.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_tool_permissions.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_tools.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_tracing.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/tests/test_types.py +0 -0
- {aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/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.177
|
|
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.177"
|
|
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.175 → aid_runtime_python-0.1.177}/src/aid_runtime/agents/__init__.py
RENAMED
|
@@ -62,6 +62,8 @@ from aid_runtime.agents.memory import (
|
|
|
62
62
|
from aid_runtime.agents.policy import Principal, evaluate_policy, policy_source
|
|
63
63
|
from aid_runtime.agents.resume import (
|
|
64
64
|
DEFAULT_CHECKPOINT_TTL_MINUTES,
|
|
65
|
+
DEFAULT_CLOCK_LEEWAY_SECONDS,
|
|
66
|
+
MIN_SECRET_BYTES,
|
|
65
67
|
CheckpointRefusalError,
|
|
66
68
|
CheckpointSigner,
|
|
67
69
|
InProcessNonceStore,
|
|
@@ -85,11 +87,13 @@ from aid_runtime.agents.state import (
|
|
|
85
87
|
|
|
86
88
|
__all__ = [
|
|
87
89
|
"DEFAULT_CHECKPOINT_TTL_MINUTES",
|
|
90
|
+
"DEFAULT_CLOCK_LEEWAY_SECONDS",
|
|
88
91
|
"DETECTORS",
|
|
89
92
|
"GUARDRAIL_ACTIONS",
|
|
90
93
|
"GUARDRAIL_STAGES",
|
|
91
94
|
"IMPLEMENTED_MEMORY_KINDS",
|
|
92
95
|
"MEMORY_SCOPES",
|
|
96
|
+
"MIN_SECRET_BYTES",
|
|
93
97
|
"MODEL_ARMOR_TEMPLATE_ENV",
|
|
94
98
|
"AgentCheckpoint",
|
|
95
99
|
"AgentDefinition",
|
{aid_runtime_python-0.1.175 → aid_runtime_python-0.1.177}/src/aid_runtime/agents/deep_agents.py
RENAMED
|
@@ -115,7 +115,7 @@ class DeepAgentsEngine:
|
|
|
115
115
|
if not frame.input_checked:
|
|
116
116
|
frame.input_checked = True
|
|
117
117
|
paused = await self._runtime._guardrail_text(
|
|
118
|
-
_GUARDRAIL_INPUT, frame, memory_key, span=span, rewrite=True
|
|
118
|
+
_GUARDRAIL_INPUT, frame, memory_key, span=span, rewrite=True, principal=principal
|
|
119
119
|
)
|
|
120
120
|
if paused is not None:
|
|
121
121
|
return paused
|
|
@@ -142,10 +142,12 @@ class DeepAgentsEngine:
|
|
|
142
142
|
return self._runtime._outcome(RunStatus.MAX_STEPS, frame)
|
|
143
143
|
|
|
144
144
|
self._record_steps(frame, models)
|
|
145
|
-
paused = self._pause(frame, result, memory_key=memory_key, span=span)
|
|
145
|
+
paused = self._pause(frame, result, memory_key=memory_key, span=span, principal=principal)
|
|
146
146
|
if paused is not None:
|
|
147
147
|
return paused
|
|
148
|
-
return await self._complete(
|
|
148
|
+
return await self._complete(
|
|
149
|
+
frame, result, memory_key=memory_key, span=span, principal=principal
|
|
150
|
+
)
|
|
149
151
|
|
|
150
152
|
# -- graph -------------------------------------------------------------------
|
|
151
153
|
|
|
@@ -410,7 +412,9 @@ class DeepAgentsEngine:
|
|
|
410
412
|
)
|
|
411
413
|
return calls
|
|
412
414
|
|
|
413
|
-
def _pause(
|
|
415
|
+
def _pause(
|
|
416
|
+
self, frame: _Frame, result: Any, *, memory_key: str, span: Span, principal: Principal
|
|
417
|
+
) -> _Outcome | None:
|
|
414
418
|
"""Turn a held interrupt into our checkpoint, or ``None`` when nothing is held."""
|
|
415
419
|
pending = result.get("__interrupt__")
|
|
416
420
|
if not pending:
|
|
@@ -421,7 +425,7 @@ class DeepAgentsEngine:
|
|
|
421
425
|
f"agent {frame.agent.id!r} paused on an interrupt that named no tool call; "
|
|
422
426
|
"the harness's interrupt payload has changed shape"
|
|
423
427
|
)
|
|
424
|
-
checkpoint = self._runtime._checkpoint(frame, calls, memory_key)
|
|
428
|
+
checkpoint = self._runtime._checkpoint(frame, calls, memory_key, principal=principal)
|
|
425
429
|
record_hitl(span, phase="pause", channel=checkpoint.channel, step=frame.step)
|
|
426
430
|
self._runtime._record_status(span, "paused", frame)
|
|
427
431
|
return _Outcome(
|
|
@@ -434,11 +438,17 @@ class DeepAgentsEngine:
|
|
|
434
438
|
)
|
|
435
439
|
|
|
436
440
|
async def _complete(
|
|
437
|
-
self,
|
|
441
|
+
self,
|
|
442
|
+
frame: _Frame,
|
|
443
|
+
result: Any,
|
|
444
|
+
*,
|
|
445
|
+
memory_key: str,
|
|
446
|
+
span: Span,
|
|
447
|
+
principal: Principal,
|
|
438
448
|
) -> _Outcome:
|
|
439
449
|
"""Apply the output guardrail, record memory, and report the answer."""
|
|
440
450
|
released = await self._runtime._guardrail_answer(
|
|
441
|
-
frame, self._answer(result), memory_key, span=span
|
|
451
|
+
frame, self._answer(result), memory_key, span=span, principal=principal
|
|
442
452
|
)
|
|
443
453
|
if isinstance(released, _Outcome):
|
|
444
454
|
return released
|
|
@@ -544,7 +554,11 @@ class _Guardrails(AgentMiddleware):
|
|
|
544
554
|
return await self._delegate_in_span(request, handler, call)
|
|
545
555
|
runtime._authorize(self._frame.agent, call, self._principal)
|
|
546
556
|
guarded, halted = await runtime._guardrail_tool_calls(
|
|
547
|
-
self._frame,
|
|
557
|
+
self._frame,
|
|
558
|
+
[call],
|
|
559
|
+
self._memory_key,
|
|
560
|
+
span=self._record_span,
|
|
561
|
+
principal=self._principal,
|
|
548
562
|
)
|
|
549
563
|
if halted is not None:
|
|
550
564
|
raise _HaltError(halted)
|
|
@@ -329,33 +329,35 @@ class AgentRuntime:
|
|
|
329
329
|
principal: Principal | None = None,
|
|
330
330
|
) -> RunResult:
|
|
331
331
|
"""Continue a paused run from its checkpoint, with a human's answer."""
|
|
332
|
-
|
|
332
|
+
who = principal if principal is not None else Principal.unauthenticated()
|
|
333
|
+
# The principal is what the owner binding is checked against, so it is resolved
|
|
334
|
+
# before the checkpoint is read rather than threaded in afterwards.
|
|
335
|
+
checkpoint = await self._accept(checkpoint, who)
|
|
333
336
|
resolved = HumanDecision(decision)
|
|
334
337
|
self._restore_ledger(checkpoint)
|
|
335
338
|
start_cost = self._gateway.ledger.cost_usd
|
|
336
339
|
start_tokens = self._gateway.ledger.total_tokens
|
|
337
340
|
try:
|
|
338
|
-
outcome = await self._resume(
|
|
339
|
-
checkpoint,
|
|
340
|
-
resolved,
|
|
341
|
-
principal if principal is not None else Principal.unauthenticated(),
|
|
342
|
-
)
|
|
341
|
+
outcome = await self._resume(checkpoint, resolved, who)
|
|
343
342
|
except BaseException:
|
|
344
343
|
# Same rule as `run`: a resumed run that fails has been billed too.
|
|
345
344
|
self._publish_spend(checkpoint.agent_id, start_cost, start_tokens)
|
|
346
345
|
raise
|
|
347
346
|
return self._wrap(outcome, start_cost, start_tokens)
|
|
348
347
|
|
|
349
|
-
async def _accept(self, checkpoint: AgentCheckpoint) -> AgentCheckpoint:
|
|
348
|
+
async def _accept(self, checkpoint: AgentCheckpoint, principal: Principal) -> AgentCheckpoint:
|
|
350
349
|
"""Refuse a checkpoint this app did not issue, has expired, or already spent.
|
|
351
350
|
|
|
352
351
|
Called before anything the checkpoint carries is read, so a tampered pending call
|
|
353
352
|
is never authorized, priced or observed. A runtime built without a signer keeps the
|
|
354
353
|
pre-signing behaviour, which is what a direct library embedder already had.
|
|
354
|
+
|
|
355
|
+
``principal`` is what the checkpoint's owner binding is checked against: a run
|
|
356
|
+
paused by a principal with a subject can only be resumed by that same subject.
|
|
355
357
|
"""
|
|
356
358
|
if self._signer is None:
|
|
357
359
|
return checkpoint
|
|
358
|
-
await self._signer.accept(checkpoint, self._nonces)
|
|
360
|
+
await self._signer.accept(checkpoint, self._nonces, subject=principal.subject)
|
|
359
361
|
return checkpoint
|
|
360
362
|
|
|
361
363
|
async def _resume(
|
|
@@ -510,7 +512,12 @@ class AgentRuntime:
|
|
|
510
512
|
if not frame.input_checked:
|
|
511
513
|
frame.input_checked = True
|
|
512
514
|
paused = await self._guardrail_text(
|
|
513
|
-
_GUARDRAIL_INPUT,
|
|
515
|
+
_GUARDRAIL_INPUT,
|
|
516
|
+
frame,
|
|
517
|
+
memory_key,
|
|
518
|
+
principal=principal,
|
|
519
|
+
span=span,
|
|
520
|
+
rewrite=True,
|
|
514
521
|
)
|
|
515
522
|
if paused is not None:
|
|
516
523
|
return paused
|
|
@@ -533,7 +540,9 @@ class AgentRuntime:
|
|
|
533
540
|
response = generation.response
|
|
534
541
|
|
|
535
542
|
if not response.tool_calls:
|
|
536
|
-
answer = await self._guardrail_answer(
|
|
543
|
+
answer = await self._guardrail_answer(
|
|
544
|
+
frame, response.text, memory_key, principal=principal, span=span
|
|
545
|
+
)
|
|
537
546
|
if isinstance(answer, _Outcome):
|
|
538
547
|
return answer
|
|
539
548
|
frame.messages.append(Message.assistant(answer))
|
|
@@ -560,13 +569,13 @@ class AgentRuntime:
|
|
|
560
569
|
record.kind = StepKind.TOOLS
|
|
561
570
|
record.tool_names = tuple(call.name for call in response.tool_calls)
|
|
562
571
|
guarded, paused = await self._guardrail_tool_calls(
|
|
563
|
-
frame, response.tool_calls, memory_key, span=span
|
|
572
|
+
frame, response.tool_calls, memory_key, principal=principal, span=span
|
|
564
573
|
)
|
|
565
574
|
if paused is not None:
|
|
566
575
|
return paused
|
|
567
576
|
frame.messages.append(Message.assistant_tool_calls(response.text, guarded))
|
|
568
577
|
if self._needs_approval(agent, guarded, principal):
|
|
569
|
-
checkpoint = self._checkpoint(frame, guarded, memory_key)
|
|
578
|
+
checkpoint = self._checkpoint(frame, guarded, memory_key, principal=principal)
|
|
570
579
|
record_hitl(
|
|
571
580
|
span,
|
|
572
581
|
phase="pause",
|
|
@@ -592,6 +601,7 @@ class AgentRuntime:
|
|
|
592
601
|
frame: _Frame,
|
|
593
602
|
memory_key: str,
|
|
594
603
|
*,
|
|
604
|
+
principal: Principal,
|
|
595
605
|
span: Span,
|
|
596
606
|
rewrite: bool,
|
|
597
607
|
) -> _Outcome | None:
|
|
@@ -611,7 +621,9 @@ class AgentRuntime:
|
|
|
611
621
|
if verdict.action == ACTION_BLOCK and deciding is not None:
|
|
612
622
|
raise GuardrailBlockedError(deciding.guardrail, stage, deciding.message)
|
|
613
623
|
if verdict.action == ACTION_ESCALATE:
|
|
614
|
-
return self._guardrail_pause(
|
|
624
|
+
return self._guardrail_pause(
|
|
625
|
+
frame, verdict, memory_key, (), principal=principal, span=span
|
|
626
|
+
)
|
|
615
627
|
if rewrite and verdict.action == ACTION_REDACT and index is not None:
|
|
616
628
|
frame.messages[index] = Message.user(verdict.text)
|
|
617
629
|
return None
|
|
@@ -622,6 +634,7 @@ class AgentRuntime:
|
|
|
622
634
|
text: str,
|
|
623
635
|
memory_key: str,
|
|
624
636
|
*,
|
|
637
|
+
principal: Principal,
|
|
625
638
|
span: Span,
|
|
626
639
|
) -> str | _Outcome:
|
|
627
640
|
"""Run the ``output`` stage over an answer, returning the text to ship.
|
|
@@ -638,7 +651,9 @@ class AgentRuntime:
|
|
|
638
651
|
if verdict.action == ACTION_BLOCK and deciding is not None:
|
|
639
652
|
raise GuardrailBlockedError(deciding.guardrail, _GUARDRAIL_OUTPUT, deciding.message)
|
|
640
653
|
if verdict.action == ACTION_ESCALATE:
|
|
641
|
-
return self._guardrail_pause(
|
|
654
|
+
return self._guardrail_pause(
|
|
655
|
+
frame, verdict, memory_key, (), principal=principal, span=span, text=text
|
|
656
|
+
)
|
|
642
657
|
return verdict.text if verdict.action == ACTION_REDACT else text
|
|
643
658
|
|
|
644
659
|
async def _guardrail_tool_calls(
|
|
@@ -647,6 +662,7 @@ class AgentRuntime:
|
|
|
647
662
|
calls: Sequence[ToolCall],
|
|
648
663
|
memory_key: str,
|
|
649
664
|
*,
|
|
665
|
+
principal: Principal,
|
|
650
666
|
span: Span,
|
|
651
667
|
) -> tuple[list[ToolCall], _Outcome | None]:
|
|
652
668
|
"""Run the ``tool-call`` stage over every call in one step.
|
|
@@ -675,7 +691,9 @@ class AgentRuntime:
|
|
|
675
691
|
call = call.model_copy(update={"arguments": dict(verdict.arguments)})
|
|
676
692
|
guarded.append(call)
|
|
677
693
|
if escalation is not None:
|
|
678
|
-
return guarded, self._guardrail_pause(
|
|
694
|
+
return guarded, self._guardrail_pause(
|
|
695
|
+
frame, escalation, memory_key, guarded, principal=principal, span=span
|
|
696
|
+
)
|
|
679
697
|
return guarded, None
|
|
680
698
|
|
|
681
699
|
def _record_guardrails(self, frame: _Frame, verdict: GuardrailVerdict, span: Span) -> None:
|
|
@@ -691,6 +709,7 @@ class AgentRuntime:
|
|
|
691
709
|
memory_key: str,
|
|
692
710
|
calls: Sequence[ToolCall],
|
|
693
711
|
*,
|
|
712
|
+
principal: Principal,
|
|
694
713
|
span: Span,
|
|
695
714
|
text: str = "",
|
|
696
715
|
) -> _Outcome:
|
|
@@ -708,7 +727,9 @@ class AgentRuntime:
|
|
|
708
727
|
channel=approval.channel if approval is not None else _GUARDRAIL_CHANNEL,
|
|
709
728
|
text=text,
|
|
710
729
|
)
|
|
711
|
-
checkpoint = self._checkpoint(
|
|
730
|
+
checkpoint = self._checkpoint(
|
|
731
|
+
frame, calls, memory_key, principal=principal, escalation=escalation
|
|
732
|
+
)
|
|
712
733
|
record_hitl(
|
|
713
734
|
span,
|
|
714
735
|
phase="pause",
|
|
@@ -835,9 +856,9 @@ class AgentRuntime:
|
|
|
835
856
|
inner.steps = [*frame.steps, *inner.steps]
|
|
836
857
|
inner.guardrails = (*frame.guardrails, *inner.guardrails)
|
|
837
858
|
if inner.checkpoint is not None:
|
|
838
|
-
caller = self._checkpoint(
|
|
839
|
-
|
|
840
|
-
)
|
|
859
|
+
caller = self._checkpoint(
|
|
860
|
+
frame, (call,), memory_key, principal=principal
|
|
861
|
+
).model_copy(update={"resume_kind": "delegate", "channel": ""})
|
|
841
862
|
inner.checkpoint = inner.checkpoint.model_copy(update={"caller": caller})
|
|
842
863
|
return inner
|
|
843
864
|
if inner.status is not RunStatus.COMPLETED:
|
|
@@ -1114,6 +1135,7 @@ class AgentRuntime:
|
|
|
1114
1135
|
calls: Sequence[ToolCall],
|
|
1115
1136
|
memory_key: str,
|
|
1116
1137
|
*,
|
|
1138
|
+
principal: Principal,
|
|
1117
1139
|
escalation: GuardrailEscalation | None = None,
|
|
1118
1140
|
) -> AgentCheckpoint:
|
|
1119
1141
|
approval = frame.agent.approval
|
|
@@ -1145,7 +1167,12 @@ class AgentRuntime:
|
|
|
1145
1167
|
# Signed here rather than at the route, so every pause path -- approval, tool
|
|
1146
1168
|
# confirmation, guardrail escalation, and the nested caller of a delegate -- is
|
|
1147
1169
|
# issued by the same key. A second signing site is a second thing to forget.
|
|
1148
|
-
|
|
1170
|
+
# The principal travels with it for the same reason: the subject that paused the
|
|
1171
|
+
# run is only available here, and a pause that skipped the binding would hand out
|
|
1172
|
+
# a checkpoint anyone holding it could resume.
|
|
1173
|
+
if self._signer is None:
|
|
1174
|
+
return checkpoint
|
|
1175
|
+
return self._signer.sign(checkpoint, subject=principal.subject)
|
|
1149
1176
|
|
|
1150
1177
|
def _restore_ledger(self, checkpoint: AgentCheckpoint) -> None:
|
|
1151
1178
|
"""Carry a pause's spend into this process's ledger before resuming.
|
|
@@ -47,6 +47,12 @@ class Principal:
|
|
|
47
47
|
roles: frozenset[str] = frozenset()
|
|
48
48
|
scopes: frozenset[str] = frozenset()
|
|
49
49
|
authenticated: bool = False
|
|
50
|
+
# A stable identifier for the caller as their token issuer named them -- a `sub`
|
|
51
|
+
# claim, a service-account id. It is *not* derived from ``authenticated``: a
|
|
52
|
+
# principal can be authenticated without a subject, and a checkpoint paused by one
|
|
53
|
+
# is therefore not owner-bound. Only this field binds a checkpoint to a person, so
|
|
54
|
+
# an app that verifies tokens should set it from the verified claim.
|
|
55
|
+
subject: str | None = None
|
|
50
56
|
|
|
51
57
|
@classmethod
|
|
52
58
|
def unauthenticated(cls) -> Principal:
|