Skip to main content

Installation

pip install xenarch[agent,langchain]
Requires langchain>=0.3.0.

Tools

The SDK provides three LangChain tools:
from xenarch.tools.langchain import CheckGateTool, PayTool, GetHistoryTool

tools = [CheckGateTool(), PayTool(), GetHistoryTool()]
ToolDescription
CheckGateToolCheck if a URL has an x402 payment gate
PayToolExecute USDC payment and return access token
GetHistoryToolView past payments for this wallet

Usage with LangGraph

from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from xenarch.tools.langchain import CheckGateTool, PayTool, GetHistoryTool

load_dotenv()

llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
tools = [CheckGateTool(), PayTool(), GetHistoryTool()]

agent = create_react_agent(
    llm,
    tools,
    prompt=(
        "You are a helpful assistant with Xenarch payment tools. "
        "You can check URLs for payment gates, pay for gated content, "
        "and review payment history."
    ),
)

result = agent.invoke({
    "messages": [{
        "role": "user",
        "content": "Check if example.com has a paywall and pay if needed."
    }]
})

Using with other LLMs

# Anthropic
from langchain_anthropic import ChatAnthropic
llm = ChatAnthropic(model="claude-sonnet-4-20250514")

# Local model via Ollama
from langchain_community.llms import Ollama
llm = Ollama(model="llama3")

Wallet configuration

The tools use the same wallet configuration as the core SDK:
  1. XENARCH_PRIVATE_KEY environment variable
  2. ~/.xenarch/config.json
  3. ~/.xenarch/wallet.json
  4. Auto-generate on first use
See Agent Quickstart for wallet setup.

Full example

See the LangChain agent example for a complete working script.