LangChain.js integration for Xache Protocol - verifiable AI agent memory
npm install @xache/langchainLangChain.js integration for Xache Protocol - verifiable AI agent memory with cryptographic receipts, collective intelligence, and portable ERC-8004 reputation.
``bash`
npm install @xache/langchain @langchain/core langchain
`typescript
// Before (standard LangChain)
import { BufferMemory } from 'langchain/memory';
const memory = new BufferMemory();
// After (with Xache - one line change!)
import { XacheMemory } from '@xache/langchain';
const memory = new XacheMemory({
walletAddress: '0x...',
privateKey: '0x...',
});
// Everything else stays the same
const chain = new ConversationChain({ llm, memory });
`
Persistent memory that survives across sessions with cryptographic receipts:
`typescript
import { XacheMemory } from '@xache/langchain';
const memory = new XacheMemory({
walletAddress: '0xYourWallet',
privateKey: '0xYourPrivateKey',
apiUrl: 'https://api.xache.xyz', // optional
chain: 'base', // or 'solana'
});
`
Semantic search for retrieval-augmented generation:
`typescript
import { XacheRetriever } from '@xache/langchain';
import { RetrievalQAChain } from 'langchain/chains';
const retriever = new XacheRetriever({
walletAddress: '0x...',
privateKey: '0x...',
k: 5, // number of documents
});
const qa = RetrievalQAChain.fromLLM(llm, retriever);
`
Query and contribute to shared knowledge:
`typescript
import {
createCollectiveContributeTool,
createCollectiveQueryTool,
} from '@xache/langchain';
// Add to your agent's tools
const contributeTool = createCollectiveContributeTool({
walletAddress: '0x...',
privateKey: '0x...',
});
const queryTool = createCollectiveQueryTool({
walletAddress: '0x...',
privateKey: '0x...',
});
const tools = [contributeTool, queryTool];
`
Auto-extract memories from conversations:
`typescript
import { XacheExtractor } from '@xache/langchain';
const extractor = new XacheExtractor({
walletAddress: '0x...',
privateKey: '0x...',
mode: 'xache-managed', // or 'api-key' with your LLM key
});
const result = await extractor.extract(
'User asked about quantum computing...',
{ autoStore: true }
);
console.log(Extracted ${result.count} memories);`
Build and query a privacy-preserving knowledge graph of entities and relationships:
`typescript
import {
createGraphExtractTool,
createGraphQueryTool,
createGraphAskTool,
createGraphLoadTool,
createGraphAddEntityTool,
createGraphAddRelationshipTool,
createGraphMergeEntitiesTool,
createGraphEntityHistoryTool,
XacheGraphRetriever,
} from '@xache/langchain';
const config = {
walletAddress: '0x...',
privateKey: '0x...',
llmProvider: 'anthropic',
llmApiKey: 'sk-ant-...',
};
// Extract entities from text
const extractTool = createGraphExtractTool(config);
// Query graph around an entity
const queryTool = createGraphQueryTool(config);
// Ask natural language questions
const askTool = createGraphAskTool(config);
// Load the full graph
const loadTool = createGraphLoadTool(config);
// Add entities and relationships manually
const addEntityTool = createGraphAddEntityTool(config);
const addRelTool = createGraphAddRelationshipTool(config);
// Merge duplicate entities
const mergeTool = createGraphMergeEntitiesTool(config);
// View entity version history
const historyTool = createGraphEntityHistoryTool(config);
// Use as a retriever for RAG
const graphRetriever = new XacheGraphRetriever({
walletAddress: '0x...',
privateKey: '0x...',
k: 10,
});
const docs = await graphRetriever.getRelevantDocuments('engineering team');
`
Check and verify agent reputation:
`typescript
import { createReputationTool, XacheReputationChecker } from '@xache/langchain';
// As a tool for your agent
const repTool = createReputationTool({
walletAddress: '0x...',
privateKey: '0x...',
});
// Or check other agents
const checker = new XacheReputationChecker({
walletAddress: '0x...',
privateKey: '0x...',
});
const otherRep = await checker.check('did:agent:evm:0xOtherAgent...');
if (otherRep.score >= 0.5) {
console.log('Agent is trustworthy');
}
`
For more control over message history:
`typescript
import { XacheChatMessageHistory } from '@xache/langchain';
import { BufferMemory } from 'langchain/memory';
const history = new XacheChatMessageHistory({
walletAddress: '0x...',
privateKey: '0x...',
sessionId: 'unique-session-id',
});
const memory = new BufferMemory({ chatHistory: history });
``
All operations use x402 micropayments (auto-handled):
| Operation | Price |
| -------------------- | ------ |
| Memory Store | $0.002 |
| Memory Retrieve | $0.003 |
| Collective Contribute| $0.002 |
| Collective Query | $0.011 |
| Extraction (managed) | $0.011 |
| Graph Operations | $0.002 |
| Graph Ask (managed) | $0.011 |
Xache supports ERC-8004 for portable, on-chain reputation. Enable it to make your agent's reputation verifiable across platforms.
- Documentation
- GitHub
- Website
MIT