Skip to content

Extending CredenceStack

Six common extensions, each with the files to touch and a checklist. The tests named in the checklists fail if a step is missed, so run uv run pytest -q -m "not guides" before you open a pull request.

A scenario

A scenario is one YAML file: the task, the simulated environment (env_seed), the authority binding, optional injections, faults and control events, and the expected outcomes. The format is documented in Writing your own scenarios and validated by schemas/scenario.schema.json.

  1. Start from credencestack packs init <dir> (a pack with one example scenario and a copy of the demo profile), or copy a built-in scenario from the pack reference.
  2. Set id, title, user_task, inputs, pillars, risks (finding types the scenario is about), severity and authority_profile (relative to the file, or builtin:<file>).
  3. Seed only what the task needs in env_seed, and add faults:, injections: or control_events: for the behaviour under test.
  4. Write expected: so a correct agent passes and the failure you care about fails: decision_in, must_call, must_not_call, ledger, max_payments, max_tool_calls, halt.
  5. Run it against both scripted agents and read the findings: credencestack run -p <dir> -s <ID> --agent credencestack.agents:scripted_naive.

Checklist:

  • credencestack packs validate <dir> passes (schema, environment, references, profiles and graders).
  • scripted_safe passes and scripted_naive fails it, for the reason in the description (or the scenario is documented as testing something they both handle).
  • The id is unique across the shipped packs and continues its pack's sequence (the next free number in that pack).

A pack

A pack is a directory with a pack.yaml (name, version, visibility, description) and a scenarios/ folder. Use one from anywhere with --pack-path <parent dir> or CREDENCESTACK_PACKS_PATH.

Checklist for a new built-in (public) pack under src/credencestack/packs/builtin/:

  • Every scenario passes credencestack packs validate, and every id is unique across all packs (load_packs rejects duplicates).
  • tests/unit/test_builtin_packs.py passes: it checks the planned scenario counts, and that for every built-in scenario scripted_safe meets the expectations and scripted_naive is caught. Update the planned counts.
  • Add the pack's framework references under packs: in src/credencestack/evidence/mappings/frameworks.yaml (every one indicative).
  • Add it to PACK_ORDER in scripts/gen_docs_reference.py, run the script, and add the new docs/reference/packs/<pack>.md to the nav in mkdocs.yml. The script refuses to document a pack that is not public.

A fault type

Faults are frozen dataclasses in src/credencestack/env/faults.py.

  1. Add the kind to FaultKind in src/credencestack/core/scenario.py.
  2. Subclass Fault: its parameters are dataclass fields, and its wrapper calls the handler it wraps, counts calls, and records a fault event when it fires.
  3. Register it in FAULT_TYPES.
  4. Teach ResilienceScorer (src/credencestack/graders/scoring.py) what a wrong reaction looks like, using an existing finding type or a new one (next section).
  5. Regenerate the scenario schema: uv run credencestack packs schema scenario > schemas/scenario.schema.json.

Checklist:

  • tests/unit/test_faults.py passes; it asserts FAULT_TYPES and FaultKind match.
  • tests/unit/test_schema.py passes (the committed schema is current).
  • A test in tests/unit/test_faults.py for the new wrapper: when it fires, what the agent sees, the ledger, and the fault event's meta.
  • A scenario that uses it, and its row in Writing your own scenarios.

A grader or a finding type

A finding type is a value of FindingType in src/credencestack/core/findings.py.

  1. Add the type to FindingType, and its pillars to FINDING_PILLARS. If it should not fail an epoch, add it to PASSING_FINDINGS too.
  2. Emit it from a scorer in src/credencestack/graders/scoring.py (or a new scorer class added to all_findings and to the Inspect task in runner/inspect_runner.py). Give every finding a step_ref, rule_ids where an grader rule or check is behind it, and a message a reviewer can act on.
  3. Map it under findings: in src/credencestack/evidence/mappings/frameworks.yaml.

Checklist:

  • tests/unit/test_core.py passes; it asserts FindingType and FINDING_PILLARS list the same types.
  • Unit tests for the scorer on a trace that should and one that should not produce it.
  • uv run python scripts/gen_docs_reference.py regenerates the framework-mapping page, and docs/running.md#findings describes the new type.

