Skip to main content
Version: v0 (preview)

Observe & Enforce

Kelhe has two modes, set on the client.

from kelhe import Kelhe, Mode

Kelhe() # Mode.OBSERVE (default)
Kelhe(mode=Mode.ENFORCE, risk_threshold=7.0) # block at score >= 7

Observe (default)

Every action is scored and logged, but nothing is ever blocked. Dropping Kelhe into a running system changes its behavior in no way — this is how a safety layer earns trust before it can cause a surprise. Use it to watch real traffic and calibrate your threshold.

Enforce

An action whose score is risk_threshold is treated as risky and blocked before the tool runs. Everything below the threshold executes normally.

Human in the loop

In Enforce mode you can route a risky action to a person instead of a hard block. Pass an escalation_handler — return True to allow the action anyway, False to block it.

def ask_human(outcome) -> bool:
print(f"AI wants to call {outcome.action.tool_name} — score {outcome.result.score}/10")
return input("Approve? (y/n): ").strip().lower() == "y"

kelhe = Kelhe(mode=Mode.ENFORCE, escalation_handler=ask_human)

Audit every action

An audit_handler fires for every action, in both modes — the hook for logging, metrics, or your SIEM. A broken audit hook never breaks scoring.

kelhe = Kelhe(audit_handler=lambda o: log.info(
"kelhe", tool=o.action.tool_name, score=o.result.score,
risky=o.risky, enforced=o.enforced))

If the engine is unreachable

Scoring can fail — network outage, rejected key, exhausted quota. The on_api_error setting decides what happens to the tool call, and it defaults to fail-closed (a risk layer should never silently allow an action it couldn't score). See Errors & fail behavior.