Skip to main content

Agent Capsule Protocol for inspectable text-native artifact transfer

Project description

Agent Capsule

CI

Agent Capsule Protocol V0 is an inspectable, verifiable artifact format for moving exact machine-readable payloads through agent and text-native channels: chat, tickets, prompts, email, GitHub issues, A2A messages, MIME attachments, and agent traces.

The default capsule path is plain Base64 plus metadata, SHA256 verification, optional signatures, local policy checks, and sandbox unpacking. An experimental carrier-shaping backend exists for research, but it is not required for normal capsule use.

Current Status

Agent Capsule V0 is the product-facing layer in this repository.

  • Base64 capsules are the primary stable path.
  • Capsules can be delivered inline, as attachments, or by reference descriptor.
  • Directory bundles are deterministic JSON with per-file SHA256 and byte counts.
  • HMAC-SHA256 and optional Ed25519 signatures are supported for authenticity experiments.
  • Local policy, scan, audit, and trust-registry flows are implemented.
  • Runtime Base64 capsule encode/decode is dependency-free Python.

What Works

  • Base64 capsule pack, inspect, verify, scan, and unpack flows.
  • Signed capsule verification with HMAC and optional Ed25519.
  • Agent handoff manifests with file inventory, requested capabilities, policy hints, and delivery mode.
  • Inline, attachment, and reference delivery metadata.
  • Byte-perfect encode/decode roundtrip for the tested payload sizes and demos.
  • Deterministic output for identical payload, model, and settings.
  • Model fingerprint checks before decode.
  • Copy/paste armour with version, model fingerprint, and settings.
  • CLI file encode/decode.
  • CRC32 corruption detection inside the payload frame.
  • Unit, stress, golden, and end-to-end verification tests.

What Does Not Yet Work

  • Production identity, central trust registry, or remote policy service.
  • Encryption or privacy.
  • Large-file distribution as an inline capsule.
  • Semantically meaningful prose generation.
  • Steganography-grade secrecy.
  • Compression superiority over base64.
  • Large-file archival confidence.
  • GPU-scale model training in the runtime path.

Agent Capsule Quickstart

Use a virtual environment for local development:

python3 -m venv .venv
.venv/bin/python -m pip install -e .

This exposes the agentcapsule and capsule commands for Agent Capsules.

Create, inspect, verify, and unpack a Base64 capsule:

printf 'agent handoff state\n' > payload.txt
agentcapsule pack payload.txt --out capsule.txt
agentcapsule inspect capsule.txt
agentcapsule verify capsule.txt
agentcapsule unpack capsule.txt --out decoded
cmp payload.txt decoded/payload.txt

Create a signed handoff capsule with explicit manifest metadata:

CAPSULE_HMAC_KEY='shared secret' agentcapsule pack payload.txt \
  --out capsule.txt \
  --created-by agent-a \
  --task-id abc123 \
  --requested-capability read_files \
  --requested-capability run_tests \
  --delivery-mode inline \
  --sign-key-env CAPSULE_HMAC_KEY
CAPSULE_HMAC_KEY='shared secret' agentcapsule verify capsule.txt --key-env CAPSULE_HMAC_KEY

Emit a reference descriptor when the capsule will be stored out of band:

agentcapsule reference capsule.txt \
  --uri https://example.test/capsules/capsule.txt \
  --json

For a shorter developer path, see docs/QUICKSTART.md. For installation packaging, see docs/INSTALL.md. For release and distribution planning, see docs/RELEASE_DISTRIBUTION.md.

Agent Capsule Commands

Capsules are inspectable text artifacts that wrap exact machine-readable payloads with plaintext metadata, SHA256 verification, and safe unpack flows. The command examples below use Base64 unless a different backend is selected explicitly. capsule remains an alias for agentcapsule.

