Skip to main content

Kinescope

rr for AI agents. Kinescope captures every nondeterministic input so any run replays exactly, and can be branched: "what if the model had picked the other tool here?"

Kinescope records the parts of an agent run that can't be predicted (LLM calls, tool calls, the clock, RNG/UUIDs, retrieval), replays any run deterministically from the trace, and lets you fork at any step: override one recorded event and resume live from there to see what would have happened. There's a Textual timeline where you scrub through steps, inspect message/tool I/O and state diffs, and fork with one key.

The demo: an agent fails a task. You scrub to the step where it picked the wrong tool, fork, override just that decision, and watch the branched run finish. All of it is reproducible from the recording.

The Kinescope timeline TUI: forking a recorded run at the sensor step and watching the downstream classification flip from "cold" to "warm", reproduced live from the trace.

Fork-and-fix in the timeline TUI: override one recorded step, and the tail re-runs live. Reproduce it with python examples/fork_demo_tui.py.

  • Local-first, pluggable. Traces live in .kinescope/ (SQLite index + content-addressed blobs) by default, with no external services. A MongoStore backend (kinescope[mongo]) drops in through the same TraceStore port.
  • Tiny core. The engine depends on httpx only. anthropic, openai, the CLI, the TUI and Mongo are optional extras.
  • Provider-agnostic. Interception happens at the httpx transport, so the same record/replay/fork engine drives Anthropic Messages, OpenAI Chat Completions, Google Gemini generateContent (a very different wire shape, with the model in the URL instead of the body), and local models via Ollama. Only the gen_ai.* metadata normalization differs (src/kinescope/adapters/).
  • Tested on real calls. Three real runs are recorded and committed as bundles that replay offline, bit-for-bit in CI: hosted Anthropic and Gemini calls, plus a local Ollama model (no key, no network). See examples/fixtures/real_*_run.zip; regenerate with python examples/live_record.py / live_gemini_record.py / live_ollama_record.py.
  • Interoperable. Event metadata follows the OpenTelemetry GenAI conventions, so any recorded run exports as gen_ai.* spans (kinescope export-otel) into existing observability backends (Phoenix, Langfuse, …).

Status: feature-complete (see ROADMAP.md). What's in:

  • deterministic record and replay across everything unpredictable: LLM calls (sync, async, SSE streaming), @kinescope.tool calls, and opt-in clock/RNG/UUID
  • a divergence detector that tells you when a replay drifts from the recording
  • state snapshots with per-step diffs
  • counterfactual branching: fork at any step, override one event, run the tail live
  • a timeline TUI and a full CLI runner (record/replay/fork your agent script)
  • Anthropic, OpenAI and Gemini, plus local models through Ollama
  • OpenTelemetry export, a MongoDB backend, shareable trace bundles, and kinescope.patch() for recording clients that a library built

Run it

Prerequisites: Python ≥ 3.11 (check: python --version).

py -m venv .venv
source .venv/Scripts/activate      # Windows Git Bash; use `.venv/bin/activate` on macOS/Linux
pip install -e ".[dev]"            # core + anthropic + openai + cli + tui + otel + test tooling
python examples/fork_demo.py       # the flagship fork-and-fix loop (cold -> warm)

(A Makefile offers make demo / make test / make lint shortcuts if you have make.)

Run the examples end-to-end (offline, no API key, no network):

python examples/record_demo.py     # records one Anthropic call, then replays it deterministically
python examples/tool_agent.py      # a tool + clock + RNG + LLM agent, recorded and replayed
python examples/stateful_agent.py  # snapshots state across steps, then diffs it
python examples/fork_demo.py       # fork-and-fix: override one step, watch the outcome change
python examples/fork_demo_tui.py   # the same, in the timeline TUI: scrub, then press 'f'
python examples/openai_demo.py     # the same engine recording a second provider (OpenAI)
python examples/otel_export.py     # export a recorded run as OpenTelemetry gen_ai spans
python examples/share_bundle.py    # export a run to a zip, import it elsewhere, replay it

Inspect and drive recorded runs from the CLI:

kinescope record -- python your_agent.py            # record an agent script (uses kinescope.http_client())
kinescope replay <run-id> -- python your_agent.py   # replay it deterministically
kinescope fork <run-id> --at 3 --override '{"output": 72}' -- python your_agent.py  # counterfactual
kinescope ls                         # list recorded runs (with fork lineage)
kinescope show <run-id> [--step k]   # inspect a run's events and I/O
kinescope diff <run-id> <a> <b>      # state diff between two steps
kinescope ui <run-id>                # scrub the timeline TUI (view-only)
kinescope export-otel <run-id>       # emit OpenTelemetry gen_ai.* spans to the console
kinescope export <run-id> run.zip    # package a run into a shareable bundle; `kinescope import run.zip`

