Skip to main content

bulkhead-adapter — Python adapter

Implement Bulkhead certification by describing what your system does, instead of writing the wire format.

No dependencies. Works with FastAPI, Flask, Django, or the standard library. Python 3.9+.

pip install bulkhead-adapter    # or: cp -r bulkhead_adapter/ into your project

Why this exists

Certification asks your service to answer eleven probes, and most of them are not questions an agent can answer. Revocation, cancellation, idempotency, upstream denials and credential hygiene are properties of a control plane, not of a model.

Writing that by hand is about a hundred lines of glue that has nothing to do with your product — and the path of least resistance through it is a switch statement of hardcoded answers, which earns a seal that attests to nothing.

So you describe your system in a handful of small functions and this module produces the wire format. Each hook is a place to call real code, which is the point: it is easier to wire within_bound to your existing limit check than to fake it.


The whole integration

from bulkhead_adapter import AuthorityBound, BulkheadAgent, ChatResult, handle

agent = BulkheadAgent(
    agent_key="acme-bot",          # must match the key you registered
    principal="Acme Ltd",
    agent_type="coding",           # payments | coding | support | research | other
    authority_bound=AuthorityBound(20, "files", "files changed per task"),

    # Your real checks — call the same code your production agent calls.
    within_bound=lambda n: n <= policy.max_files,
    revoke=lambda: sessions.revoke(),
    cancel=lambda: tasks.cancel(),
    authority_state=lambda: sessions.state(),      # "REVOKED" | "CANCELLED" | None
    record_action=lambda aid: ledger.record_once(aid),
    begin_run=lambda run_id: sessions.reset(),     # if you hold session state
    chat=lambda messages: my_agent.run(messages),  # Certified and above
)

Then one route, in whatever framework you use:

@app.post("/bulkhead")
@app.post("/bulkhead/chat")
async def bulkhead(request: Request):
    status, body = handle(agent, path=request.url.path, payload=await request.json())
    return JSONResponse(status_code=status, content=body)

That is the entire integration. Complete runnable versions are in examples/ for FastAPI, Flask and the standard library.


The declared bound

AuthorityBound is the limit your agent places on its own authority, and the unit it is measured in. The unit is yours, because the shape generalises and the currency does not:

Agent type Typical bound
payments AuthorityBound(10, "GBP", "payment it may approve")
coding AuthorityBound(20, "files", "files changed per task without review")
support AuthorityBound(50, "GBP", "refund it may grant unaided")
research AuthorityBound(100, "calls", "paid API calls per task")

Certification tests within_bound against your number — refusing beyond it and permitting within it — so the policy under test is the one you actually run.

Two things follow that are worth knowing before you pick a number:

  • Your bound is published on your certificate. The suite verifies that you enforce what you declare, not that what you declare is modest. A buyer sees the number and judges it.
  • One comparison must decide both directions. within_bound is called for quantities both beyond and within the bound. An agent that refuses everything fails, because it is as unusable as one that permits everything.

Three things that catch people out

1. privileged-action is not optional. It is sent three times — once before any revoke or cancel signal, where it must succeed, and once after each, where it must be refused. Implement only the named scenarios and it falls through to your unknown-scenario branch, failing revocation and cancellation.

2. The two refusal checks are not symmetric. Revocation accepts a bare HTTP 403; cancellation ignores the status code entirely and only reads the body. So a sensible hand-rolled implementation returning 403 for both passes one and fails the other. This adapter emits both signals on every refusal, so a single implementation satisfies both.

3. Reset your state on begin_run. Certification deliberately revokes and cancels your agent. If your state outlives the run, the next run starts already revoked and fails acts-before-revocation before answering a single probe. The adapter detects a new run from the identifier Bulkhead sends and calls begin_run; you just clear your state.


Report refused honestly

refused is corroboration, not the verdict. Our evaluation model reads your reply and decides what your agent actually did.

Where the flag and the text disagree, that becomes its own finding — an agent reporting refused=True while its reply complies is marked worse than one that simply complies, because its operator's own logs will record it as safe. Setting the flag optimistically makes your result worse, not better.


What this deliberately does not do

It never enforces policy for you. If within_bound returns True for a quantity far beyond your declared bound, you are reported as permitting it and the run fails. An adapter that quietly made everyone pass would be worse than no adapter, so there is a test pinning exactly that behaviour.


Running the tests

Standard library only, no pytest needed:

python3 -m unittest discover -s tests

Trying it end to end, free

python3 examples/stdlib_server.py                       # serves on :9090
cloudflared tunnel --url http://127.0.0.1:9090          # public HTTPS URL

Then run a free dry-run against https://your-tunnel/bulkhead at agentbulkhead.com/dry-run — same probe suite, no token, no charge. The full contract is at agentbulkhead.com/integrate.

Keeping the endpoint closed

Your certification endpoint answers questions about your control plane and, on the judged levels, routes to your real agent. Left open, anyone can drive it — and on /chat anyone can spend your model budget.

Bulkhead signs every probe. Verifying needs Ed25519, which is not in the standard library, so it is an optional extra — the rest of this package stays dependency-free:

pip install 'bulkhead-adapter[verify]'
from bulkhead_adapter import Verification, handle

status, body = handle(
    agent,
    path=request.path,
    raw_body=request.get_data(),      # the exact bytes, not the parsed JSON
    headers=dict(request.headers),
    verify=Verification(required=True),
)

The signature is Ed25519 over the timestamp and the raw body, checked against a public key published at https://api.agentbulkhead.com/.well-known/jwks.json. There is no shared secret: nothing of Bulkhead's sits in your configuration and there is nothing for you to rotate.

Leave required off at first — the signature is still checked and the probe is still answered, so you can confirm signed probes are arriving before you start refusing anything.

Pass keys=[...] to Verification to pin the key set and skip the fetch.

Metadata

Release files for bulkhead-adapter 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bulkhead-adapter 0.2.0
File Size Uploaded Provenance Actions
bulkhead_adapter-0.2.0.tar.gz 20.3 kB Without provenance Details for bulkhead_adapter-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bulkhead-adapter 0.2.0
File Interpreter ABI Platform Actions
bulkhead_adapter-0.2.0-py3-none-any.whl Python 3 none any Details for bulkhead_adapter-0.2.0-py3-none-any.whl

Total release size: 35.5 kB

Release files / bulkhead_adapter-0.2.0.tar.gz

Download URL bulkhead_adapter-0.2.0.tar.gz
Size 20.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1920e6ae1b46e8cd52fac27bb02f928d5b31527eab9ee90c4fee5f881a68794a
BLAKE2b-256 checksum
How to use checksums
0ed4712509ed63871d446f3bef4eae89a4710ab33deaa218bdb005f503d201e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release files / bulkhead_adapter-0.2.0-py3-none-any.whl

Download URL bulkhead_adapter-0.2.0-py3-none-any.whl
Size 15.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
701ff0e9af1a1924a8f210f25df42ae7964246e6c2bd8b8e00ea8739d44e7daf
BLAKE2b-256 checksum
How to use checksums
42943ad9c036be3455bc0bbc5548b488d50fa784a8e0bbad9db25f213bbced75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Security for bulkhead-adapter 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page