LangChain integration for Xache Protocol - verifiable AI agent memory
Project description
langchain-xache
LangChain integration for Xache Protocol - verifiable AI agent memory with cryptographic receipts, collective intelligence, ephemeral working memory, knowledge graph, and portable ERC-8004 reputation.
Installation
pip install langchain-xache
Quick Start
One-Line Memory Replacement
# Before (standard LangChain)
from langchain.memory import ConversationBufferMemory
memory = ConversationBufferMemory()
# After (with Xache - one line change!)
from xache_langchain import XacheMemory
memory = XacheMemory(
wallet_address="0x...",
private_key="0x..."
)
# Everything else stays the same
agent = initialize_agent(tools, llm, memory=memory)
Features
Memory Storage
Persistent memory that survives across sessions with cryptographic receipts:
from xache_langchain import XacheMemory
memory = XacheMemory(
wallet_address="0xYourWallet",
private_key="0xYourPrivateKey",
api_url="https://api.xache.xyz",
chain="base"
)
Retrieval (RAG)
from xache_langchain import XacheRetriever
from langchain.chains import RetrievalQA
retriever = XacheRetriever(
wallet_address="0x...",
private_key="0x...",
k=5
)
qa = RetrievalQA.from_chain_type(llm=llm, retriever=retriever)
Collective Intelligence
from xache_langchain import XacheCollectiveContributeTool, XacheCollectiveQueryTool
contribute = XacheCollectiveContributeTool(
wallet_address="0x...",
private_key="0x..."
)
query = XacheCollectiveQueryTool(
wallet_address="0x...",
private_key="0x..."
)
tools = [contribute, query]
Memory Extraction
from xache_langchain import XacheExtractor
extractor = XacheExtractor(
wallet_address="0x...",
private_key="0x...",
mode="xache-managed"
)
result = extractor.extract(
trace="User asked about quantum computing...",
auto_store=True
)
Knowledge Graph
Build and query a privacy-preserving knowledge graph:
from xache_langchain import (
XacheGraphExtractTool,
XacheGraphLoadTool,
XacheGraphQueryTool,
XacheGraphAskTool,
XacheGraphAddEntityTool,
XacheGraphAddRelationshipTool,
XacheGraphMergeEntitiesTool,
XacheGraphEntityHistoryTool,
XacheGraphRetriever,
)
config = {
"wallet_address": "0x...",
"private_key": "0x...",
"llm_provider": "anthropic",
"llm_api_key": "sk-ant-...",
}
extract_tool = XacheGraphExtractTool(**config)
query_tool = XacheGraphQueryTool(wallet_address="0x...", private_key="0x...")
ask_tool = XacheGraphAskTool(**config)
# Use as a retriever for RAG
graph_retriever = XacheGraphRetriever(
wallet_address="0x...",
private_key="0x...",
k=10
)
Ephemeral Context (Working Memory)
Short-lived scratch sessions for multi-turn workflows with 6 named slots (conversation, facts, tasks, cache, scratch, handoff):
from xache_langchain import (
XacheEphemeralCreateSessionTool,
XacheEphemeralWriteSlotTool,
XacheEphemeralReadSlotTool,
XacheEphemeralPromoteTool,
XacheEphemeralStatusTool,
)
# Create tools for your agent
create_session = XacheEphemeralCreateSessionTool(
wallet_address="0x...",
private_key="0x..."
)
write_slot = XacheEphemeralWriteSlotTool(
wallet_address="0x...",
private_key="0x..."
)
read_slot = XacheEphemeralReadSlotTool(
wallet_address="0x...",
private_key="0x..."
)
promote = XacheEphemeralPromoteTool(
wallet_address="0x...",
private_key="0x..."
)
status = XacheEphemeralStatusTool(
wallet_address="0x...",
private_key="0x..."
)
tools = [create_session, write_slot, read_slot, promote, status]
Typical agent workflow:
- Agent creates a session at the start of a conversation
- Writes facts, tasks, and context to slots as conversation progresses
- Reads slots to maintain context across turns
- Promotes the session to persistent memory when the conversation has lasting value
- Or lets the session expire if the context is transient
Reputation
from xache_langchain import XacheReputationTool, XacheReputationChecker
rep_tool = XacheReputationTool(
wallet_address="0x...",
private_key="0x..."
)
checker = XacheReputationChecker(
wallet_address="0x...",
private_key="0x..."
)
Chat History
from xache_langchain import XacheChatMessageHistory
from langchain.memory import ConversationBufferMemory
history = XacheChatMessageHistory(
wallet_address="0x...",
private_key="0x...",
session_id="unique-session-id"
)
memory = ConversationBufferMemory(chat_memory=history)
Pricing
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 |
| Ephemeral Session | $0.005 |
| Ephemeral Promote | $0.05 |
| Extraction (managed) | $0.011 |
| Graph Operations | $0.002 |
| Graph Ask (managed) | $0.011 |
Resources
License
MIT
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_xache-0.7.0.tar.gz.
File metadata
- Download URL: langchain_xache-0.7.0.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7503f22ee1a1d3cb0b95049e2c2df62417819f92e2e8a207ece19808013026c2
|
|
| MD5 |
05cd3b7b33e4844ddad50dd66a2937b4
|
|
| BLAKE2b-256 |
7f2dae715d949889b5b25b08d3c2f168d50c7d7694511ce3bd194760acf84b88
|
File details
Details for the file langchain_xache-0.7.0-py3-none-any.whl.
File metadata
- Download URL: langchain_xache-0.7.0-py3-none-any.whl
- Upload date:
- Size: 26.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bccf1fdd0c85c76478a29c5438ce04ef8023ec6d52f3fca32523f924bfbfb30d
|
|
| MD5 |
cb68c8877ae517370d2725165e5c0f37
|
|
| BLAKE2b-256 |
3eb2016f4e2ab9889c7a39e602494cee8aa12dd4aa7077635be371ba616f0a6f
|