Skip to main content

Reliability layer for LLM agents: scope drift, cost circuit breaks, and procedural correction memory as event-driven decisions

Project description

noos (Python)

Python bindings for Noos, a reliability layer for LLM agents: scope drift, cost circuit breaks, procedural correction memory, and tool-call loop detection as event-driven decisions.

The Rust core is unchanged — this package ships a native extension (noos.abi3.*.so / .pyd) built from the same crate published on crates.io.

Status

0.1.0 — code complete + CI validated on ubuntu-latest. Publish workflow (.github/workflows/publish.yml) builds and publishes abi3-py39 wheels for Linux / macOS / Windows on every v* tag. Requires PYPI_API_TOKEN repo secret.

Install

pip install noos

Wheels are published for CPython 3.9+ on Linux (x86_64, aarch64), macOS (x86_64, arm64), and Windows (x86_64). Other platforms build from source (requires a Rust toolchain).

Quick start

from noos import Regulator, LLMEvent

r = Regulator.for_user("alice").with_cost_cap(2000)

r.on_event(LLMEvent.turn_start("Refactor fetch_user to be async"))

# ... call your LLM of choice; collect response text ...

r.on_event(LLMEvent.turn_complete(response_text))
r.on_event(LLMEvent.cost(
    tokens_in=25,
    tokens_out=800,
    wallclock_ms=500,
    provider="anthropic",
))

decision = r.decide()

match decision.kind:
    case "continue":
        pass  # deliver response
    case "scope_drift_warn":
        print(f"drift {decision.drift_score:.2f}: {decision.drift_tokens}")
    case "circuit_break":
        print(f"halt: {decision.suggestion} (reason: {decision.reason.kind})")
    case "procedural_warning":
        for p in decision.patterns:
            print(f"learned rule {p.pattern_name}: {p.example_corrections}")

The full per-event contract + pre- vs post-generation decide() timing rules lives in the Rust crate's docs/regulator-guide.md.

API summary

Class Purpose
Regulator Main API. for_user(id), with_cost_cap(n), on_event(e), decide(), export_json(), from_json(s) + accessors.
LLMEvent Event constructors. turn_start, token, turn_complete, cost, quality_feedback, user_correction, tool_call, tool_result.
Decision Output of decide(). .kind + variant-specific attributes.
CircuitBreakReason Nested on Decision.reason when kind == "circuit_break".
CorrectionPattern Items of Decision.patterns when kind == "procedural_warning".

Decision variants

decision.kind is one of:

kind Available attributes
continue
scope_drift_warn drift_score, drift_tokens, task_tokens
circuit_break reason (a CircuitBreakReason), suggestion
procedural_warning patterns (list of CorrectionPattern)
low_confidence_spans reserved

CircuitBreakReason variants

reason.kind is one of:

kind Available attributes
cost_cap_reached tokens_spent, tokens_cap, mean_quality_last_n
quality_decline_no_recovery turns, mean_delta
repeated_failure_pattern cluster, failure_count
repeated_tool_call_loop tool_name, consecutive_count

Persistence

# Save
snapshot: str = r.export_json()
with open("regulator.json", "w") as f:
    f.write(snapshot)

# Restore
with open("regulator.json") as f:
    r = Regulator.from_json(f.read())

The snapshot carries cross-session learning (strategy EMA + correction patterns above the emergence threshold). Malformed JSON raises ValueError.

Path B helper (prompt injection)

Once a CorrectionPattern has emerged on a topic cluster, the cheapest way to apply it is to prepend the learned examples to the next user prompt:

prompt = r.inject_corrections(user_message)
response = my_llm.complete(prompt)

inject_corrections is a no-op when decide() wouldn't fire procedural_warning — so it's safe to wrap every prompt.

Build from source

Requires: Rust toolchain (1.75+), Python 3.9+, maturin.

pip install maturin
cd bindings/python
maturin develop --release

For a wheel you can redistribute:

maturin build --release
# wheel lands in target/wheels/

License

MIT. Same as the Rust crate.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

noos-0.1.0-cp39-abi3-win_amd64.whl (961.5 kB view details)

Uploaded CPython 3.9+Windows x86-64

noos-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

noos-0.1.0-cp39-abi3-macosx_11_0_arm64.whl (932.2 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

noos-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl (985.1 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file noos-0.1.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: noos-0.1.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 961.5 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for noos-0.1.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 0ec3572103755a2cf2a142ce1755ccafd77cab7d52e0d20a48ca22a4eef137d5
MD5 b6802b2335d884d629d1597eb81b958f
BLAKE2b-256 de1f4bf66886ad9740852ca8968a7c317d265e62a341d9b811256b4f16e2c32f

See more details on using hashes here.

File details

Details for the file noos-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for noos-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2f2d79b3ab16073006b3c8a6c7ef49965ae9a23607f2d1e829c34caf25eed121
MD5 00febec292c9e7457447a7d31af8d749
BLAKE2b-256 72f2e7cfee57b6133e88face6a4e905491c0397603a33bffd07d04456748737b

See more details on using hashes here.

File details

Details for the file noos-0.1.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: noos-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 932.2 kB
  • Tags: CPython 3.9+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for noos-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3b5f0539718ef4f2eb195bdcb0bee2e7ecdd24bcd31159e1dffbf58355a7ac3e
MD5 5d317300bfb7ff69983839225b039f58
BLAKE2b-256 a9f2f3e21c6355b28fd72b676a4fb3aadadad04ad77c23b3bed59422b0cfba5d

See more details on using hashes here.

File details

Details for the file noos-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: noos-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 985.1 kB
  • Tags: CPython 3.9+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for noos-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6abd748862a286258da4409b1c3418c340f4aff672f7284e63bdcbf25e76cdea
MD5 61686782bbb52e69d9db2e5948b4433f
BLAKE2b-256 4a8ad029d02f484439b521d29d10d08e281297e76c1a73c16531c4fa8d48bbdd

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