Skip to main content

Contract-bounded autonomy for LLM agents: five small primitives that make an agent safe to leave alone.

Project description

bounded-agent

Contract-bounded autonomy for LLM agents: five small primitives that make an agent safe to leave alone.

The model is table stakes. The reliability of an autonomous agent lives in the harness — the deterministic structure around the LLM that decides what it may see, what it may say, what it may do, and what happens when it fails. This library is that harness, reduced to its five load-bearing primitives, each ~50 lines, each independently testable, built on top of PydanticAI (which already solves the typed-LLM-call problem — we don't rebuild it, we add the autonomy layer it deliberately leaves to you).

The design stance, in one sentence: deterministic spine, agentic leaves — code you can test decides the flow; the LLM reasons inside well-fenced steps and never pilots the loop.

The manifesto: The Edge Is the Harness, Not the Model — the argument this library implements, and the start of a series that takes each primitive in depth.

The five primitives

Module Primitive The failure it prevents
contracts.py Contracts & gates — a declared book of who may do what, at which autonomy tier (observe / propose / act) an agent quietly acquiring capabilities nobody signed off on
leaf.py The typed leaf & the escalate-only floor — LLM output is a validated type or an error value; an LLM may raise an alarm, never silence one a plausible-sounding model response lowering a deterministic alarm
actions.py The double-closed action set — an action runs only if it is both contracted and implemented; everything else is refused and recorded prompt-injected or hallucinated actions; silent capability creep
ledgers.py Evidence & idempotency ledgers — append-only truth for every action and verdict; a finding alerts once per period, not forever un-auditable agents; alert fatigue that trains humans to ignore the pager
envelope.py The safety envelope — ships disarmed, kill-switch checked before anything runs, a hard per-run breaker, and act-then-report (silence is impossible) the runaway loop; the agent that did things nobody heard about

Quickstart

uv add bounded-agent            # or: pip install bounded-agent
from bounded_agent import ContractBook, Gate, ActionSet, Envelope, EvidenceLedger

book = ContractBook.load("contracts.yaml")            # raises loudly if missing/malformed
gate = Gate(required_scope="checkout-stack", required_tier="act")
granted = book.granted(gate)                          # {contract-name: (allowed actions,)}

actions = ActionSet()
actions.register("restart_worker", restart_worker)    # the implemented closed set

env = Envelope(armed=True, kill_switch_path=Path("STOP"),
               max_actions_per_run=2, notify=page_the_operator)
outcome = actions.execute(list(granted.items()), env,
                          ledger=EvidenceLedger(Path("ledger")), period=today)

An action fires only if it appears in both the contract's allows list and the registered set — and only inside an armed envelope with no kill-switch present and breaker budget remaining. Everything that happens (and everything refused) is one JSONL line.

For the LLM side, see examples/sentinel/ — a complete service-health watchdog: deterministic probes → an escalate-only LLM verdict → a typed diagnosis → contract-bounded remediation. It runs offline with no API key (PydanticAI's TestModel) so you can study the whole loop before connecting a real model.

What this deliberately is NOT

Stating the non-goals is part of the teaching — most agent failures start with adopting more machinery than the problem earns:

  • Not a planner. No GOAP, no A*-search over preconditions. If you can hardcode the flow, hardcode the flow.
  • Not a durable-execution engine. Design your steps idempotent and re-run from clean; reach for Temporal/DBOS only when a mid-run crash would genuinely corrupt or double-charge.
  • Not a graph framework. Small fixed pipelines and explicit state machines in plain code beat a graph DSL until your control flow is genuinely graph-shaped.
  • Not a PydanticAI replacement. The typed leaf is solved; this is the autonomy layer above it. If PydanticAI grows this layer, this library should shrink.

Status

A teaching artifact, maintained best-effort. The patterns here are extracted from a production system that runs unattended daily; the code is written fresh for clarity. Issues and discussion welcome; roadmap promises are not made.

License

MIT

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

bounded_agent-0.1.0.tar.gz (41.2 kB view details)

Uploaded Source

Built Distribution

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

bounded_agent-0.1.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bounded_agent-0.1.0.tar.gz
  • Upload date:
  • Size: 41.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for bounded_agent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ff5174bdc4fea58c93ff1b374580618970ff7b489f0e596639e63a97cc951b51
MD5 2afffc114d0c833ead4271fa6d822f1f
BLAKE2b-256 a117859d0f600c6c839d74fbd27fcefc9412ae52760987472377a8872a4cbe97

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bounded_agent-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for bounded_agent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0afa94e5743d9bf05c5a1cc20d53b0a1992fd29ee6302707026ebc1b58b43660
MD5 1444d0d4d496dc57f6bc4349c1064951
BLAKE2b-256 5ce1a9938d2ffc25553ecdfcc638f90f7a6b04bc8c59fbb3d46ba79b4c2e7518

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