Skip to main content

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:

  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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_xache-0.6.0.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_xache-0.6.0-py3-none-any.whl (25.0 kB view details)

Uploaded Python 3

File details

Details for the file langchain_xache-0.6.0.tar.gz.

File metadata

  • Download URL: langchain_xache-0.6.0.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.6

File hashes

Hashes for langchain_xache-0.6.0.tar.gz
Algorithm Hash digest
SHA256 d338dc99edafa54a33fe9bf301fae9fe49ce961699c63ea5adf97d2b4d59bb15
MD5 14253bb326d5381659961ab4d315d0c1
BLAKE2b-256 d339b370875ece6abe9f494086398689cd7d985cb08b52f1f0520fa7c363a6c8

See more details on using hashes here.

File details

Details for the file langchain_xache-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_xache-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c8c17e9b5b03b6790f19a69cf3bb50f2899e97a03e38a5966184c0bf511b4b8
MD5 63f3fab884952af810d8b759acc4c04d
BLAKE2b-256 74f3c5b5845351a757bdb8c0d49879a8d5089fb5c3df19747d73fd4b56fa3da2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page