Back to Docs
Integration Guide
LangChain Integration
LangChain integration uses the generic wrap() method on the RANKIGI SDK. Wrap your agent or executor invocation and the input args plus the final result are SHA-256 hashed and appended to your tamper-evident chain.
Callback Handler
The Node SDK ships RankigiCallbackHandler, which hooks every LangChain lifecycle event (tool start/end, agent action, LLM end, errors) and seals each into your chain.
typescript
import { Rankigi } from "@rankigi/sdk";
import { RankigiCallbackHandler } from "@rankigi/sdk/langchain";
const rk = Rankigi.fromEnv();
const handler = new RankigiCallbackHandler({ client: rk, sessionId: "research-agent" });
const executor = new AgentExecutor({ agent, tools, callbacks: [handler] });Prefer the generic wrap() pattern below when you want one event per invocation instead of per lifecycle hook.
Installation
Node.js / TypeScript
bash
npm install @rankigi/sdk @langchain/core langchainPython
bash
pip install rankigi langchain-core langchainEnvironment
Use npx @rankigi/cli init to issue a credential and write RANKIGI_CREDENTIAL and RANKIGI_CHAIN_ID into your .env.
bash
RANKIGI_CREDENTIAL=rnk_live_cred_v1...
RANKIGI_CHAIN_ID=chn_your_chain_id
OPENAI_API_KEY=sk-...Quick Start. Node.js
typescript
import "dotenv/config";
import { Rankigi } from "@rankigi/sdk";
import { AgentExecutor, createOpenAIFunctionsAgent } from "langchain/agents";
import { ChatOpenAI } from "@langchain/openai";
const rk = Rankigi.fromEnv();
const llm = new ChatOpenAI({ modelName: "gpt-4" });
const agent = await createOpenAIFunctionsAgent({ llm, tools, prompt });
const executor = new AgentExecutor({ agent, tools });
// Wrap the executor invocation. The input args and the final
// output are SHA-256 hashed and appended to your chain.
const input = { input: "your task" };
const result = await rk.wrap(
"langchain-run",
input,
() => executor.invoke(input),
);
await rk.close();Quick Start. Python
python
from dotenv import load_dotenv
load_dotenv()
from rankigi import Rankigi
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
rk = Rankigi.from_env()
llm = ChatOpenAI(model="gpt-4")
agent = initialize_agent(
tools=tools,
llm=llm,
agent=AgentType.OPENAI_FUNCTIONS,
)
# Wrap the agent.run() call. Input and output are hashed
# and appended to your tamper-evident chain.
result = rk.wrap(
"langchain-run",
{"input": "your task"},
lambda: agent.run("your task"),
)
rk.close()Sidecar Guarantees
Blocking behaviorNever blocks agent execution
Error propagationFailures logged to stderr, never thrown
Data transmittedSHA-256 hashes only, no raw input/output
Transport (Node.js)One POST per event, 3 retries with exponential backoff
Transport (Python)Daemon thread queue, no retry