Thin Python client for the RiskKernel reliability runtime (Surface 2).
Project description
riskkernel (Python SDK)
The Python SDK for RiskKernel — Surface 2, deep control over a governed agent run.
It is a thin client over the self-hosted RiskKernel daemon. Every deterministic decision — budgets, loop/time halts, approval policy — happens in the Go core. The SDK just makes governed runs ergonomic from Python. Core install is stdlib-only (no third-party dependencies).
pip install riskkernel
Quickstart
import riskkernel as rk
rt = rk.Runtime(base_url="http://localhost:7070") # your daemon
with rt.governed_run(name="research",
budget=rt.budget(dollars=1.00, loops=20, seconds=300)) as run:
# Route your LLM client through the governing proxy so every model call is
# metered, priced, and budget-enforced under this run:
cfg = run.proxy_config()
# cfg["base_url"] -> http://localhost:7070/v1
# cfg["headers"] -> {"X-RiskKernel-Run-Id": "<run id>"}
for _ in range(100):
run.step() # raises rk.BudgetExceeded when loops/time run out
# ... your agent reasoning + tool calls ...
run.checkpoint("after-step", {"messages": messages})
When the governor halts the run (token / dollar / loop / time budget), the next
run.step() — or a proxied model call — raises rk.BudgetExceeded.
Resume after a crash
The daemon reloads non-terminal runs on restart with the budget and usage they had
already spent, so a SIGKILL'd run keeps enforcing without re-spending. Reattach to
it by id with resume_run and pick your work back up from the last checkpoint:
with rt.resume_run(run_id) as run: # attaches; never creates or cancels
cp = run.latest_checkpoint() # the state you saved before the crash
start = cp["payload"]["cursor"] if cp else 0
for i in range(start, total): # skip the steps you already paid for
run.step() # counts against the SAME budget
# ... your work ...
run.checkpoint("step", {"cursor": i + 1})
The run resumes against whatever budget it had left, so it can't overspend by
restarting — run.step() still raises rk.BudgetExceeded at the original ceiling.
Human-in-the-loop tools
Gate side-effecting tools on human approval (the daemon's policy decides what needs it; the call blocks until a human resolves it via CLI / web / webhook):
from riskkernel import governed_tool, ApprovalGate
@governed_tool(side_effect="write")
def write_file(path, content):
... # only runs if approved; else rk.ApprovalDenied
# or explicitly:
gate = ApprovalGate(run)
if gate.allow("mcp://shell", side_effect="exec", arguments={"cmd": cmd}):
run_shell(cmd)
Framework adapters
Lazy-imported, so you only pay for what you use:
# LangChain / LangGraph — enforces loop/time budgets per LLM call
from riskkernel.adapters.langchain import RiskKernelCallbackHandler
llm.invoke(prompt, config={"callbacks": [RiskKernelCallbackHandler(run)]})
# Claude Agent SDK — PreToolUse approval hook
from riskkernel.adapters.claude_agent import make_pre_tool_use_hook
hook = make_pre_tool_use_hook(run, side_effect_for={"Bash": "exec", "Write": "write"})
# OpenAI Agents SDK — RunHooks (steps + tool approval)
from riskkernel.adapters.openai_agents import RiskKernelRunHooks
hooks = RiskKernelRunHooks(run, gate_tools=True)
Configuration
Runtime(base_url=..., token=...), or the env vars RISKKERNEL_BASE_URL and
RISKKERNEL_API_TOKEN (used by the decorator/convenience API and default_runtime()).
License
Apache-2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file riskkernel-0.4.0.tar.gz.
File metadata
- Download URL: riskkernel-0.4.0.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5246fe9832557354e140765a7729cb7f2d6a7cc82bd8471223b0344b11d5f79
|
|
| MD5 |
a880560011e23d53e04038b8bfff585c
|
|
| BLAKE2b-256 |
11ef5f1e724fa58b0d2f411e69897763f226f32b219c1ad493eff0ba52803ba8
|
Provenance
The following attestation bundles were made for riskkernel-0.4.0.tar.gz:
Publisher:
python-publish.yml on prashar32/riskkernel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
riskkernel-0.4.0.tar.gz -
Subject digest:
c5246fe9832557354e140765a7729cb7f2d6a7cc82bd8471223b0344b11d5f79 - Sigstore transparency entry: 1740882308
- Sigstore integration time:
-
Permalink:
prashar32/riskkernel@5e4bf3f0f0217d8a2a303c327de320b313222b68 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/prashar32
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@5e4bf3f0f0217d8a2a303c327de320b313222b68 -
Trigger Event:
push
-
Statement type:
File details
Details for the file riskkernel-0.4.0-py3-none-any.whl.
File metadata
- Download URL: riskkernel-0.4.0-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90e44131a6028d49313df75abc4e552239ea43a227cfcfa3fe1a7cf7cab913c4
|
|
| MD5 |
1b6990c53bdba77995c4dc4f624eec8d
|
|
| BLAKE2b-256 |
a33f72ec69377b7165868c011479c48e7b82594a7dbf1ad094dd2b4200b8ad4c
|
Provenance
The following attestation bundles were made for riskkernel-0.4.0-py3-none-any.whl:
Publisher:
python-publish.yml on prashar32/riskkernel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
riskkernel-0.4.0-py3-none-any.whl -
Subject digest:
90e44131a6028d49313df75abc4e552239ea43a227cfcfa3fe1a7cf7cab913c4 - Sigstore transparency entry: 1740882444
- Sigstore integration time:
-
Permalink:
prashar32/riskkernel@5e4bf3f0f0217d8a2a303c327de320b313222b68 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/prashar32
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@5e4bf3f0f0217d8a2a303c327de320b313222b68 -
Trigger Event:
push
-
Statement type: