lokahi 0.1.4.post1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,202 @@
1
+ 
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Salik Shah / Dirgha-AI
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,307 @@
1
+ Metadata-Version: 2.4
2
+ Name: lokahi
3
+ Version: 0.1.4.post1
4
+ Summary: Checks what an AI agent is about to do against rules its community wrote, before it runs. Silence means no.
5
+ Author: Salik Shah, Sabin Ranjit
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/Dirgha-AI/lokahi
8
+ Project-URL: Repository, https://github.com/Dirgha-AI/lokahi
9
+ Project-URL: Changelog, https://github.com/Dirgha-AI/lokahi/blob/main/CHANGELOG.md
10
+ Project-URL: Issues, https://github.com/Dirgha-AI/lokahi/issues
11
+ Keywords: ai-safety,ai-agents,mcp,mcp-gateway,policy,guardrails,consent,ahimsa
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Security
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Dynamic: license-file
24
+
25
+ <h1 align="center">LOKAHI</h1>
26
+
27
+ <p align="center">
28
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-blue.svg" alt="License: Apache-2.0"></a>
29
+ <a href="https://github.com/Dirgha-AI/lokahi/actions/workflows/ci.yml"><img src="https://github.com/Dirgha-AI/lokahi/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
30
+ <a href="tests/test_core.py"><img src="https://img.shields.io/badge/unit%20tests-70%20passed-brightgreen.svg" alt="Unit tests: 70 passed"></a>
31
+ <a href="https://modelcontextprotocol.io"><img src="https://img.shields.io/badge/protocol-MCP-purple.svg" alt="Protocol: MCP"></a>
32
+ </p>
33
+
34
+ <p align="center"><strong>Rules a community writes for its AI agents, checked before every tool call.</strong></p>
35
+
36
+ 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.
37
+
38
+ 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.
39
+
40
+ **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](#known-limits) say exactly what's missing. v0.1.4 adds an [experimental learned decisions tier](#experimental-learned-decisions-tier), off by default.
41
+
42
+ ## How it works
43
+
44
+ Every check starts from a signed boundary manifest, a JSON file the community writes. It lists:
45
+
46
+ - the data fields an agent may read, and the ones it must never use
47
+ - where data may be stored, and which legal jurisdiction applies
48
+ - each tool the agent may call, the arguments that tool accepts, and whether the tool is irreversible
49
+ - how long people have to approve an irreversible action
50
+
51
+ When the agent calls a tool over the [Model Context Protocol (MCP)](https://modelcontextprotocol.io), LOKAHI checks the call against the manifest, then allows it, refuses it, or holds it for people to decide:
52
+
53
+ ```text
54
+ AI agent ── tool call ──▶ LOKAHI ── allowed ──▶ your MCP client sends it to the tool
55
+ │ ▲
56
+ local record ◀─┘ └── signed approvals from people
57
+ ```
58
+
59
+ Three rules matter most:
60
+
61
+ 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.
62
+ 2. **Silence means no.** If an approval window closes without enough separate people saying yes, the call is refused.
63
+ 3. **Two people can stop an action.** Two separate people saying no freeze it, whatever anyone else says.
64
+
65
+ 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.
66
+
67
+ 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](https://arxiv.org/abs/2602.17357), which shows how global AI safety frameworks miss local context in India.
68
+
69
+ ## What runs today
70
+
71
+ Everything is Python 3.10 or later, with no dependencies:
72
+
73
+ - **Decision engine** ([`tools/lokahi.py`](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.
74
+ - **MCP gate** ([`tools/mcp_stdio_proxy.py`](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.
75
+ - **Signing tools** ([`tools/lokahi_sign.py`](tools/lokahi_sign.py), [`tools/lokahi_approve.py`](tools/lokahi_approve.py)): create keys, sign manifests, and let each person sign a yes or no for one exact call.
76
+ - **Pilot example** ([`examples/editorial_desk_demo.py`](examples/editorial_desk_demo.py)): a small publication's editorial desk, run end to end through the gate.
77
+ - **Tests** ([`tests/test_core.py`](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`](tools/run_evals.py).
78
+
79
+ ## Known limits
80
+
81
+ Read these before you depend on LOKAHI:
82
+
83
+ 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.
84
+ 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.
85
+ 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.
86
+ 4. **Approval windows reset on restart.** A restart opens a new window; it never approves anything.
87
+ 5. **No emergency override through the gate.** The engine supports emergency declarations; the MCP gate doesn't accept them.
88
+ 6. **Distinct people are assumed, not proven.** Two different approver IDs are trusted to be two different people.
89
+ 7. **No outside review yet.** No independent security or cryptographic review has been done.
90
+
91
+ ## Try it
92
+
93
+ ```bash
94
+ git clone https://github.com/Dirgha-AI/lokahi.git
95
+ cd lokahi
96
+
97
+ python tests/test_core.py # 70 unit tests
98
+ python tests/test_decisions.py # 32 tests for the experimental decisions tier
99
+ python examples/editorial_desk_demo.py # pilot example, end to end
100
+ python tools/mcp_stdio_proxy.py --self-test # gate scenarios, including attacks
101
+ python demo.py # engine walkthrough, 11 scenarios
102
+ python tools/run_evals.py # 50 scenarios and 200 benign tasks
103
+ ```
104
+
105
+ Nothing to install: each command runs from a fresh clone.
106
+
107
+ Or install it from PyPI:
108
+
109
+ ```bash
110
+ pip install lokahi
111
+ lokahi-gate --self-test # the same gate scenarios
112
+ lokahi-sign --help # make keys and sign a rules file
113
+ lokahi-approve --help # sign one person's yes for one exact call
114
+ ```
115
+
116
+ In Python: `from lokahi import Manifest, Signer, evaluate`.
117
+
118
+ ## Gate MCP tool calls
119
+
120
+ Five steps:
121
+
122
+ 1. Create a key for the manifest and one for each approver:
123
+
124
+ ```bash
125
+ python tools/lokahi_sign.py keygen --out manifest.key
126
+ python tools/lokahi_sign.py keygen --out editor-fiction.key
127
+ ```
128
+
129
+ 2. Write your manifest. [`examples/editorial-desk.manifest.json`](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:
130
+
131
+ ```json
132
+ "email_author": {
133
+ "class": "irreversible",
134
+ "args": {"submission_id": "submission_id", "body": null}
135
+ }
136
+ ```
137
+
138
+ 3. Sign it. Signing checks the tools policy and refuses a malformed one:
139
+
140
+ ```bash
141
+ python tools/lokahi_sign.py manifest --key-file manifest.key \
142
+ --in examples/editorial-desk.manifest.json --out manifest.json
143
+ ```
144
+
145
+ 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`](examples/approvers.example.json). Keep the approvals file somewhere the agent can't write:
146
+
147
+ ```bash
148
+ python tools/mcp_stdio_proxy.py --manifest manifest.json \
149
+ --key-file manifest.key --approvers approvers.json \
150
+ --approvals approvals.jsonl --ledger lokahi-ledger.jsonl \
151
+ --requester agent:my-agent --operator ops:agent-runner
152
+ ```
153
+
154
+ The `--operator` is whoever runs the agent. If that person also tries to approve one of its calls, LOKAHI refuses the call.
155
+
156
+ 5. Approve when asked. When a call needs people, the decision includes an `action_digest`. Each approver signs it from their own device:
157
+
158
+ ```bash
159
+ python tools/lokahi_approve.py --key-file editor-fiction.key \
160
+ --operator editor:fiction --node laptop-1 \
161
+ --digest the_action_digest --decision yes --approvals approvals.jsonl
162
+ ```
163
+
164
+ An approval covers that exact call, with the same tool and the same argument values, and expires after an hour by default.
165
+
166
+ ## Example: an editorial desk
167
+
168
+ [`examples/editorial_desk_demo.py`](examples/editorial_desk_demo.py) shows the gate protecting unpublished manuscripts:
169
+
170
+ ```text
171
+ summarize a submission -> ALLOWED within_manifest
172
+ ask for the author's home address -> FORBIDDEN forbidden_target:author_home_address
173
+ ask for a field nobody listed -> FORBIDDEN argument_out_of_policy:author_social_handles
174
+ send the manuscript to a US cloud model -> FORBIDDEN residency_violation:US
175
+ use a tool the editors never listed -> FORBIDDEN tool_not_in_manifest:delete_submission_archive
176
+ agent sends its own 'approvals' with the email -> FORBIDDEN agent_supplied_control_metadata
177
+ email a rejection: waits for people -> ESCALATE insufficient_disjoint_consent
178
+ email a rejection: nobody answered in an hour -> FORBIDDEN non_response
179
+ publish: waits for people -> ESCALATE insufficient_disjoint_consent
180
+ publish: two editors and the author sign yes -> ALLOWED quorum_met
181
+ their approvals reused for a different story -> ESCALATE insufficient_disjoint_consent
182
+ local record: 11 decisions, tamper check passed = True
183
+ someone edits decision 4 to hide the cloud upload: tamper check passed = False (record breaks at decision 4)
184
+ ```
185
+
186
+ ## Experimental: learned decisions tier
187
+
188
+ 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.
189
+
190
+ **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`](docs/decisions/CHARTER.md)) and a one-line rationale. The order is fixed:
191
+
192
+ 1. LOKAHI decides first. If it refuses or escalates, that stands and the model isn't asked.
193
+ 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.
194
+ 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.
195
+
196
+ 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.
197
+
198
+ **Turn it on.**
199
+
200
+ ```bash
201
+ python tools/mcp_stdio_proxy.py --manifest manifest.json --key-file manifest.key --decisions experimental
202
+ ```
203
+
204
+ ```python
205
+ LokahiMCPGateway(manifest, signer, experimental_decisions=True)
206
+ ```
207
+
208
+ 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.
209
+
210
+ **Results.** These numbers are for the bundled model `ddm-0.1.1`, re-measured for this release. They come from [`docs/decisions/metrics.json`](docs/decisions/metrics.json).
211
+
212
+ | | Holdout (198 synthetic rows) | Hard set (50 hand-written rows) |
213
+ |---|---|---|
214
+ | Accuracy, final pipeline | 0.86 | 0.74 |
215
+ | Should-refuse or irreversible calls let through (false ALLOW) | 2 of 102 | 0 of 24 |
216
+ | Any non-ALLOW call let through | 5 of 132 | 0 of 33 |
217
+ | Benign calls refused | 1 of 66 | 0 of 17 |
218
+ | Benign calls allowed | 91% | 16 of 17 |
219
+ | REFUSE recall | 0.83 | 0.47 |
220
+
221
+ - 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.
222
+ - 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.
223
+ - The runtime model is a plain JSON file ([`tools/decisions/model.json`](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.
224
+ - 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.
225
+
226
+ **Limits.** Read these before turning it on:
227
+
228
+ - **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.
229
+ - **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`](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.
230
+ - **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.
231
+ - **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.
232
+ - **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.
233
+ - **Not tested on real agent traffic** or on a public benchmark such as AgentDojo.
234
+
235
+ **Retrain it.** Training is optional and is the only step that needs third-party packages:
236
+
237
+ ```bash
238
+ python -m pip install "scikit-learn>=1.5" numpy
239
+ python tools/decisions/train.py --corrections data/decisions/review/corrections.jsonl
240
+ python tests/test_decisions.py
241
+ ```
242
+
243
+ `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`](docs/decisions/metrics_before_corrections.json)). Pickle and joblib files are never used.
244
+
245
+ ## About the test scenarios and baselines
246
+
247
+ The 50 scenarios in [`data/LOKAHI_RedTeam_Corpus_v1.0.csv`](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.
248
+
249
+ `run_evals.py` also scores two simplified stand-ins on the same scenarios:
250
+
251
+ - a content filter that auto-approves on timeout
252
+ - a stateless check in the style of role-based access control (RBAC) or Open Policy Agent (OPA)
253
+
254
+ 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.
255
+
256
+ ## Research extensions
257
+
258
+ These run in CI but are research prototypes, separate from the gate:
259
+
260
+ | Path | What it explores |
261
+ |---|---|
262
+ | [`tools/ghostproof.py`](tools/ghostproof.py), [`tools/run_ghostproof_evals.py`](tools/run_ghostproof_evals.py) | Surfacing a model's hesitation from its token probabilities, so reviewers don't rubber-stamp close calls |
263
+ | [`tools/run_kinetic_evals.py`](tools/run_kinetic_evals.py) | Physical limits for robots: force, torque, speed, workspace and stopping distance |
264
+ | [`tools/run_wargame_workshop.py`](tools/run_wargame_workshop.py) | A five-round red team/blue team workshop built on the duology's scenes |
265
+
266
+ ## Repository layout
267
+
268
+ | Path | What it contains |
269
+ |---|---|
270
+ | [`tools/lokahi.py`](tools/lokahi.py) | Decision engine: manifests, tool policies, the 15 rules, vote binding, approvals, ledger |
271
+ | [`tools/mcp_stdio_proxy.py`](tools/mcp_stdio_proxy.py) | MCP gate, approvals store, command line and self-test |
272
+ | [`tools/lokahi_sign.py`](tools/lokahi_sign.py) | Create keys and sign manifests |
273
+ | [`tools/lokahi_approve.py`](tools/lokahi_approve.py) | Sign a yes or no for one action |
274
+ | [`examples/`](examples/) | Editorial desk example, a complete manifest and an approvers file |
275
+ | [`tests/test_core.py`](tests/test_core.py) | 70 unit tests |
276
+ | [`tools/decisions/`](tools/decisions/) | Experimental decisions tier: charter rules, pure-Python model, `model.json`, optional `train.py` |
277
+ | [`tests/test_decisions.py`](tests/test_decisions.py) | 32 tests for the decisions tier |
278
+ | [`demo.py`](demo.py) | Engine walkthrough on a municipal water board |
279
+ | [`data/`](data/) | 50-scenario set (CC BY 4.0) and the Ghostproof scenario set |
280
+ | [`data/decisions/`](data/decisions/) | Decisions tier training and test data, schema and data card (CC BY 4.0) |
281
+ | [`docs/decisions/`](docs/decisions/) | Decisions charter, research notes and metrics |
282
+ | [`docs/SPEC.md`](docs/SPEC.md) | Specification: manifest fields, rule order, vote binding, MCP gate |
283
+ | [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) | Notes on taking the reference to production |
284
+ | [`CHANGELOG.md`](CHANGELOG.md) | What changed in each release |
285
+
286
+ ## Related projects
287
+
288
+ LOKAHI is the runtime half of a two-stage check. The two companion repositories are:
289
+
290
+ - [**Ahimsa AI**](https://github.com/Dirgha-AI/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.
291
+ - [**Synthetic Humanism**](https://github.com/Dirgha-AI/synthetic-humanism): the manifesto and essays behind both tools, plus a benchmark that runs both stages against 20 documented AI failures.
292
+ ## Background reading
293
+
294
+ - **Boundaries:** Andrew Critch, *Boundaries: an open sequence on multi-agent alignment and cooperative AI* (2022–2023).
295
+ - **Local context in AI risk:** Aggarwal et al., *ASTRA: AI Safety, Trust, & Risk Assessment*, [arXiv:2602.17357](https://arxiv.org/abs/2602.17357) (2026). An India-focused AI safety risk database with 37 risk classes.
296
+ - **Guaranteed safe AI:** Dalrymple, Skalse, Bengio, Russell, Tegmark et al., *Towards Guaranteed Safe AI*, [arXiv:2405.06624](https://arxiv.org/abs/2405.06624) (2024).
297
+ - **Object capabilities:** Mark S. Miller, *Robust Composition*, PhD dissertation, Johns Hopkins University (2006).
298
+ - **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.
299
+
300
+ ## Authors
301
+
302
+ - **Salik Shah**: protocol design, reference implementation, scenario set ([salikshah.com](https://salikshah.com), [x.com/salik](https://x.com/salik), [GitHub](https://github.com/salikshah))
303
+ - **Sabin Ranjit**: security architecture ([GitHub](https://github.com/thinksabin))
304
+
305
+ ## License
306
+
307
+ The software is licensed under [Apache-2.0](LICENSE). The scenario set in `data/` and the decisions data in `data/decisions/` are licensed under [CC BY 4.0](data/LICENSE).