KavachOS DAN gate callback for LangChain agents — pre-execution governance via AEGIS
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_kavachos-1.0.0.tar.gz.
File metadata
- Download URL: langchain_kavachos-1.0.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2a37ffa6159e3bdb7098baeea9b606ad05497283c0124ba8101c0f79a94039a
|
|
| MD5 |
0c981328528cc863ffb44b12ec01bf7b
|
|
| BLAKE2b-256 |
ac6b946c90a253813b4b5547125244794f22a563fbc16fa3231cfb5105bd013c
|
File details
Details for the file langchain_kavachos-1.0.0-py3-none-any.whl.
File metadata
- Download URL: langchain_kavachos-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4e575613d315906cf6602620e7b2df3ebe67b0288c55b744498833055a435f9
|
|
| MD5 |
c4af1386e1fbfffc2aa2083beb3b0e0b
|
|
| BLAKE2b-256 |
8ab9a2fe887dd9c66f39ee545589676fc2802a53652be3bb732fe420a34ff2c1
|