Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 1.2.0 instead.

LOKAHI

License: Apache-2.0 CI Unit tests: 70 passed Protocol: MCP

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: v0.1.4 is a reference implementation for review and pilots. It hasn't been independently reviewed, so don't rely on it to protect real systems yet. The known limits say exactly what's missing. v0.1.4 adds an experimental learned decisions tier, off by default.

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:

  1. 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.
  2. Silence means no. If an approval window closes without enough separate people saying yes, the call is refused.
  3. 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-RPC tools/call requests 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 in tools/run_evals.py.

Known limits

Read these before you depend on LOKAHI:

  1. Shared-secret signatures. v0.1.4 signs with HMAC-SHA256, a shared-secret scheme. Whoever checks a signature also holds the key, so the gate could forge approvals. Public-key signatures (Ed25519) come next.
  2. It decides but doesn't relay. LOKAHI returns a decision; your MCP client or wrapper sends allowed calls to the tool. It doesn't yet inspect what tools send back, which is where hidden instructions (indirect prompt injections) usually arrive.
  3. Approval count is fixed at three people. That suits a public utility but is heavy for a small team. Per-tool counts are planned.
  4. Approval windows reset on restart. A restart opens a new window; it never approves anything.
  5. No emergency override through the gate. The engine supports emergency declarations; the MCP gate doesn't accept them.
  6. Distinct people are assumed, not proven. Two different approver IDs are trusted to be two different people.
  7. No outside review yet. No independent security or cryptographic review has been done.

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

Nothing to install: each command runs from a fresh clone.

Or install it from PyPI:

pip install lokahi
lokahi-gate --self-test     # the same gate scenarios
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:

  1. 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
    
  2. Write your manifest. examples/editorial-desk.manifest.json is a complete one. Each tool lists its class (read, write or irreversible) and maps each argument to the data field it reveals, or to null if it reveals none:

    "email_author": {
      "class": "irreversible",
      "args": {"submission_id": "submission_id", "body": null}
    }
    
  3. 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
    
  4. 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 --operator is whoever runs the agent. If that person also tries to approve one of its calls, LOKAHI refuses the call.

  5. 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:

  1. LOKAHI decides first. If it refuses or escalates, that stands and the model isn't asked.
  2. 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.
  3. 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

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

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 0.1.4.post1

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

Source distribution (sdist)

Source distribution for lokahi 0.1.4.post1
File Size Uploaded Provenance Actions
lokahi-0.1.4.post1.tar.gz 2.2 MB Without provenance Details for lokahi-0.1.4.post1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lokahi 0.1.4.post1
File Interpreter ABI Platform Actions
lokahi-0.1.4.post1-py3-none-any.whl Python 3 none any Details for lokahi-0.1.4.post1-py3-none-any.whl

Total release size: 4.5 MB

Release files / lokahi-0.1.4.post1.tar.gz

Download URL lokahi-0.1.4.post1.tar.gz
Size 2.2 MB
Tags Source
SHA-256 checksum
How to use checksums
c1a1cfe1d420337b598c764162808c1cfe012867a4e2b159aa95e0f2661a914e
BLAKE2b-256 checksum
How to use checksums
fdfb3247e823fef688b89bf0647c85e5a4ea4e34490da89fb4599848b24e2e4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.6

Release files / lokahi-0.1.4.post1-py3-none-any.whl

Download URL lokahi-0.1.4.post1-py3-none-any.whl
Size 2.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
0e012a3c6ee23799a3cb913fb636dcd3389b398e419988d055840f8e3793c413
BLAKE2b-256 checksum
How to use checksums
c4ca104ab0dc58c56d0af345c4bf06c8ad8e936876cdc966f499267c1faf6a01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.6

Security for lokahi 0.1.4.post1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

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