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, 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",  # optional
    chain="base"  # or "solana"
)

Retrieval (RAG)

Semantic search for retrieval-augmented generation:

from xache_langchain import XacheRetriever
from langchain.chains import RetrievalQA

retriever = XacheRetriever(
    wallet_address="0x...",
    private_key="0x...",
    k=5  # number of documents
)

qa = RetrievalQA.from_chain_type(llm=llm, retriever=retriever)

Collective Intelligence

Query and contribute to shared knowledge:

from xache_langchain import XacheCollectiveContributeTool, XacheCollectiveQueryTool

# Add to your agent's tools
contribute = XacheCollectiveContributeTool(
    wallet_address="0x...",
    private_key="0x..."
)

query = XacheCollectiveQueryTool(
    wallet_address="0x...",
    private_key="0x..."
)

tools = [contribute, query, ...]

Memory Extraction

Auto-extract memories from conversations:

from xache_langchain import XacheExtractor

extractor = XacheExtractor(
    wallet_address="0x...",
    private_key="0x...",
    mode="xache-managed"  # or "api-key" with your LLM key
)

result = extractor.extract(
    trace="User asked about quantum computing...",
    auto_store=True  # automatically store extracted memories
)

print(f"Extracted {len(result.memories)} memories")

Knowledge Graph

Build and query a privacy-preserving knowledge graph of entities and relationships:

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 entities from text
extract_tool = XacheGraphExtractTool(**config)

# Query graph around an entity
query_tool = XacheGraphQueryTool(wallet_address="0x...", private_key="0x...")

# Ask natural language questions
ask_tool = XacheGraphAskTool(**config)

# Load the full graph
load_tool = XacheGraphLoadTool(wallet_address="0x...", private_key="0x...")

# Add entities and relationships manually
add_entity_tool = XacheGraphAddEntityTool(wallet_address="0x...", private_key="0x...")
add_rel_tool = XacheGraphAddRelationshipTool(wallet_address="0x...", private_key="0x...")

# Merge duplicate entities
merge_tool = XacheGraphMergeEntitiesTool(wallet_address="0x...", private_key="0x...")

# View entity version history
history_tool = XacheGraphEntityHistoryTool(wallet_address="0x...", private_key="0x...")

# Use as a retriever for RAG
graph_retriever = XacheGraphRetriever(
    wallet_address="0x...",
    private_key="0x...",
    k=10
)

docs = graph_retriever.get_relevant_documents("engineering team")

Reputation

Check and verify agent reputation:

from xache_langchain import XacheReputationTool, XacheReputationChecker

# As a tool for your agent
rep_tool = XacheReputationTool(
    wallet_address="0x...",
    private_key="0x..."
)

# Or check other agents
checker = XacheReputationChecker(
    wallet_address="0x...",
    private_key="0x..."
)

other_rep = checker.check("did:agent:evm:0xOtherAgent...")
if other_rep.score >= 0.5:
    print("Agent is trustworthy")

Chat History

For more control over message 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
Extraction (managed) $0.011
Graph Operations $0.002
Graph Ask (managed) $0.011

ERC-8004 Portable Reputation

Xache supports ERC-8004 for portable, on-chain reputation. Enable it to make your agent's reputation verifiable across platforms.

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.4.0.tar.gz (17.6 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.4.0-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: langchain_xache-0.4.0.tar.gz
  • Upload date:
  • Size: 17.6 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.4.0.tar.gz
Algorithm Hash digest
SHA256 6545f262951c06abdf9515972c0719ef1ada6f5ae880cd57a20b71b2da90900c
MD5 36325f8af5ab7831d55cf26a21011c37
BLAKE2b-256 7c60b08f3c6e3d3bf64ad430e9a3406efcd12e89d90c62e365c8fb800ecd6a28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for langchain_xache-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4c7793b9a45b740c59b11bb8bda9a607eb628512c764a3b93043d58c4de6176e
MD5 eed5a7dc076aa26e10269d8157786fc5
BLAKE2b-256 99b696bf9d0b3a88b4c4190b7006b0c32ac1b00e707b0267e4c1818bb09f914a

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