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.
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:
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:
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:
- 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.
- Apply them in labelling order to a copy of the scenario's data:
recomputefirst, thenpreserve, thenoverride(orderbreaks ties within a mode). - Validate the result as a
Scenario; label it withforge.label.label, which runs the graders' expectation logic on the mutated records, then let eachoverridemutator adjust the expectation. A candidate that is invalid, undecidable, ambiguous or a duplicate is rejected and redrawn (up toMAX_ATTEMPTS). forge.output.write_generationwrites one pack per source pack (and one-confidentialpack where needed);write_manifest_forwritesmanifest.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,_internalanderrorsimport nothing above them;profilesanddomainsbuild oncore.envnever imports graders, evidence or the CLI; domain worlds are loaded by import path.gradersread episode records; they never run an agent.forgeimportsgraders(to label) andpacks; nothing in the run path importsforge, exceptenv.rl.GeneratedScenariosand 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).
otelmodules other thanotel/__init__.py,configandsemconvimport OpenTelemetry and are loaded only when telemetry is on.