Skip to main content

Contractual runtime for AI agents — pre/post contracts, policy enforcement, credits metering, checkpoint & replay

Project description

DEED

Contractual runtime for AI agents.

pip install deed-runtime

Zero dependencies. Python 3.10+.


The problem

Your AI agent ran. Something unexpected happened. No pre-conditions checked. No audit trail. No rollback.

The answer

Every action passes through a contract:

agent score_agent
  contract score_contract
    pre  company_name_present
    post score_generated

  policy
    cap  budget_tokens <= 5000
    deny score_company if region == "restricted"
    allow score_company if company_name_present
  • Pre-condition fails → action rejected, no side effects, no credits charged
  • Post-condition fails → DLQ entry written, credits refunded
  • Policy violation → blocked before execution

Five lines

from deed import DeedRuntime

runtime = DeedRuntime(".")
runtime.register("score_company", my_scorer, charge=1)
result = runtime.run("my_pipeline", "input/state.json")
print(result["score"])  # 0.82

What you get

  • Pre/post contracts on every agent action
  • Policy engine (cap / allow / deny) enforced before execution
  • DEED Credits metering — charge per deed, refund on violation
  • Checkpoint & replay — resume from last known good state
  • DLQ — failed stages captured with full context

Examples

Mushroom Safety Triage — main working example

A four-stage safety-critical pipeline demonstrating contracts and the failure path.

cd examples/mushroom_safety
python run.py           # happy path → completed
python run.py --fail    # ContractViolation → DLQ

Stages: intake → taxonomy → risk → advisory


Sales Intelligence Agent — working example

A three-stage B2B sales pipeline with ICP scoring and outreach brief generation.

cd examples/sales_agent
python run.py               # happy path → completed, score 1.0
python run.py --restricted  # policy deny → failed (region == "restricted")

Stages: enrich → score → brief


Orchid Rescue Lab — .dd reference only

Agent specs and pipeline for a conservation triage workflow. No run.py — use the .dd files as reference for writing your own vertical.

examples/orchid_rescue/
├── deeds/agents/       legality_agent.dd, triage_agent.dd, curator_agent.dd
└── deeds/pipelines/    orchid_rescue_intelligence.dd

How register() works

runtime = DeedRuntime(
    project_root=".",           # must contain deeds/ with .dd files
    initial_credits=100,
    named_predicates_fn=my_fn,  # optional: callable(context) -> dict[str, bool]
)

(runtime
    .register("normalize",    normalize_fn,  charge=1)
    .register("score",        score_fn,      charge=1, retry=2)
    .register("send_alert",   alert_fn,      charge=1, idempotency_key="alert_id")
)

result = runtime.run("my_pipeline", "input/state.json")

.dd syntax

agent my_agent
  capabilities ["action_a", "action_b"]

  contract my_contract
    pre  input_present
    post result_generated

  policy
    cap  budget_tokens <= 3000
    deny action_b if region == "restricted"
    allow action_a if input_present

pipeline my_pipeline
  stage step_one
    agent my_agent
    -> action_a()
    checkpoint after
    on_error retry

  stage step_two
    agent my_agent
    -> action_b()
    on_error deadletter

Error types

from deed import ContractViolation, PolicyViolation, DeedError

try:
    result = runtime.run("my_pipeline", "input/state.json")
except ContractViolation as e:
    # pre or post condition failed
    # pre: action was NOT executed, no credits charged
    # post: action ran but outcome invalid, credits refunded
    print(e)
except PolicyViolation as e:
    # cap / deny / allow rule blocked the action
    # action was NOT executed, no credits charged
    print(e)

Replay after failure

# Resume from last checkpoint — skips completed steps, credits not re-charged
runtime = DeedRuntime(".", replay=True, initial_credits=100, ...)
runtime.register(...)
result = runtime.run("my_pipeline", "input/state.json")

Writing .dd files with an LLM

docs/MASTER_MANUAL_FOR_LLM.md is a complete authoring guide for generating .dd files. Use it as a system prompt to make any LLM produce idiomatic DEED agent specs from a domain description.

Includes: canonical model, naming conventions, anti-patterns, few-shot examples, validation checklist, templates for agent and pipeline blocks.


DEED Credits

Every deed execution costs credits (default: 1 credit per action, configurable per register()).

print(runtime.x402.credits)   # remaining balance
print(runtime.x402.spent)     # total spent this run

Credits are charged after the pre-condition passes and refunded automatically on post-condition failure. The metering layer uses the X402Client interface, which is designed for forward compatibility with the x402 payment protocol.


Docs

deed-docs.onrender.com

License

MIT — Deadly-Reiter

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

deed_runtime-0.1.1a0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

deed_runtime-0.1.1a0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file deed_runtime-0.1.1a0.tar.gz.

File metadata

  • Download URL: deed_runtime-0.1.1a0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for deed_runtime-0.1.1a0.tar.gz
Algorithm Hash digest
SHA256 cc5d38e6a86efe7f688fa8e0d1fc4764b73acd71c498664bf4a8b739f4a15544
MD5 bd0ba470d8231d756bad07b7bea14efa
BLAKE2b-256 e40c1e4de2b34eea870b9f0079eea354a30d98c3591226176e7d6de87af2af98

See more details on using hashes here.

File details

Details for the file deed_runtime-0.1.1a0-py3-none-any.whl.

File metadata

  • Download URL: deed_runtime-0.1.1a0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for deed_runtime-0.1.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 c944c2e041a50fce610339dbce04aa59d03451d8b124a1d5107f8103cba1bf20
MD5 4bd3f9b2176affd90bfbf5a919f9fc57
BLAKE2b-256 a340033599ccb5293413f5780e913472fa1c5fed9bb7c70f4f1c5631ff12d21d

See more details on using hashes here.

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