LOKAHI
Rules a community writes for its AI agents, checked before every tool call.
LOKAHI is a small gate that sits between an AI agent and the tools it uses. A community writes down what the agent may read, where data may go, and which actions need people to say yes. LOKAHI checks each tool call against those rules before it runs. If no one approves in time, the answer is no. Every decision goes into a tamper-evident local record.
The name comes from the Hawaiian word lōkahi, meaning unity, agreement or harmony. LOKAHI lets the actions that matter go ahead only when separate people agree. No single party decides alone, and neither does the agent.
Status: v1.1.0 is a reference implementation for review and pilots. It has not been independently security-reviewed, so do not rely on it to protect real systems yet. A pre-release audit found four critical defects; all are fixed and covered by tests/test_audit_regressions.py — see AUDIT_REPORT.md for the findings of record and ROADMAP.md for what remains before production.
The runtime is a four-layer cascade: a WASM deterministic pre-flight, the 15-rule engine, m-of-n Ed25519 consent, then a fail-secure state with human WebXR handoff. The learned decisions tier is experimental and is not part of the safety claim; the guarantee comes from the deterministic rules and the consent framework.
How it works
Every check starts from a signed boundary manifest, a JSON file the community writes. It lists:
- the data fields an agent may read, and the ones it must never use
- where data may be stored, and which legal jurisdiction applies
- each tool the agent may call, the arguments that tool accepts, and whether the tool is irreversible
- how long people have to approve an irreversible action
When the agent calls a tool over the Model Context Protocol (MCP), LOKAHI checks the call against the manifest, then allows it, refuses it, or holds it for people to decide:
AI agent ── tool call ──▶ LOKAHI ── allowed ──▶ your MCP client sends it to the tool
│ ▲
local record ◀─┘ └── signed approvals from people
Three rules matter most:
- Fail closed. LOKAHI allows nothing if the manifest is unsigned, can't be verified or has expired, or if no key is configured to check it.
- Silence means no. If an approval window closes without enough separate people saying yes, the call is refused.
- Two people can stop an action. Two separate people saying no freeze it, whatever anyone else says.
People count once each, however many agents they run. And the agent can't approve itself: a call that carries its own approval data is refused.
The design draws on Andrew Critch's Boundaries sequence and on ahimsa (non-harm) as a default of not acting. It also responds to ASTRA, which shows how global AI safety frameworks miss local context in India.
What runs today
Everything is Python 3.10 or later, with no dependencies:
- Decision engine (
tools/lokahi.py): signed manifests, 15 ordered rules, vote counting by person, conflict-of-interest checks, emergency rate caps, and a hash-chained ledger. Votes count only for the exact action they approve. - MCP gate (
tools/mcp_stdio_proxy.py): reads MCP JSON-RPCtools/callrequests and returns a decision for each. Facts such as whether a tool is irreversible and where it stores data come from the signed manifest, never from the agent. Unknown tools and arguments are refused. - Signing tools (
tools/lokahi_sign.py,tools/lokahi_approve.py): create keys, sign manifests, and let each person sign a yes or no for one exact call. - Pilot example (
examples/editorial_desk_demo.py): a small publication's editorial desk, run end to end through the gate. - Tests (
tests/test_core.py): 70 unit tests, including attacks on the gate. The 50-scenario set and 200 benign tasks are intools/run_evals.py.
Known limits
Read these before you depend on LOKAHI:
- No independent security review. The audit at
AUDIT_REPORT.mdis internal. No external cryptographic or safety review has been completed. - Ed25519 is not threshold signing. Each validator signs independently and the gate counts distinct valid signatures. There is no key splitting and no FROST group key; a compromised gate operator can see every signature.
- It decides but does not relay. LOKAHI returns a decision; your MCP client or wrapper sends allowed calls to the tool. It does not yet inspect tool responses (indirect prompt injection arrives there), and it does not pin tool descriptions, so a server can change a tool schema after approval.
- stdio only. There is no OAuth 2.1 / Streamable HTTP resource-server support yet, so it cannot front remote MCP servers on its own.
- Approval windows reset on restart. A restart opens a new window; it never approves anything, but in-progress windows are lost.
- Distinct people are assumed, not proven. Two different approver IDs are trusted to be two different people. Disjointness attestation is roadmap item R3.
- The ledger is a local JSONL file written by one process. It is hash-chained but not Merkle-proved, not witness-cosigned, and not remotely immutable.
- The learned decisions tier is experimental. It was trained on synthetic data, its labels have not been human-reviewed, and it has never seen real agent traffic. It is excluded from the safety claim.
- Performance. The WASM checks run in microseconds inside the module; the Python bridge adds roughly 9 ms per call. A Rust host is roadmap item R1-12.
- No SOC 2, no pen test, no support SLA. Enterprise operational controls are roadmap items R2.
Try it
git clone https://github.com/Dirgha-AI/lokahi.git
cd lokahi
python tests/test_core.py # 70 unit tests
python tests/test_decisions.py # 32 tests for the experimental decisions tier
python examples/editorial_desk_demo.py # pilot example, end to end
python tools/mcp_stdio_proxy.py --self-test # gate scenarios, including attacks
python demo.py # engine walkthrough, 11 scenarios
python tools/run_evals.py # 50 scenarios and 200 benign tasks
The core needs nothing installed: each command runs from a fresh clone. Ed25519 keys, the newer test suites and the conformance suite need pip install "cryptography>=42.0".
Or install it from PyPI:
pip install "lokahi[signatures]" # or plain `pip install lokahi` for the dependency-free core
lokahi-gate --self-test # the same gate scenarios
lokahi-conformance # the published conformance checks
lokahi-sign --help # make keys and sign a rules file
lokahi-approve --help # sign one person's yes for one exact call
In Python: from lokahi import Manifest, Signer, evaluate.
Gate MCP tool calls
Five steps:
-
Create a key for the manifest and one for each approver:
python tools/lokahi_sign.py keygen --out manifest.key python tools/lokahi_sign.py keygen --out editor-fiction.key
-
Write your manifest.
examples/editorial-desk.manifest.jsonis a complete one. Each tool lists its class (read,writeorirreversible) and maps each argument to the data field it reveals, or tonullif it reveals none:"email_author": { "class": "irreversible", "args": {"submission_id": "submission_id", "body": null} }
-
Sign it. Signing checks the tools policy and refuses a malformed one:
python tools/lokahi_sign.py manifest --key-file manifest.key \ --in examples/editorial-desk.manifest.json --out manifest.json
-
Run the gate. It reads one JSON-RPC request per line on standard input and writes one decision per line. Approvers are listed in a file like
examples/approvers.example.json. Keep the approvals file somewhere the agent can't write:python tools/mcp_stdio_proxy.py --manifest manifest.json \ --key-file manifest.key --approvers approvers.json \ --approvals approvals.jsonl --ledger lokahi-ledger.jsonl \ --requester agent:my-agent --operator ops:agent-runner
The
--operatoris whoever runs the agent. If that person also tries to approve one of its calls, LOKAHI refuses the call. -
Approve when asked. When a call needs people, the decision includes an
action_digest. Each approver signs it from their own device:python tools/lokahi_approve.py --key-file editor-fiction.key \ --operator editor:fiction --node laptop-1 \ --digest the_action_digest --decision yes --approvals approvals.jsonl
An approval covers that exact call, with the same tool and the same argument values, and expires after an hour by default.
Example: an editorial desk
examples/editorial_desk_demo.py shows the gate protecting unpublished manuscripts:
summarize a submission -> ALLOWED within_manifest
ask for the author's home address -> FORBIDDEN forbidden_target:author_home_address
ask for a field nobody listed -> FORBIDDEN argument_out_of_policy:author_social_handles
send the manuscript to a US cloud model -> FORBIDDEN residency_violation:US
use a tool the editors never listed -> FORBIDDEN tool_not_in_manifest:delete_submission_archive
agent sends its own 'approvals' with the email -> FORBIDDEN agent_supplied_control_metadata
email a rejection: waits for people -> ESCALATE insufficient_disjoint_consent
email a rejection: nobody answered in an hour -> FORBIDDEN non_response
publish: waits for people -> ESCALATE insufficient_disjoint_consent
publish: two editors and the author sign yes -> ALLOWED quorum_met
their approvals reused for a different story -> ESCALATE insufficient_disjoint_consent
local record: 11 decisions, tamper check passed = True
someone edits decision 4 to hide the cloud upload: tamper check passed = False (record breaks at decision 4)
Experimental: learned decisions tier
v0.1.4 adds an optional second check after LOKAHI's own decision. It is off by default. With it off, LOKAHI behaves exactly as before.
What it does. A small classifier reads each call that LOKAHI has already allowed: the tool name, the tool class from the signed manifest, and the argument values. It answers ALLOW, ESCALATE (a person decides) or REFUSE, with a reason code from a published charter (docs/decisions/CHARTER.md) and a one-line rationale. The order is fixed:
- LOKAHI decides first. If it refuses or escalates, that stands and the model isn't asked.
- Charter rules in plain code come next: a timed-out approval is refused, data leaving the allowed places is refused, and an irreversible call needs people.
- The model runs last. Its answer and LOKAHI's are combined by taking the stricter one, so it can turn an allowed call into ESCALATE or REFUSE, never the other way round.
The tool class always comes from the signed manifest, never from the agent. If the model fails or returns something unknown, the call is escalated.
Turn it on.
python tools/mcp_stdio_proxy.py --manifest manifest.json --key-file manifest.key --decisions experimental
LokahiMCPGateway(manifest, signer, experimental_decisions=True)
When the tier makes a call stricter, the reason is decisions_tier:<code> (for example decisions_tier:DDM-08 for a hidden instruction) and the ledger records the stricter verdict. The response also carries a decisions object with the model's decision, reason code, rationale and model version.
Results. These numbers are for the bundled model ddm-0.1.1, re-measured for this release. They come from docs/decisions/metrics.json.
| Holdout (198 synthetic rows) | Hard set (50 hand-written rows) | |
|---|---|---|
| Accuracy, final pipeline | 0.86 | 0.74 |
| Should-refuse or irreversible calls let through (false ALLOW) | 2 of 102 | 0 of 24 |
| Any non-ALLOW call let through | 5 of 132 | 0 of 33 |
| Benign calls refused | 1 of 66 | 0 of 17 |
| Benign calls allowed | 91% | 16 of 17 |
| REFUSE recall | 0.83 | 0.47 |
- The two holdout misses are deception written through reversible "draft" tools: a made-up quote and made-up trial scores. Word and character counts can't tell an invented number from a real one.
- On the hard set the model is cautious but not strict enough. Nine of the 17 should-refuse cases came out ESCALATE, so a person would still see them.
- The runtime model is a plain JSON file (
tools/decisions/model.json, 8 MB) read by standard-library Python. Its decisions and reason codes match scikit-learn's on all 198 holdout rows and all 50 hard rows. The largest probability difference is below 1e-7. - Each decision takes 5 to 9 ms (median) and 9 to 17 ms (p95) in pure Python on a 2013 laptop CPU (Intel Core i5-4200U), on Python 3.10 to 3.12. Loading the model takes about one second.
Limits. Read these before turning it on:
- Synthetic data. The model learned from 995 examples written by one open model (DeepSeek V4.1 Flash). The holdout shares that model's style, so holdout scores are optimistic. The 50 hand-written cases are the more honest test, and 50 is small.
- Labels pending human review. No person has reviewed the training labels yet. A second model and an AI agent proposed 5 corrections (
data/decisions/review/corrections.jsonl), and this model was trained with them applied. The charter (DDM-13) says only labels reviewed by named people should retrain the model, and that hasn't happened yet. - Not a safety guarantee. It still lets through some calls that should be refused. The safety comes from LOKAHI's rules and the checks in plain code. The model is an extra layer.
- Different input shape. The model was trained on short summaries of calls. Through the gate it reads the raw argument values as JSON, and the stated purpose is LOKAHI's own
mcp:<tool>record. The published numbers don't cover that shift. - Its escalations can't be approved through the gate. A tier ESCALATE doesn't open an approval window, so a person has to act outside LOKAHI.
- Not tested on real agent traffic or on a public benchmark such as AgentDojo.
Retrain it. Training is optional and is the only step that needs third-party packages:
python -m pip install "scikit-learn>=1.5" numpy
python tools/decisions/train.py --corrections data/decisions/review/corrections.jsonl
python tests/test_decisions.py
train.py uses the same 80/20 split and settings each time, writes a new model.json and its metrics, and checks that the JSON model matches scikit-learn. Use --version to give a retrained model a new number. Leave out --corrections to train on the original labels; that reproduces ddm-0.1.0 (docs/decisions/metrics_before_corrections.json). Pickle and joblib files are never used.
About the test scenarios and baselines
The 50 scenarios in data/LOKAHI_RedTeam_Corpus_v1.0.csv are adapted from scenes in a speculative-fiction duology about AI in public services. Each one is written as a test with an expected decision and reason. Passing all 50 shows the engine behaves as specified on those cases. It doesn't show how LOKAHI performs in the field.
run_evals.py also scores two simplified stand-ins on the same scenarios:
- a content filter that auto-approves on timeout
- a stateless check in the style of role-based access control (RBAC) or Open Policy Agent (OPA)
They show which kinds of rule those approaches don't express. They aren't a head-to-head comparison with real OPA policies or classifiers.
Research extensions
These run in CI but are research prototypes, separate from the gate:
| Path | What it explores |
|---|---|
tools/ghostproof.py, tools/run_ghostproof_evals.py |
Surfacing a model's hesitation from its token probabilities, so reviewers don't rubber-stamp close calls |
tools/run_kinetic_evals.py |
Physical limits for robots: force, torque, speed, workspace and stopping distance |
tools/run_wargame_workshop.py |
A five-round red team/blue team workshop built on the duology's scenes |
Repository layout
| Path | What it contains |
|---|---|
tools/lokahi.py |
Decision engine: manifests, tool policies, the 15 rules, vote binding, approvals, ledger |
tools/mcp_stdio_proxy.py |
MCP gate, approvals store, command line and self-test |
tools/lokahi_sign.py |
Create keys and sign manifests |
tools/lokahi_approve.py |
Sign a yes or no for one action |
examples/ |
Editorial desk example, a complete manifest and an approvers file |
tests/test_core.py |
70 unit tests |
tools/decisions/ |
Experimental decisions tier: charter rules, pure-Python model, model.json, optional train.py |
tests/test_decisions.py |
32 tests for the decisions tier |
demo.py |
Engine walkthrough on a municipal water board |
data/ |
50-scenario set (CC BY 4.0) and the Ghostproof scenario set |
data/decisions/ |
Decisions tier training and test data, schema and data card (CC BY 4.0) |
docs/decisions/ |
Decisions charter, research notes and metrics |
docs/SPEC.md |
Specification: manifest fields, rule order, vote binding, MCP gate |
docs/ARCHITECTURE.md |
Notes on taking the reference to production |
CHANGELOG.md |
What changed in each release |
Related projects
LOKAHI is the runtime half of a two-stage check. The two companion repositories are:
- Ahimsa AI: a design-time impact assessment (AIA v1.1). It scores a project before deployment and compiles approved projects into the signed manifests that LOKAHI enforces.
- Synthetic Humanism: the manifesto and essays behind both tools, plus a benchmark that runs both stages against 20 documented AI failures.
Background reading
- Boundaries: Andrew Critch, Boundaries: an open sequence on multi-agent alignment and cooperative AI (2022–2023).
- Local context in AI risk: Aggarwal et al., ASTRA: AI Safety, Trust, & Risk Assessment, arXiv:2602.17357 (2026). An India-focused AI safety risk database with 37 risk classes.
- Guaranteed safe AI: Dalrymple, Skalse, Bengio, Russell, Tegmark et al., Towards Guaranteed Safe AI, arXiv:2405.06624 (2024).
- Object capabilities: Mark S. Miller, Robust Composition, PhD dissertation, Johns Hopkins University (2006).
- Threshold signatures: Connolly, Komlo, Goldberg and Wood, Two-Round Threshold Schnorr Signatures with FROST, IETF RFC 9591 (2024). A planned back end, not yet built.
Authors
- Salik Shah: protocol design, reference implementation, scenario set (salikshah.com, x.com/salik, GitHub)
- Sabin Ranjit: security architecture (GitHub)
License
The software is licensed under Apache-2.0. The scenario set in data/ and the decisions data in data/decisions/ are licensed under CC BY 4.0.
Metadata
Release files for lokahi 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lokahi-1.1.0.tar.gz | 2.3 MB | With provenance | Details for lokahi-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lokahi-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for lokahi-1.1.0-py3-none-any.whl |
Total release size: 4.6 MB
Release files / lokahi-1.1.0.tar.gz
| Download URL | lokahi-1.1.0.tar.gz |
|---|---|
| Size | 2.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d65a90d80a4f5ff7cdb30856c1943609f119505039ba4c371a18b4c001b7edcc
|
|
BLAKE2b-256 checksum How to use checksums |
101510a5dd0f7040bc45bdbc0c1a7d82ecd3de6766a3f96a474407950054e698
|
| 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 20, 2026.
Transparency logRelease files / lokahi-1.1.0-py3-none-any.whl
| Download URL | lokahi-1.1.0-py3-none-any.whl |
|---|---|
| Size | 2.3 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3a7a71b5977cc94fa0287bf0b1c3144d54cc324088dcdcb9a6b941f1055cb967
|
|
BLAKE2b-256 checksum How to use checksums |
87cd24bdf827e2d62d02f5cb3983b09456e39891054880d59fa5c614838dce5b
|
| 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 20, 2026.
Transparency logSecurity for lokahi 1.1.0
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.
Attestation for lokahi-1.1.0.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 20, 2026.
Transparency logA 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.