langchain-kavachos
KavachOS DAN gate callback for LangChain agents.
Intercepts every tool call through the AEGIS KAVACH gate before execution. Zero agent code changes — add the callback and every tool invocation is governed.
Install
pip install langchain-kavachos
Quick start
from langchain_kavachos import KavachGateCallback
callback = KavachGateCallback(
base_url="http://localhost:4850", # AEGIS server
on_block="raise", # raise KavachGateError on DAN-3/4
dry_run=False,
)
# LangChain agent — pass callback in config
result = agent.invoke(
{"input": "summarise the quarterly report"},
config={"callbacks": [callback]},
)
# Or attach to a single tool:
result = my_tool.invoke("drop table users", config={"callbacks": [callback]})
KavachGateCallback parameters
| Parameter | Default | Description |
|---|---|---|
base_url |
http://localhost:4850 |
AEGIS server URL |
token |
$AEGIS_TOKEN |
Bearer auth token |
on_block |
"raise" |
"raise" → KavachGateError · "warn" → print + continue |
dry_run |
False |
Classify only — no notification, no human-in-loop polling |
tool_name |
"langchain" |
Label appearing in audit records |
session_id |
auto-generated | Audit grouping key (one per agent session) |
Direct client
from langchain_kavachos import AegisClient
client = AegisClient(base_url="http://localhost:4850")
# Pre-flight budget check
state = client.state()
if state["budget"]["breached"]:
raise RuntimeError("Daily budget breached — halt")
# Manual gate call
result = client.gate(command="rm -rf /var/postgres", tool_name="my-agent")
print(result) # {"allow": false, "level": 4, "reason": "DAN-4 catastrophic..."}
# Audit query
records = client.audit(session_id="lc-abc123", status="stop", limit=20)
How it works
KavachGateCallback.on_tool_start() fires before any tool execution.
It POSTs to POST /api/v1/kavach/gate on the AEGIS server.
- DAN-1/2: allowed immediately, logged.
- DAN-3: notify approver via Telegram/WhatsApp, wait for ALLOW/STOP.
- DAN-4: blocked immediately,
KavachGateErrorraised.
All policy is in AEGIS — the callback is a thin HTTP relay.
AEGIS server
Run with: bun /root/aegis/src/dashboard/server.ts
Default port: 4850
Gate endpoint: POST /api/v1/kavach/gate
License
AGPL-3.0 — see LICENSE.
Metadata
Release files for langchain-kavachos 1.0.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 | |
|---|---|---|---|
| langchain_kavachos-1.0.0.tar.gz | 5.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_kavachos-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.5 kB
Release files / langchain_kavachos-1.0.0.tar.gz
| Download URL | langchain_kavachos-1.0.0.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c2a37ffa6159e3bdb7098baeea9b606ad05497283c0124ba8101c0f79a94039a
|
|
BLAKE2b-256 checksum How to use checksums |
ac6b946c90a253813b4b5547125244794f22a563fbc16fa3231cfb5105bd013c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / langchain_kavachos-1.0.0-py3-none-any.whl
| Download URL | langchain_kavachos-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c4e575613d315906cf6602620e7b2df3ebe67b0288c55b744498833055a435f9
|
|
BLAKE2b-256 checksum How to use checksums |
8ab9a2fe887dd9c66f39ee545589676fc2802a53652be3bb732fe420a34ff2c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|