Skip to content

Architecture

CredenceStack as it is now. It tests an AI agent that acts in finance (pays invoices, reviews sanctions alerts, checks supplier documents, onboards customers) inside a simulated back office, judges every step with deterministic graders, and writes signed evidence of what happened. Forge generates new scenarios, the environment exposes the same back office step by step, benchmarks compare configurations, and every workflow can emit OpenTelemetry traces.

flowchart LR subgraph In["Inputs"] packs["Scenario packs<br/>(shipped, yours, generated)"] rules["Profiles and<br/>domain policies"] agent["Your agent"] end subgraph Core["credencestack"] forge["forge<br/>seed scenarios + mutators"] env["env<br/>simulated back office"] conn["connectors<br/>one per framework"] runner["runner<br/>episodes through Inspect"] graders["graders<br/>findings, expected outcomes"] evidence["evidence<br/>manifest, chain, signature"] reports["reports<br/>HTML and Markdown"] bench["bench<br/>authority and brittleness"] otel["otel<br/>spans, metrics"] assess["assess<br/>credencestack test"] end agent --> assess --> conn assess --> runner assess --> forge packs --> forge --> packs packs --> runner rules --> graders agent <--> conn <--> env runner --> env env --> graders --> evidence --> reports bench --> runner env -. events .-> otel runner -. episodes .-> otel forge -. generation .-> otel bench -. configurations .-> otel

Components

Package What it does Notes
core Shared models: scenarios and packs, findings, results, pillars, trace events, visibility core
profiles Authority profiles, their schema, step classification profiles
domains Domain policies (fincrime, docintegrity, kyc) and how a scenario names one domains
packs Loading packs: YAML, JSONL, the built-in packs, the JSON Schema packs
env The simulated back office (Environment, tools, worlds, faults, the kill switch, rate observation) and CredenceEnv env, faults, kill switch
connectors One connector per framework, MCP, Python and HTTP; the conformance kit connectors
agents Scripted and LangChain reference agents: naive, safe, brittle agents
runner One episode (run_episode), and packs through Inspect with the scorers (run_packs) runner
graders The authority grader (decide), the domain graders (GRADERS), outcome checks, statistics, the advisory judge graders
forge Mutators, the difficulty dial, the generator and its labeller, output and validation forge
assess credencestack test: detection, interception of the agent's own tools, the tool map, the advisor, preflight, outcome labels, the assessment and backend mode for services assess
evidence Bundles, manifests, the hash chain, the Merkle root, signatures, verification, export and redaction, gating evidence, integrity
reports One report model and one template set for runs, benchmarks and brittleness reports
bench Benchmark configurations, the cost meter, run_bench, run_brittleness bench
otel The registry (semconv), spans for every workflow, metrics, redaction otel
integrations Runtime logs (Atryum, Tenuo) and AP2 mandates, reconciled against the graders integrations
cli The command grammar, shared flags, settings, console output CLI
_internal One module per utility: io, hashing, seeding, stats, formatting, logging, ids, outputs, matching _internal

credencestack.api is the public Python surface (run, select_packs, verify); see the Python API.

A run

credencestack run (and credencestack.run, and each configuration of a benchmark) goes through evidence.pipeline.run_to_bundle:

sequenceDiagram participant CLI as cli/run.py participant P as evidence.pipeline participant R as runner.inspect_runner participant E as runner.episode participant Env as env.Environment participant C as connector participant G as graders participant B as evidence.bundle CLI->>P: run_to_bundle(packs, connector factory, epochs, seed) P->>R: run_packs(...) loop every scenario x epoch (an Inspect sample) R->>E: run_episode(scenario, connector, seed) E->>Env: prepare_episode: world, faults, rate observer, kill switch E->>C: start(task, tools, env), run_until_done(max_steps) C->>Env: call(tool, args) ... (every call is a trace event) R->>G: scorers: authority or domain grader, resilience, injection, third party, outcome end R-->>P: records, results, statistics P->>B: write_bundle: results.json, traces/, profiles, report, manifest.json CLI->>CLI: --sign signs the manifest; the gate checks --fail-on

Seeds are derived (_internal.seeding.derive) from the run's seed, the scenario and the epoch, so a run reproduces exactly. Agent failures never raise: they are recorded on the episode and become agent_error findings.

A test

credencestack test (cli/test.py, assess.run) wraps the same pipeline around an agent that was not written for CredenceStack:

sequenceDiagram participant CLI as cli/test.py participant D as assess.detect participant M as assess.toolmap participant A as assess.advisor participant R as assess.run participant P as evidence.pipeline participant F as forge participant S as assess.assessment CLI->>D: target (module:attr or URL), agent file D-->>CLI: Detected (framework, tools, prompt) and a Driver; tools intercepted in place CLI->>M: tools M-->>CLI: ToolMap (sim tool, args, confidence) CLI->>A: Detected, ToolMap A-->>CLI: domains, packs, reasons CLI->>R: preflight_checks, plan, smoke episode R->>P: fixed scenarios (AssessConnector or ServiceConnector) R->>F: generate at the mode's levels R->>P: generated scenarios R->>S: both runs S-->>CLI: assessment.json, report, suggestions

During an episode, the connector activates the episode's EpisodeTools, then runs the agent through its framework. Each intercepted tool call is translated with the tool map and answered by env.Environment, so the trace, the graders and the evidence are the same as for credencestack run.

