Skip to content

credencestack.runner

Run scenarios: one episode at a time (run_episode), or whole packs through UK AISI's Inspect, where each pack is an Inspect task, each scenario a sample, and each epoch a repeat.

Responsibilities

  • Build the environment a scenario describes, with its faults and kill switch installed (build_environment).
  • Run one episode through a connector and return everything it produced (Episode), and turn it into a serialisable EpisodeRecord.
  • Derive one deterministic seed per scenario and epoch (derive_seed).
  • Run packs through Inspect, with the five scorers, and read per-epoch RunResults back from Inspect's logs (inspect_runner). Outside payments the authority scorer also calls the scenario's domain grader (graders.domain.domain_findings).
  • Add cross-epoch findings once every epoch is in, such as rating_inconsistent for a KYC file rated differently across epochs (run_packs).

Non-goals

  • Writing evidence. evidence.pipeline.run_to_bundle calls the runner and writes the bundle.
  • Using Inspect's model layer. The agent is driven by its connector, so Inspect runs with its built-in mockllm/model and needs no API key.

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
Episode model Episode(scenario_id, epoch, seed, env, handle, kill_switch, rate, faults, …) Everything one epoch produced. - data
build_environment function build_environment(scenario: Scenario, *, seed: int, profile: AuthorityProfile \| None = None) -> Environment Create the environment a scenario describes (env_seed plus its authority binding). - pure (a new in-memory environment)
record_episode function record_episode(episode: Episode, pack: str \| None = None) -> EpisodeRecord A serialisable record of episode for scorers and logs. - pure
run_episode function run_episode(scenario: Scenario, connector: Connector, *, epoch: int = 0, seed: int = 0, profile: AuthorityProfile \| None = None, max_steps: int = 50) -> Episode Run connector against scenario once and return the episode. - runs the agent against an in-memory environment; no files

Examples

The connectors example calls run_episode directly, and the evidence example runs packs through Inspect via run_to_bundle.

Invariants and gotchas

  • Seeds are sha256(f"{base_seed}:{scenario_id}:{epoch}"), truncated to 31 bits: stable across processes, platforms and Python versions.
  • Inspect numbers epochs from 1; CredenceStack numbers them from 0 (traces/<scenario>/0.jsonl, RunResult.epoch).
  • Inspect's epoch reduction keeps the score metadata of one epoch only: in a 3-epoch run the reduced authority score carries one epoch's findings, while each of the three samples carries its own. Read per-epoch findings from log.samples, as run_packs does, never from log.reductions.
  • The solver stores the whole EpisodeRecord in the sample's store, so any episode can be re-scored from the Inspect log alone.

Where the tests are

Test files that import this package's modules (from the file index):

  • tests/integration/test_adk_connector.py
  • tests/integration/test_assess_frameworks.py
  • tests/integration/test_claude_agent_sdk_connector.py
  • tests/integration/test_crewai_connector.py
  • tests/integration/test_domain_packs.py
  • tests/integration/test_example_agents.py
  • tests/integration/test_mcp_connector.py
  • tests/integration/test_msaf_connector.py
  • tests/integration/test_openai_agents_connector.py
  • tests/integration/test_strands_connector.py
  • tests/live/test_live_connectors.py
  • tests/unit/test_assess_core.py
  • tests/unit/test_bench.py
  • tests/unit/test_builtin_packs.py
  • tests/unit/test_cli_authority.py
  • tests/unit/test_connectors.py
  • tests/unit/test_control.py
  • tests/unit/test_faults.py
  • tests/unit/test_inspect_runner.py
  • tests/unit/test_integrations.py
  • tests/unit/test_otel.py
  • tests/unit/test_otel_workflows.py