Skip to main content

nodloop for Python

Record what your agent answered, take a person's verdict on it, and hand the corrections they approve to the agent's next run in the same situation. This is the Python client of nodloop.

pip install nodloop
pip install "nodloop[langchain]"      # or openai-agents, claude-agent

The client starts a local nodloop mcp over stdio, so no server runs. It uses NODLOOP_BIN, then the binary the Claude Code plugin keeps under ~/.nodloop/bin, then nodloop on PATH, and otherwise downloads the release of its own version from GitHub and checks it against the release checksums. It requires Python 3.10 or newer and is tested on Linux with Python 3.12.

The loop

from nodloop import Client

acme = {"tenant": ["acme"], "task": ["refund"]}

async with Client() as c:
    knowledge = await c.knowledge("support-bot", acme)
    prompt = f"{system_prompt}\n\n{knowledge.text}"  # empty text when nothing is approved
    answer = await my_agent(prompt)
    run = await c.record("support-bot", answer, labels=acme, applied=knowledge.items)

    # later, when a person reads the answer
    await c.judge(run, "reject", "ann", reason="the refund window was missing", reason_code="scope")
    candidate = await c.propose("judgment", "Quote the refund window before the steps", from_run=run)

The person approves the candidate in a terminal of their own with nodloop knowledge approve <id> --version <n>, or the client approves it through a nodloop server under an approver key the person holds, added with --person. Over stdio approve records a proposal and changes nothing, since a program proves no person. From then on every knowledge("support-bot", acme) carries the item, and a run of another tenant never does. judge takes approve, edit with edited= holding the corrected output, reject with what was wrong, or withdraw to take back the verdict before it, and always the name of the reviewer.

Method Returns
knowledge(producer, labels, holdout_key) Knowledge with items, the text to put in the prompt and withheld. With a holdout_key such as <service>:<hour>, the holdout share of config.json gets no items and withheld instead
record(producer, output, *, labels, applied, subject, withheld, holdout_key, model) the run id a verdict cites. Pass knowledge.withheld as withheld and the holdout_key the run passed to knowledge. report effect counts only runs recorded with the key and counts a run without it as undrawn. withheld takes Ref or Item values. model names the one model the producer runs, which the OTLP export sends as gen_ai.request.model. Leave it out when the producer may switch models
judge(run, verdict, reviewer, reason, reason_code, edited) nothing. reviewer is required, so a verdict without a name never reads as a person's
propose(kind, content, from_run, producer, labels, new_labels, item_id, veto) Candidate with id, version, status and overlaps, the current items of the same kind one run may carry with it
approve(item_id, version, approver, labels=) Under a key of a nodloop server that a person holds, approves as proposed, or for the runs carrying labels when given, and {} for every run of the producer. Anywhere else it records a proposal the person is asked about and the status stays. Approval with id, version, status, approver, veto, proposal when a proposal was recorded, and export_error and folder_error when a step after the approval failed
check_call(tool, arguments, producer) Decision with action of allow, block or ask, veto and reason
outcome(run, result, confirmed_cause, note, reviewer) nothing. result is a Result, confirmed, refuted or inconclusive: what a real check found, apart from the verdict on the output. Over stdio reviewer is required
report(name) Report with report, the report as JSON, and since, the RFC3339 start of the runs it read or empty for every run. name is a ReportName: loop, extract, critic, effect, health or replay. critic is {critics, reactions}: the rows of the draft critics and of the reaction classifiers

A tool that refuses, such as a proposal from a run nobody corrected, raises ToolError with the reason.

Every adapter takes an optional holdout_key, passes it to knowledge and record and records what came back as applied or withheld.

A stream producer with a holdout

A producer that runs on a schedule, such as an anomaly check over each window of a stream, draws the holdout on a key it keeps for the run. Use <service>:<time block of an hour or more> so the windows of one block land in the same arm and a lesson seen in one window does not leak into a withheld window next to it.

from datetime import datetime, timezone

block = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H")  # one hour
orders = {"service": ["orders"]}
knowledge = await c.knowledge("lag-check", orders, holdout_key=f"orders:{block}")
answer = await check(window, knowledge.text)
run = await c.record(
    "lag-check", answer, labels=orders, applied=knowledge.items, withheld=knowledge.withheld, holdout_key=f"orders:{block}"
)

# later, when the cause was checked
await c.outcome(run, "confirmed", confirmed_cause="partition 7 was hot", reviewer="ann")
effect = (await c.report("effect")).report

The share comes from holdout in config.json. With url the share is the one in the config.json of the nodloop server, read when the server starts.

Adapters

LangChain create_agent middleware fetches the items once per run and puts them in the system message, records the final answer and refuses a vetoed tool call:

from nodloop.langchain import NodloopMiddleware

mw = NodloopMiddleware(c, "support-bot", acme)
agent = create_agent(model, tools, middleware=[mw])
await agent.ainvoke({"messages": [...]})
await c.judge(mw.run, "approve", "ann")

OpenAI Agents SDK hooks and a tool input guardrail:

from nodloop.openai_agents import NodloopHooks, veto_guardrail

hooks = NodloopHooks(c, "support-bot", acme)
agent = Agent(name="support", instructions=hooks.instructions("You help with refunds"), tools=[...])
await Runner.run(agent, "refund?", hooks=hooks)

Pass veto_guardrail(c, "support-bot") in a tool's tool_input_guardrails.

Claude Agent SDK hooks, the same loop the Claude Code plugin runs:

from nodloop.claude_agent import NodloopHooks

hooks = NodloopHooks(c, "support-bot", acme, holdout_key=conversation_id)
options = ClaudeAgentOptions(hooks=hooks.hooks())

Use one adapter instance per run or conversation, since it keeps the items it handed out and the id of the run it recorded.

The Claude Agent hooks draw once per conversation since the key stays the same for every turn, so a whole conversation is in one arm. report effect counts every turn of one key as one draw unit, so the turns of a conversation widen its intervals instead of passing for independent samples.

A shared server

Client(url="https://nodloop.example/mcp", key="nl_...") connects to nodloop-server serve instead of a local binary. The key decides the tenant and what the client may do, and an approval through it is recorded under the key's name.

More

The nodloop README covers labels, vetoes, reports and the server. MIT licensed.

Metadata

Release files for nodloop 0.10.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nodloop 0.10.3
File Size Uploaded Provenance Actions
nodloop-0.10.3.tar.gz 190.1 kB Without provenance Details for nodloop-0.10.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nodloop 0.10.3
File Interpreter ABI Platform Actions
nodloop-0.10.3-py3-none-any.whl Python 3 none any Details for nodloop-0.10.3-py3-none-any.whl

Total release size: 212.5 kB

Release files / nodloop-0.10.3.tar.gz

Download URL nodloop-0.10.3.tar.gz
Size 190.1 kB
Tags Source
SHA-256 checksum
How to use checksums
95d7ee1d8f49d8bfd2569bb96eb1f76af140c1af9839e9a81f877a7fac62af3d
BLAKE2b-256 checksum
How to use checksums
83f05e5b288a30f06e5fc60dedd3cf85f2dc73d272bcfc8c2e9a663f8f12cbcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / nodloop-0.10.3-py3-none-any.whl

Download URL nodloop-0.10.3-py3-none-any.whl
Size 22.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb53374fbf0a92d5b72664600d20897524737bd70112a92a547cea137b6ef37c
BLAKE2b-256 checksum
How to use checksums
7bcc09c3854e262bced8531de967c5f4c9b23fa5be9a1131e2468b387fef6996
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for nodloop 0.10.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page