record/replay/fork run your agent script (which builds its client with kinescope.http_client()) in-process under a session. Try it offline with examples/agent_script.py.

The timeline (TUI)

kinescope ui <run-id> opens a three-pane timeline (steps · detail · state diff) that you scrub with ↑/↓. Launched with an agent (kinescope.ui(run_id, agent=run_agent)), f forks the highlighted step, overrides its output, and runs the tail live. That's the fork-and-fix loop shown in the gif above (static frame):

┌ Kinescope ── weather#fork@0  …  ⑂ from <parent>@0 ───────────────────────────────────┐
│ seq kind  name        │ #1 tool classify              │ state diff (sensed → …)     │
│  0  tool  sensor  fork│ ok · 0ms                      │ ~ /verdict   "warm"         │
│ ▸1  tool  classify    │ input  [72]                   │                             │
│                       │ output "warm"                 │                             │
└ ↑/↓ scrub · f fork · q quit ───────────────────────────────────────────────────────┘

Both examples use the real Anthropic SDK wired through a Kinescope transport with a stub inner transport, so they record and replay with no network and no key, and replay provably never touches the network.

Use it in your own agent

import anthropic, kinescope

@kinescope.tool                              # tool calls are recorded boundaries
def get_weather(city: str) -> dict:
    ...

def run_agent():
    client = anthropic.Anthropic(http_client=kinescope.http_client())
    msg = client.messages.create(
        model="claude-opus-4-8", max_tokens=256,
        messages=[{"role": "user", "content": "What's the weather in Paris?"}],
    )
    return msg

# capture=[...] also records direct clock/RNG/UUID use (opt-in; off by default)
with kinescope.record("paris", capture=["clock", "rng"]) as rec:
    run_agent()

with kinescope.replay(rec.run_id) as rep:    # reproduce, offline & deterministic
    run_agent()
assert not rep.divergences

# counterfactual: override step k's output, then run the tail LIVE
with kinescope.fork(rec.run_id, at=3, override={"output": {"temp_f": 71}}) as branch:
    run_agent()                            # steps 0-2 replay; step 3 is overridden; 4+ go live
print(branch.run_id)                       # a new child run, linked to its parent

For async agents use kinescope.async_http_client() with anthropic.AsyncAnthropic. Streaming (messages.stream(...)) is captured and replayed automatically.

Record code you didn't write

http_client() needs you to build the client. Libraries such as litellm build their own and cache them, so there's nowhere to pass one. kinescope.patch() records every httpx client in the process while the session is open, whoever built it and whenever:

import asyncio

import kinescope, litellm

async def ask():
    reply = await litellm.acompletion(model="openrouter/...", messages=[...])
    return reply.choices[0].message.content

async def record_it():
    with kinescope.record("forecast") as rec:
        kinescope.patch()                  # every httpx client in the process
        await ask()
    return rec.run_id

async def replay_it(run_id):
    with kinescope.replay(run_id) as rep:  # the run remembers patch(): nothing to add
        await ask()                        # answered from the recording, offline
    assert not rep.divergences

run_id = asyncio.run(record_it())
asyncio.run(replay_it(run_id))

A script that has never heard of Kinescope records from the command line:

kinescope record --capture httpx -- python your_agent.py
kinescope replay <run-id> -- python your_agent.py

This is tested against the OpenAI SDK and against litellm's own aiohttp-backed client, and it records my forecasting bot's model rotation. A request is one event however the transports are stacked. What it can't see: anything that doesn't go through httpx (requests, raw aiohttp, a subprocess).

What is kept out of recordings, and what isn't.

  • Request headers that look like credentials are stripped by name, including ones nobody listed in advance (proxy-authorization, x-openrouter-token, ocp-apim-subscription-key).
  • Credentials in the URL are stripped, and they aren't part of a call's identity, so a recording replays for someone holding a different key. That covers a user:password@ in front of the host and the query parameters key, api_key, access_token, token, client_secret, refresh_token, password, sig, signature and the AWS and Google presigned-URL parameters. The full list is REDACT_QUERY_PARAMS in model.py.
  • Set-Cookie is not stored. Your program still receives it while recording. A replay sets no cookies.
  • Request and response bodies and URL paths are not redacted. A key sent in a JSON body, a token in a path, or a secret a server echoes back is stored as it is. Recordings stay on your machine by default, and the check comes at the point of sharing: kinescope export refuses to write a bundle that contains the value of any credential-looking environment variable (as it is, JSON-escaped or URL-encoded), and names the variable and the event. It can only find values that are in the environment it runs in, or that you pass with secrets=.

