Skip to main content

SRBN

srbn is a small Python library for reliable long-horizon work with language model systems. It does one thing: it runs a generator behind explicit checks, records every attempt, and stops only when the accepted output satisfies the declared tolerance or the policy says no further progress is certified.

It is a library, not an agent framework. There are no providers, planners, databases, background workers, or hidden orchestration layers in the core.

import srbn


def generate(prompt: str, feedback: str | None) -> str:
    if feedback:
        return "please approve the request"
    return "approve the request"


result = srbn.run(
    "Write a polite request",
    generate=generate,
    checks=[srbn.contains("please")],
)

assert result.ok
print(result.output)

Install

pip install srbn
# or
uv add srbn

Python 3.12+. The core package has zero runtime dependencies.

Model

Reliable long-horizon systems need to preserve checked state. SRBN expresses that requirement as a small control loop.

  1. A generator proposes an output.
  2. Checks report residuals.
  3. Residuals are aggregated into a non-negative score.
  4. Failed checks produce feedback for the next proposal.
  5. The trace records the evidence used to accept, stop, or exhaust the run.

The score is a runtime proxy for Lyapunov or barrier energy. A score of 0.0 means the configured checks pass cleanly. A positive score means some declared condition remains unsatisfied.

With Policy(require_descent=True, on_no_descent="stop"), the loop also enforces a measured descent gate: a new attempt must reduce the score by more than min_descent, or the run stops with Status.STOPPED.

API

Symbol Purpose
srbn.run(...) Text-in, text-out checked generation.
srbn.stabilize(...) Generic loop for arbitrary typed state.
srbn.Client(...) Reusable wrapper around run.
srbn.Policy(...) Attempt budget, tolerance, and descent settings.
srbn.CheckResult Check outcome: ok, score, feedback, evidence.
srbn.BarrierResult Structured-state barrier outcome.
srbn.Result.trace Complete attempt history.

Built-in checks are intentionally plain:

checks = [
    srbn.contains("SELECT"),
    srbn.not_contains("DROP"),
    srbn.json_valid(),
]

Domain checks are just callables that return CheckResult.

def has_ticket_id(output: str) -> srbn.CheckResult:
    ok = "REQ-" in output
    return srbn.CheckResult(
        ok=ok,
        score=0.0 if ok else 1.0,
        feedback="" if ok else "Include a request id.",
        name="has_ticket_id",
        evidence={"required_prefix": "REQ-"},
    )

Structured State

Use stabilize when the state is not text.

def barrier(x: int) -> srbn.BarrierResult:
    residual = abs(x)
    return srbn.BarrierResult(
        ok=x == 0,
        score=float(residual),
        feedback="move toward zero",
        correction=-1 if x > 0 else 1,
        name="distance_to_zero",
    )


def update(x: int, result: srbn.BarrierResult) -> int:
    return x + int(result.correction or 0)


result = srbn.stabilize(3, barrier=barrier, update=update)
assert result.state == 0

What Belongs Outside Core

The core deliberately excludes:

  • provider SDKs;
  • tool execution;
  • multi-agent orchestration;
  • capability security;
  • risk calibration;
  • durable storage;
  • domain-specific verifier suites.

Those are application or plugin concerns. The core stays small so it can be embedded anywhere.

Development

uv sync
uv run --with pytest python -m pytest projects/python/srbn/tests
uv run --with ruff python -m ruff check projects/python/srbn/src projects/python/srbn/tests

License

GNU Lesser General Public License v3.0 only.

Citing

If you use SRBN in research, cite the Stability Is All You Need paper series.

Download files

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

Source Distribution

srbn-0.1.1.tar.gz (30.6 kB view details)

Uploaded Source

Built Distribution

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

srbn-0.1.1-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file srbn-0.1.1.tar.gz.

File metadata

  • Download URL: srbn-0.1.1.tar.gz
  • Upload date:
  • Size: 30.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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 srbn-0.1.1.tar.gz
Algorithm Hash digest
SHA256 62bc229632e58da68b2106565015d41509eca25a9b77fb7738cc9ffc580ac802
MD5 3aef33eb17e5bb05177e4a132c0e2b22
BLAKE2b-256 11a977b29d93219ca0cce1757565f450f353ebbfb0a4367b9487fb6b234a9834

See more details on using hashes here.

File details

Details for the file srbn-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: srbn-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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 srbn-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4b5da81bd7a6166334f7b1dd9b8e315c419a825c97e7bee702d47c558870c280
MD5 c94fba89aa88dcad1da61e573454b7ab
BLAKE2b-256 a1aa392535602f1856024f1b09e0ff1b649f08e5b52e98afca23e122053e5610

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