Skip to main content

khonsu-sdk (Python)

The companion to the khonsu CLI, a time-travel debugger for AI agents.

pip install khonsu-sdk      # then: import khonsu
curl -fsSL https://lazeeez.github.io/Khonsu/downloads/install.sh | sh    # the khonsu CLI (Linux, or Windows via WSL)

Guide, examples and downloads: https://lazeeez.github.io/Khonsu/

Model calls are recorded by the CLI's proxy with no code changes. This package adds one decorator for tool side effects:

import khonsu

@khonsu.tool
def run_tests(path: str) -> dict:
    ...   # touches the filesystem, the network, a database, the clock...
Under Behaviour
khonsu record -- python agent.py The tool runs; its arguments and result (or exception) are recorded durably.
khonsu replay run.khn -- python agent.py The recorded result is returned without running the tool: no repeated side effects, reproducible output.
khonsu replay … --on-miss live / khonsu fork Calls whose arguments differ from the recording run for real and are recorded.
Plain python agent.py The decorator does nothing.

Arguments and return values must be JSON-compatible. Exceptions are replayed as the same builtin type (for example ValueError), or as khonsu.ToolError for other types. If replay meets a call whose arguments are not in the recording, it raises khonsu.KhonsuDivergence, with the differing field, unless live fallback is enabled.

pytest plugin

Installed automatically (entry point pytest11). Mark a test with a recording:

@pytest.mark.khonsu("recordings/refund_flow.khn")
def test_refund_flow():
    assert run_my_agent("I want a refund").action == "refund"
  • pytest replays the recording: offline, free, same answer every time. If the agent's requests changed, the test fails with the call, the JSON field, and the old and new values.
  • pytest --khonsu-record [--khonsu-upstream URL] (re-)records against a live model.
  • The khonsu binary is found on PATH, in $KHONSU_BIN, or via --khonsu-bin. Create model clients inside the test so they pick up the replay server's base URL.

The SDK itself has no dependencies (standard library only); the plugin needs pytest.

Metadata

Release files for khonsu-sdk 0.3.0

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

Built distribution (wheel)

Table of built distributions (wheels) for khonsu-sdk 0.3.0
File Interpreter ABI Platform
khonsu_sdk-0.3.0-py3-none-any.whl Python 3 none any Details

Release files / khonsu_sdk-0.3.0-py3-none-any.whl

Download URL khonsu_sdk-0.3.0-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c01d06142068a5d015a748bd6f31ec9ec313299a818a4f8c5b361ec5ddba22a
BLAKE2b-256 checksum
How to use checksums
7c932c3592d0ad4e10d8fcefe6204c1468307541feddcb631e210bbe633902c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 30, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

1 release file

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