lelu
Integrations

LangGraph

Add authorization checkpoints to LangGraph workflows. Gate tool nodes, interrupt on human review, and resume graphs after approval.

Installation

terminal
npm install lelu-agent-auth @langchain/langgraph

Authorization node

Add a Lelu node before any tool node to gate execution. The node reads the pending tool call from state, evaluates it, and routes to execute, block, or review.

graph.ts
import { StateGraph, Annotation } from "@langchain/langgraph";
import { createClient } from "lelu-agent-auth";

const lelu = createClient({ apiKey: process.env.LELU_API_KEY! });

const State = Annotation.Root({
  tool: Annotation<string>(),
  context: Annotation<string>(),
  decision: Annotation<string>(),
  result: Annotation<string>(),
});

async function leluGuard(state: typeof State.State) {
  const { decision, reason } = await lelu.authorize({
    tool: state.tool,
    context: state.context,
  });
  return { decision, reason };
}

const graph = new StateGraph(State)
  .addNode("agent", agentNode)
  .addNode("lelu_guard", leluGuard)
  .addNode("execute_tool", executeToolNode)
  .addNode("blocked", blockedNode)
  .addEdge("agent", "lelu_guard")
  .addConditionalEdges("lelu_guard", (s) => s.decision, {
    allow: "execute_tool",
    deny: "blocked",
    human_review: "execute_tool", // interrupted for approval
  })
  .compile({ interruptBefore: ["execute_tool"] }); // pause for human review

Resume after approval

approve.ts
// After human approves in your dashboard:
await graph.updateState(threadId, { decision: "allow" });
await graph.invoke(null, { configurable: { thread_id: threadId } });