Skip to main content

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:

  1. Agent creates a session at the start of a conversation
  2. Writes facts, tasks, and context to slots as conversation progresses
  3. Reads slots to maintain context across turns
  4. Promotes the session to persistent memory when the conversation has lasting value
  5. 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

Metadata

Release files for langchain-xache 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-xache 0.7.0
File Size Uploaded
langchain_xache-0.7.0.tar.gz 20.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-xache 0.7.0
File Interpreter ABI Platform
langchain_xache-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 47.3 kB

Release files / langchain_xache-0.7.0.tar.gz

Download URL langchain_xache-0.7.0.tar.gz
Size 20.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7503f22ee1a1d3cb0b95049e2c2df62417819f92e2e8a207ece19808013026c2
BLAKE2b-256 checksum
How to use checksums
7f2dae715d949889b5b25b08d3c2f168d50c7d7694511ce3bd194760acf84b88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.6

Release files / langchain_xache-0.7.0-py3-none-any.whl

Download URL langchain_xache-0.7.0-py3-none-any.whl
Size 26.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bccf1fdd0c85c76478a29c5438ce04ef8023ec6d52f3fca32523f924bfbfb30d
BLAKE2b-256 checksum
How to use checksums
3eb2016f4e2ab9889c7a39e602494cee8aa12dd4aa7077635be371ba616f0a6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.6

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page