Commands

Command What it does
python examples\record_demo.py Run the offline record-and-replay demo
kinescope ls List recorded runs
kinescope show <id> [--step k] Inspect a run's events / per-step I/O
kinescope record --capture httpx -- python agent.py Record a script as it is, with no Kinescope code in it
pytest Run the tests
ruff check . && mypy src Lint + typecheck

Project docs

Doc What's in it
DESIGN.md The full design and the reasons behind it.
ROADMAP.md The milestone checklist (the plan + what's done).
docs/ Deeper docs and architecture decisions (ADRs).

Determinism, honestly (limitations)

Determinism is guaranteed at recorded boundaries, and leaks are surfaced, not hidden. The divergence detector flags input/order/count mismatches (strict raises, warn continues). Known limits:

  • One recording context per run. The active session is a contextvar, so tool and clock/RNG boundaries on worker threads that don't inherit it are not captured, and since they never enter the sequence, the detector can't flag them. HTTP is the exception: a client from http_client(), or any client under patch(), is bound to the session and records on every thread. One gap remains: while a recorded tool body is running, nested boundaries are suppressed for the whole session, so an HTTP call made on another thread during that time isn't recorded. Single-thread or asyncio (tasks inherit the context) is the supported model for the rest.
  • patch() sees httpx only. Calls made with requests, raw aiohttp, or from a subprocess never reach the session. If one of them feeds a prompt, replay diverges there and says so. It hooks a private httpx method (_transport_for_url, present in httpx 0.27 to 0.29) and fails loudly if a future httpx removes it.
  • Concurrent boundary ordering (asyncio.gather) may differ between record and replay; when it does, replay is flagged, never silently wrong.
  • Streaming replays batched. SSE is reproduced by content, not re-timed.
  • Responses are buffered whole. A response is read to the end before it is handed back, so a stream that never ends (a long-lived event subscription) blocks under recording.
  • Multipart uploads flag on replay. httpx picks a random multipart boundary for each request, so the body differs between record and replay. The recorded response is still served by position, with an input mismatch reported.
  • Clock/RNG capture is opt-in (record(capture=[...])); it monkeypatches time/random/uuid, so library calls to those are captured too (and replay deterministically as long as the library's call pattern is stable).
  • Throughput: inline (clock/RNG) events record at ~20k to 190k/s (cache-warmth dependent) and replay faster. 10k events record+replay in well under a second; tool/LLM events are bound by per-payload blob writes (~1k/s for distinct payloads; identical payloads dedup for free).

Tech stack

Python 3.11+ · httpx transport interception · Anthropic / OpenAI / Gemini adapters · SQLite + content-addressed blobs (or MongoDB via the same port) · Typer (CLI) · Textual (TUI) · OpenTelemetry export. Hexagonal/ports-and-adapters around a deterministic core.

License

MIT, see LICENSE.

Metadata

Release files for kinescope 0.0.4

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

Source distribution (sdist)

Source distribution for kinescope 0.0.4
File Size Uploaded Provenance Actions
kinescope-0.0.4.tar.gz 205.1 kB With provenance Details for kinescope-0.0.4.tar.gz

Built distribution (wheel)

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

Total release size: 255.5 kB

Release files / kinescope-0.0.4.tar.gz

Download URL kinescope-0.0.4.tar.gz
Size 205.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1f5a8433bbea88acf5d3b43b763a673166def39ffeca29f976260e2e3b14a202
BLAKE2b-256 checksum
How to use checksums
509bb1bb6f3f09b5dfb155566ce05e37ad90d3dce3ff6156c8a9d001424f4c01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / kinescope-0.0.4-py3-none-any.whl

Download URL kinescope-0.0.4-py3-none-any.whl
Size 50.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
03fa6359f31071cc108d1eb3c8d68c23f71ad97576c10b828a027b58de3300d6
BLAKE2b-256 checksum
How to use checksums
3d6822799d607dfad48f3cf67860981f728d4aa2e6cbdb0dec7fb20606bb7d0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Security for kinescope 0.0.4

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for kinescope-0.0.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

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