A framework mapping

All mappings live in src/credencestack/evidence/mappings/frameworks.yaml: the primary grouping by the six pillars, then frameworks (title, version, url), references (an id per item, with its framework and theme), and which references each finding type and pack bears on.

  1. Add the framework under frameworks: with status: indicative, and its items under references:. Mark anything not confirmed against a primary source todo_verify: true and list it in the TODO-verify register.
  2. Point finding types and packs at the new reference ids.

Checklist:

  • load_framework_map() loads it: evidence/frameworks.py rejects reference ids that are not defined and references to unknown frameworks.
  • Every new entry says indicative; nothing is worded as a compliance claim.
  • uv run python scripts/gen_docs_reference.py regenerates Framework mappings, and a sample run's mappings.json and report show it.

A connector

Follow Write and check a connector: the Connector contract, the patterns the built-in connectors use (tools through env.call, model_call events, approvals, suspension, a scripted offline model), the ConnectorSpec in src/credencestack/connectors/registry.py, and the conformance kit.

Checklist:

  • An optional extra in pyproject.toml; the framework is imported only inside the connector module (the core install must not need it).
  • credencestack connectors check --connector <name> --model credencestack:scripted is conformant, and its report is committed under src/credencestack/connectors/conformance/reports/.
  • Connector tests in tests/integration/test_<name>_connector.py, skipped when the extra is missing.
  • A connector note in docs/dev/connectors/, an integration page in docs/integrate/, and a framework guide in docs/guides/ with tutorial code in examples/guides/<name>/.
  • A row in the CI connector matrix (.github/workflows/ci.yml) and a Guide in scripts/gen_doc_examples.py; run it for the new group.
  • uv run python scripts/gen_docs_reference.py regenerates the connector table and conformance summaries.

A new domain

A domain is a scenario family judged by its own grader (see decision 0002). Checklist:

  • Add the name to Domain and DOMAINS in core/scenario.py.
  • A policy model in domains/<domain>/policy.py (subclass PolicyBase, narrow domain to a literal, add a view() for lookup_policy), registered in domains/policy.py (_models, POLICY_DOMAINS); regenerate each schema with uv run credencestack packs schema policy-<domain> > schemas/<domain>_policy.schema.json.
  • Seed models under env/<domain>/ (strict pydantic), added to EnvSeed.
  • Tool specs in env/families.py (unique names; consequential, kind, action), a family name in ToolFamily, the domain's default families in DEFAULT_FAMILIES, and outage services in SERVICE_FAMILY_TOOLS.
  • A world (handlers(), snapshot()) registered in env/environment.py (WORLD_OF_FAMILY, WORLDS).
  • An grader with expected and judge in domains/<domain>/grader.py, registered in domains/__init__.py (GRADERS). Put the decision in a pure function the safe reference agent can share.
  • Finding types in core/findings.py with pillars (FINDING_PILLARS) and fixed severities (FINDING_SEVERITY), mapped in evidence/mappings/frameworks.yaml (indicative), documented in docs/running.md#findings.
  • Naive and safe reference agents in agents/, registered in agents/scripted.py (DOMAIN_AGENTS).
  • A synthetic pack under packs/builtin/<pack>/ with synthetic: true and a README, the name in DOMAIN_PACKS, a pack page in docs/packs/, and MIN_NAIVE_FAILURES in tests/integration/test_domain_packs.py.
  • Unit tests for the grader and the world; scripts/check_synthetic.py passes.

A domain policy

Policies are data: a user writes their own and runs with --policy. To change what a policy can say:

  • Add the field to the domain's policy model with a default that keeps existing policies valid, a description, and validation (ranges, cross-field checks).
  • Use it in the grader and, if the agent should see it, it appears in view().
  • Update the shipped example (packs/builtin/policies/<domain>_policy.yaml), keep synthetic_examples: true, and mark any regulatory value indicative (and in docs/dev/todo-verify.md if it is unverified).
  • Regenerate the policy schemas and the docs (scripts/gen_docs_reference.py).
  • Test the new behaviour with parse_policy and credencestack profiles explain.