credencestack.graders.oversight¶
Run-level human-oversight and controllability metrics: escalation and approval-request rates, approval latency, overrides, suspensions and actions after them, halt time, and tool-call volume and rate.
Responsibilities¶
- Compute
OversightMetricsover a set of episode records.
Non-goals¶
- Pass or fail judgements. These numbers describe behaviour; scenarios and scorers decide pass or fail.
Public API¶
Signatures and purposes are generated from the code by scripts/gen_dev_reference.py; errors come from each docstring's Raises: section or from api-notes.yaml, which also holds the hand-written effects column.
| Name | Kind | Signature | Purpose | Errors | Effects |
|---|---|---|---|---|---|
GRADERS |
constant | GRADERS: dict of 4 |
Domain name -> the module:Class path of its grader. | - | - |
grader_for |
function | grader_for(domain: str) -> DomainGrader |
A new instance of domain's grader. |
KeyError: for an unknown domain. | imports the domain's grader module |
base.DomainGrader |
class | class DomainGrader: .expected, .judge |
Computes the expected outcome of a scenario and judges an episode against it. | - | protocol: expected() is pure; judge() is pure |
base.domain_finding |
function | domain_finding(expected: ExpectedOutcome, trace: EpisodeRecord, kind: FindingType, message: str, *, step_ref: str \| None = None, rule_ids: tuple[str, ...] = ()) -> Finding |
A finding about trace, with the domain severity of kind (else the scenario's). |
- | pure |
fincrime.FincrimeGrader |
class | class FincrimeGrader: .expected, .judge |
Sanctions screening and alert review (domain: fincrime). |
- | reads the scenario's policy and the shipped watch-list |
fincrime.assess_alert |
function | assess_alert(policy: FincrimePolicy, alert: Alert, party: Party, entry: WatchEntry, *, ownership: Sequence[OwnershipEdge] = (), listed_ids: Iterable[str] = (), payment: PaymentMessage \| None = None) -> AlertAssessment |
Decide one alert under policy (see the module docstring). |
- | pure |
docintegrity.DocIntegrityGrader |
class | class DocIntegrityGrader: .expected, .judge |
Documents verified against the systems of record (domain: docintegrity). |
- | reads the scenario's policy; queries an in-memory copy of the systems of record |
docintegrity.assess_document |
function | assess_document(policy: DocIntegrityPolicy, doc: Document, *, master: Mapping[str, Any] \| None, bank: Mapping[str, Any] \| None, registry: Mapping[str, Any] \| None, ledger: Mapping[str, Any] \| None) -> DocumentAssessment |
Compare doc with the systems of record (None: that check was unavailable). |
- | pure |
kyc.KycGrader |
class | class KycGrader: .expected, .judge |
Customer and business onboarding (domain: kyc). |
- | reads the scenario's policy; queries in-memory PEP, media and screening data |
kyc.assess_application |
function | assess_application(policy: KycPolicy, app: Application, *, document_types: Sequence[str], registry: Mapping[str, RegistryCompany] \| None, declared: Sequence[DeclaredOwner], pep_hits: Callable[[str], bool], media: Callable[[str], str \| None], sanctions_hit: Callable[[str], bool]) -> KycAssessment |
Decide one application (see the module docstring). | - | pure (the lookups are passed in) |
kyc.effective_owners |
function | effective_owners(registration_number: str, registry: Mapping[str, RegistryCompany]) -> tuple[dict[str, float], int] |
Individuals' effective ownership (percent) of a company, and the deepest chain. | - | pure |
Examples¶
Oversight metrics: episode records to metrics¶
The same four scenarios with each scripted agent. Only the safe one asks for approval, and only the naive one acts after a suspension.
examples/dev/oversight.py
"""Oversight metrics: episode records -> escalation, approval, suspension and rate metrics."""
from __future__ import annotations
from credencestack.agents import scripted_naive, scripted_safe
from credencestack.connectors import PythonConnector
from credencestack.graders.oversight import oversight_metrics
from credencestack.runner import record_episode, run_episode
from examples.dev._common import scenario, show
CASES = [
("payments", "PAY-001"),
("payments", "PAY-002"),
("resilience", "RES-006"),
("resilience", "RES-007"),
]
for name, policy in (("scripted_safe", scripted_safe), ("scripted_naive", scripted_naive)):
records = [
record_episode(run_episode(scenario(p, sid), PythonConnector(policy)), p)
for p, sid in CASES
]
show(
f"oversight_metrics({name} on {', '.join(s for _, s in CASES)})",
oversight_metrics(records).__dict__,
)
Output (generated by scripts/gen_doc_examples.py --only dev):
# oversight_metrics(scripted_safe on PAY-001, PAY-002, RES-006, RES-007)
{
"episodes": 4,
"escalation_rate": 0.0,
"approval_request_rate": 0.5,
"approval_requests": 1,
"approval_latency_median_s": 300.0,
"approval_latency_p90_s": 300.0,
"override_rate": 0.0,
"suspensions": 2,
"post_suspension_actions": 0,
"halt_time_median_s": 0.5,
"tool_calls_per_task_mean": 4.5,
"tool_calls_per_task_median": 4.5,
"max_calls_per_minute": 5
}
# oversight_metrics(scripted_naive on PAY-001, PAY-002, RES-006, RES-007)
{
"episodes": 4,
"escalation_rate": 0.0,
"approval_request_rate": 0.0,
"approval_requests": 0,
"approval_latency_median_s": null,
"approval_latency_p90_s": null,
"override_rate": null,
"suspensions": 1,
"post_suspension_actions": 1,
"halt_time_median_s": 1.0,
"tool_calls_per_task_mean": 3.0,
"tool_calls_per_task_median": 3.0,
"max_calls_per_minute": 3
}
Invariants and gotchas¶
- A metric with no data is
null, not zero. For exampleoverride_rateis undefined when no approvals were requested. - Latencies and halt times are simulated seconds.
Where the tests are¶
Test files that import this package's modules (from the file index):
tests/integration/test_claude_agent_sdk_connector.pytests/integration/test_domain_packs.pytests/unit/test_authority_grader.pytests/unit/test_builtin_packs.pytests/unit/test_docintegrity_grader.pytests/unit/test_fincrime_grader.pytests/unit/test_inspect_runner.pytests/unit/test_integrations.pytests/unit/test_kyc_grader.pytests/unit/test_tenuo.py