A generation

credencestack generate calls forge.generator.generate:

  1. For each index, derive a seed; pick a seed scenario; draw mutators for the index's level from the difficulty dial among those that apply.
  2. Apply them in labelling order to a copy of the scenario's data: recompute first, then preserve, then override (order breaks ties within a mode).
  3. Validate the result as a Scenario; label it with forge.label.label, which runs the graders' expectation logic on the mutated records, then let each override mutator adjust the expectation. A candidate that is invalid, undecidable, ambiguous or a duplicate is rejected and redrawn (up to MAX_ATTEMPTS).
  4. forge.output.write_generation writes one pack per source pack (and one -confidential pack where needed); write_manifest_for writes manifest.json (kind: generate).

An environment episode

env.rl.CredenceEnv.reset draws a scenario (fixed or generated) and calls runner.episode.prepare_episode, the same setup a run uses. step calls Environment.call with the action and returns the tool's result; a final answer, the step limit or the kill switch ends the episode, and env.rl.grade grades it with the same scorers as a run (graders.scoring.all_findings and graders.outcome.check_outcome) and computes the reward from env/rewards.yaml. run_connector lets any connector be the policy, through run_episode.

A benchmark

bench.runner.run_bench runs every configuration through run_to_bundle into <out>/bench-<id>/<config_id>/, under one CostMeter that refuses model calls once the cap is reached, and writes the results tables and the manifest; reports.bench builds the report. bench.brittleness.run_brittleness first generates scenarios per pack and level, then calls run_bench on the fixed and the generated packs, and summarise computes the curve, the gaps and the sensitivities.

Where telemetry hooks in

Telemetry is off unless asked for, and the core imports no OpenTelemetry module until it is on (credencestack.otel is import-free; otel.start loads the rest).

Workflow Hook Spans
Run run_to_bundle opens RunSpans; run_episode asks Telemetry.episode() run, scenario, invoke_agent, execute_tool, chat, grade
Test cli/test.py starts telemetry; the fixed and generated runs each go through run_to_bundle as a run, twice (fixed and forge)
Every episode EpisodeSpans.on_event, a listener on Environment.listeners tool spans and events from the trace, for every connector alike
Generation forge.generator.generate opens GenerationSpans generate, generate.scenario
Environment CredenceEnv with otel=True opens an episode span when sampled episode, execute_tool or invoke_agent
Benchmark run_bench and run_brittleness open BenchSpans bench, bench.config, and each configuration's run under it

Every name is registered in otel/semconv.py; otel.validate.unregistered is the test.

The evidence format

Every output directory (run-, generate-, bench-, brittleness-, env-export-, export-<id>) has a manifest.json (credencestack.evidence/v1): its kind, the version, the settings (secrets removed, paths portable), the inputs and a section per kind, and every file with its SHA-256 and a Merkle root over them. Trace files are hash-chained, event by event. signature.json is an Ed25519 signature over the manifest's statement. evidence.verify.verify_bundle checks files, chains, the root, nested outputs and the signature. Outputs are never overwritten; latest-<kind> points at the newest.

How confidential content is tracked

Visibility is set per pack or per mutator and carried on every Scenario (effective_visibility) and every Generated scenario. core.visibility.shown_id is the one function that turns an id into what shared outputs show (confidential:<hash>). evidence.privacy redacts results and catalogue entries; evidence.export writes the redacted copy; reports, CredenceEnv.info, env export and telemetry check visibility before writing content. otel.redaction removes secrets from any captured content. The canary fixtures in tests/fixtures/confidential/ and tests/fixtures/mutators/ are checked against every output.

Extension points

To add Implement Register
A connector connectors.protocol.Connector a ConnectorSpec in connectors/registry.py; pass the conformance kit
A pack pack.yaml and scenarios a directory on --pack-path (or packs.path)
A mutator a forge.Mutator subclass a .py file on --mutator-path (or mutators.path)
A domain a policy model, a world, a grader GRADERS in graders/__init__.py, tool families in env/families.py
A report section a section in the builder for that output kind reports/evidence.py, reports/bench.py, reports/brittleness.py
A telemetry name the emission otel/semconv.py first

The contributor guide names the checks that enforce each.

Import layering

  • core, _internal and errors import nothing above them; profiles and domains build on core.
  • env never imports graders, evidence or the CLI; domain worlds are loaded by import path.
  • graders read episode records; they never run an agent.
  • forge imports graders (to label) and packs; nothing in the run path imports forge, except env.rl.GeneratedScenarios and the brittleness benchmark.
  • Optional frameworks are imported only when their connector is built, so the core install imports none of them (the CI job "Core install (no extras)" checks this).
  • otel modules other than otel/__init__.py, config and semconv import OpenTelemetry and are loaded only when telemetry is on.

Data flow in detail

Verifying

sequenceDiagram participant CLI as credencestack evidence verify participant V as evidence.verify CLI->>V: verify_bundle(directory, public key) V->>V: read manifest.json; hash every listed file; no unlisted, missing or linked files V->>V: recompute the Merkle root V->>V: check every trace's hash chain V->>V: verify nested outputs (a benchmark's bundles; an export's bundle/) V->>V: check signature.json against the public key, if given V-->>CLI: pass, or every problem found