Skip to main content

nightly-sdk

The Python SDK for Nightly, the on-call engineer for your AI agents.

AI agents rarely fail loudly. A prompt change, a model swap or a tool update ships, and the agent starts answering wrong, looping, refunding money it shouldn't, or failing its tools, while every request still returns HTTP 200. Nightly watches your agent's traces and outcomes, investigates when something breaks (traces, deploy log, diff, the coding-agent prompt behind the change), prices the damage, and applies the reversible fix your policy allows: roll back the release, fail over the model, switch off a capability, or cap the steps. It proves the fix by replaying the failed runs through your agent, then pages you once in Slack. Anything irreversible waits for your approval.

This SDK is how your agent takes part. With it, your agent can:

  • Read its control plane (release, model, feature flags, step cap) so Nightly can steer it during an incident without a redeploy.
  • Report deploys and outcomes so Nightly knows what changed and what a bad run costs.
  • Run verification replays so a fix is proven on real failed inputs before Nightly calls it done.

It has no dependencies and fails open. If Nightly is unreachable, every call returns the default you passed, so the SDK can never take your agent down.

Install

pip install nightly-sdk

Python 3.9+. Pair it with neatlogs tracing (pip install neatlogs), which is where Nightly reads your agent's traces from.

Get a token

Sign in to Nightly with GitHub and open Connect an agent. Creating the agent shows its token (nsa_...) once. You can rotate it from the agent's page at any time.

export NIGHTLY_API_URL=https://<your Nightly API>
export NIGHTLY_AGENT_TOKEN=nsa_...

Quickstart

import neatlogs
from nightly_sdk import Nightly

neatlogs.init(api_key=NEATLOGS_KEY, workflow_name="support-agent")
ns = Nightly()  # reads NIGHTLY_API_URL and NIGHTLY_AGENT_TOKEN


def handle(ticket: str, dry_run: bool = False) -> dict:
    prompt = load_prompt(ns.release("v12"))        # the release Nightly says is live
    model = ns.model("claude-haiku")                # a failover model during a provider outage
    max_steps = ns.max_steps(8)                     # Nightly can lower it to stop a loop
    tools = TOOLS if ns.flag("auto_refunds", True) else TOOLS_WITHOUT_REFUNDS  # kill switch

    result = run_agent(ticket, prompt, model, tools, max_steps, dry_run=dry_run)

    if not dry_run:
        ns.record("ok" if result.ok else "failed", value_usd=result.money_lost)
    return {"ok": result.ok, "output": result.text}


# Let Nightly verify a fix by replaying failed inputs through the agent, with no side effects.
ns.serve_replays(lambda text: handle(text, dry_run=True))

In CI, when you ship:

Nightly().report_deploy("v13", commit=GIT_SHA)

API

Call What it does
Nightly(api_url=None, token=None, refresh_s=5.0, timeout_s=4.0) Client. Reads NIGHTLY_API_URL and NIGHTLY_AGENT_TOKEN when arguments are omitted. Config is cached for refresh_s seconds.
ns.release(default) The release to run. Nightly changes it to roll back.
ns.model(default) The model to use. Nightly changes it to fail over.
ns.flag(name, default=True) A kill switch for a capability. Nightly turns it off to contain damage.
ns.max_steps(default) Your step limit, lowered if Nightly caps it to stop a runaway loop.
ns.config(force=False) The raw control-plane dict.
ns.report_deploy(release, commit=None, actor="ci", default_model=None) Records a deploy, so Nightly can tie an incident to the change that caused it.
ns.record(outcome, trace_id=None, value_usd=0.0, ...) Reports a graded run: ok, failed, escalated or negative. value_usd is money lost on that run. The current neatlogs/OpenTelemetry trace id is attached automatically. Optional run details: input, output, steps, tool_errors, tokens, latency_ms, cost_usd.
ns.serve_replays(handler, poll_s=3.0) Starts a background thread that runs Nightly's replay jobs through handler(input) -> {"ok": bool, "output": str}. The handler must not cause side effects.
ns.close() Stops the replay thread.
current_trace_id() The active neatlogs/OpenTelemetry trace id, or None.

report_deploy and record return True when Nightly accepted the call. They never raise.

Privacy

The SDK sends only what you pass to it: deploys, outcomes, the run details you choose, and replay results. Prompts and outputs stay in your own neatlogs project unless you pass them to record.

Metadata

Release files for nightly-sdk 0.1.2

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

Source distribution (sdist)

Source distribution for nightly-sdk 0.1.2
File Size Uploaded
nightly_sdk-0.1.2.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nightly-sdk 0.1.2
File Interpreter ABI Platform
nightly_sdk-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 13.0 kB

Release files / nightly_sdk-0.1.2.tar.gz

Download URL nightly_sdk-0.1.2.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f2debacf80405859b47535d23a72432edfeb56c5c43bde6a561256c3cbc577be
BLAKE2b-256 checksum
How to use checksums
c8e6bf5eb04b50b56f0023d58fc536d7112d19e92295feb786a8104e18bb7e6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / nightly_sdk-0.1.2-py3-none-any.whl

Download URL nightly_sdk-0.1.2-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0715a51759a59c144e0352f9f990faa7a32ba8f273fe1b4b6eef9bc4439340fe
BLAKE2b-256 checksum
How to use checksums
e52f3139164a86d733514e6707f584958a1f7bfde611c6643522f9f74cbd8f97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

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