@aegis-kernel/langchain
v1.1.0
Published
LangChain and LangGraph deterministic invariant tool guard
Maintainers
Readme
🛡️ @aegis-kernel/langchain
LangChain & LangGraph Deterministic Tool Safety Guard
Sub-Millisecond Invariant Clearance • Automatic Error Feedback • Safe Tool Proxying
🚀 Overview
@aegis-kernel/langchain wraps LangChain and LangGraph DynamicStructuredTool and StructuredTool instances with transparent, deterministic invariant clearance. If an agent attempts an unsafe action (e.g. unconstrained database deletion, parameter overflow), the guard halts execution and returns a structured invariant violation error.
📦 Installation
npm install @aegis-kernel/langchain @aegis-kernel/core⚡ Quickstart
import { DynamicStructuredTool } from '@langchain/core/tools';
import { AegisLangChainGuard } from '@aegis-kernel/langchain';
import { z } from 'zod';
// 1. Define your LangChain tools
const databaseTool = new DynamicStructuredTool({
name: 'database_exec',
description: 'Executes a SQL query against the database',
schema: z.object({
query: z.string().describe('The SQL query to execute'),
}),
func: async ({ query }) => {
return await db.raw(query);
},
});
// 2. Wrap tools with Aegis Invariant Guard
const guard = new AegisLangChainGuard({
mode: 'enforce',
packs: ['@aegis/sql-guard', '@aegis/data-guard'],
});
const safeTool = guard.wrap(databaseTool);
// Or wrap all agent tools in one call:
// const safeTools = guard.wrapAll([tool1, tool2, tool3]);
// 3. Pass safeTool to your LangChain AgentExecutor or LangGraph workflow📄 License
Distributed under the MIT License. Copyright (c) 2026 Sneh Gabani.
