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"
pytestreplays 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
khonsubinary is found onPATH, 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.
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)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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