agentcapsule pack examples/agent_capsule_demo/handoff --out capsule.txt
agentcapsule inspect capsule.txt
agentcapsule verify capsule.txt
agentcapsule unpack capsule.txt --out decoded
agentcapsule scan capsule.txt
agentcapsule codecs
agentcapsule inspect capsule.txt --json
CAPSULE_HMAC_KEY='shared secret' agentcapsule pack payload.bin --out capsule.txt --sign-key-env CAPSULE_HMAC_KEY
agentcapsule keys generate --private-key publisher.key --public-key publisher.pub
agentcapsule pack payload.bin --out capsule.txt --sign-ed25519-key publisher.key --signature-key-id publisher
agentcapsule verify capsule.txt --ed25519-public-key publisher.pub
agentcapsule verify capsule.txt --signature-registry trusted-keys.json
agentcapsule verify capsule.txt --audit-json

Core capsule, HMAC, and base64 workflows work with the default dependency-free install. Ed25519 demos/tests require the optional signing extra:

python3 -m pip install -e ".[signing]"

For Ed25519, distinguish validity from trust: signature_verification: ok means the capsule was signed by the matching key; signature_trust.status: trusted means the key also passed local registry and policy checks.

capsule scan --json emits typed findings with source locations for governance logs and agent traces. --audit-json on inspect, verify, unpack, and scan emits a consistent allow/review/block governance event.

See docs/AGENT_CAPSULE_PROTOCOL_V0.md and docs/AGENT_CAPSULE_PRODUCT_BRIEF.md. For security assumptions, HMAC limits, and governance policy examples, see docs/AGENT_CAPSULE_THREAT_MODEL.md. For the public-key signing proposal, see docs/AGENT_CAPSULE_ED25519_DESIGN.md. For structured governance events, see docs/AGENT_CAPSULE_AUDIT_LOG_V0.md. For an observable agent-to-agent handoff experiment, see docs/AGENT_TO_AGENT_HANDOFF_DEMO.md. The handoff demo writes events.jsonl plus an evaluator report that checks the summary, capsule, registry-trusted signature, sandbox unpack, and artifact comparison evidence. For enterprise policy tiers, see docs/AGENT_HANDOFF_POLICY_MATRIX_V0.md. For a static observability view over handoff evidence, see docs/AGENT_HANDOFF_OBSERVABILITY_DASHBOARD_V0.md. For the central trust registry direction, see docs/AGENT_CAPSULE_CENTRAL_TRUST_REGISTRY.md.

Research Backends

The repository also contains experimental carrier-shaping backends used for research and regression coverage.

The research path has five core layers:

  • Frame: wraps the payload as magic || payload_len || crc32 || payload.
  • Range coder: provides the reversible bit-to-symbol mapping.
  • LM probabilities: provide the next-token carrier distribution.
  • Quantizer: converts floating-point probabilities into deterministic integer CDFs for range coding.
  • Armour: stores carrier text with version, model fingerprint, and settings in a copy/paste-safe text block.

Encoding:

payload bytes
  -> binary frame
  -> framed bits
  -> source RangeDecoder over framed bits
  -> LM probabilities + shaping + quantization
  -> carrier token choices
  -> mirror RangeEncoder stopping check
  -> armoured text

Decoding:

armoured text
  -> parse and check model fingerprint
  -> carrier tokens
  -> same LM probabilities + shaping + quantization
  -> RangeEncoder reconstructs framed bits
  -> frame parser validates magic, length, and CRC32
  -> payload bytes

The stopping condition is intentionally conservative. Range decoders use lookahead, so encode does not stop based on a naive "all bits consumed" rule. Instead, the research carrier keeps a mirror range encoder and stops only when its finalized preview has the framed payload bits as a prefix.

Verification

PYTHONPATH=src python3 -m unittest discover -s tests

Full V1 verification:

sh scripts/verify_v1.sh

Installed CLI release check:

sh scripts/release_check.sh

Demo And Experiment Scripts

sh scripts/demo_roundtrip.sh

Compare the fixed carrier against the trained order-1 n-gram carrier:

sh scripts/demo_compare.sh

Run the pinned Transformer carrier demo:

sh scripts/demo_transformer.sh

Create deterministic carrier corpora and train/held-out splits:

scripts/build_carrier_corpus.py \
  --out examples/carrier_corpus_v2.txt \
  --lines 5000 \
  --seed 42 \
  --domain mixed
scripts/split_corpus.py \
  --input examples/carrier_corpus_v2.txt \
  --train-out examples/carrier_train_v2.txt \
  --heldout-out examples/carrier_heldout_v2.txt \
  --heldout-ratio 0.20 \
  --filter-vocab

Compare models with optional benchmark JSON:

scripts/compare_models.py \
  --payload payload.bin \
  --corpus examples/carrier_train_v2.txt \
  --quality-text examples/carrier_heldout_v2.txt \
  --json-out benchmark.json

Run a bounded V2 experiment config:

scripts/run_experiment.py experiments/configs/example_fixed.json

Optional PyTorch training/export is available in scripts/train_transformer_torch.py. PyTorch is only needed for that exporter; the exported JSON model loads through the dependency-free TransformerLM runtime.

Research Notes

Probability shaping is intentionally separate from the models. Defaults are a no-op, while non-default shaping settings are written into the armour so decode can reproduce the same distribution. Uniform mixing and temperature are guardrails for keeping model distributions usable by the range coder; they are not a claim of natural language quality.

Greedy previews are useful diagnostics, but they are not representative of encoded carrier text. The actual carrier is selected by payload bits through the range coder under the model distribution.

Current demo metrics for bytes(range(256)):

  • Payload bytes: 256
  • Carrier chars: 358
  • Bits per carrier char: 5.989
  • Base64 baseline chars: 344

Pinned Transformer fixture metrics for bytes(range(256)) with --shape-uniform-mix 0.80 --temperature 1.25:

  • Payload bytes: 256
  • Carrier chars: 362
  • Bits per carrier char: 5.923

Documentation

Golden V1 Fixtures

All golden fixtures use payload bytes(range(256)).

Payload SHA256:

40aff2e9d2d8922e47afd4648e6967497158785fbd1da870e7110266bf944880

Fixed carrier:

  • Message fixture: tests/fixtures/golden_message_v1.txt
  • Model fingerprint: d60583f4d741e42cb713b11c78b8ffc89cda1ee05eca522929bec8cbdb423be8
  • Message SHA256: f53ec3604a378788b20cf6e0aadbfe441a063aa7ce1cea0bef9b1427cbd21e35

Order-1 n-gram carrier fixture:

Transformer carrier fixture:

Regenerate golden fixtures only after intentional codec changes:

python3 scripts/generate_golden.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentcapsule-0.1.0.tar.gz (72.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentcapsule-0.1.0-py3-none-any.whl (56.9 kB view details)

Uploaded Python 3

File details

Details for the file agentcapsule-0.1.0.tar.gz.

File metadata

  • Download URL: agentcapsule-0.1.0.tar.gz
  • Upload date:
  • Size: 72.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for agentcapsule-0.1.0.tar.gz
Algorithm Hash digest
SHA256 93e374c354f27484363fffe9003935dcbc7720fa2382c96fdf3704a5d63b78b3
MD5 0bc8125c6b57207fc6e84120ee7f96e4
BLAKE2b-256 dddef1dd6970d16f8630add61f5fbbbb1a9e622879538dc9a60520d7acfe84f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentcapsule-0.1.0.tar.gz:

Publisher: pypi-publish.yml on arikyp/agentcapsule

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agentcapsule-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: agentcapsule-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 56.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for agentcapsule-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 59537e07b4597a4c3e572ffb392e5a4a7f2e0a7e4eee8b775b788902a3cce7bb
MD5 dfdb1565597e816e66e62ce8ea4f2579
BLAKE2b-256 7a8316aa076ac576336ba1f205cab6e133d13880986501a07f7b9a92a7b66ea3

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentcapsule-0.1.0-py3-none-any.whl:

Publisher: pypi-publish.yml on arikyp/agentcapsule

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page