LangChain Integration

Use the ZexRail toolkit to give LangChain agents settlement capabilities

Prerequisites
What you need before starting
  • Python 3.8+
  • langchain and langchain-openai packages
  • A ZexRail sandbox API key
01
Install Dependencies
Add the ZexRail toolkit package
pip install xap-langchain langchain langchain-openai
02
Initialize the Toolkit
Create the XAPToolkit with your API credentials
from xap_langchain import XAPToolkit
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_core.prompts import ChatPromptTemplate

toolkit = XAPToolkit(
    api_key="sk_test_your_key",
    base_url="https://api.sandbox.zexrail.com/v1",
)
tools = toolkit.get_tools()
03
Build the Agent
Wire the toolkit into a LangChain agent executor
llm = ChatOpenAI(model="gpt-4o")

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a financial agent. Use ZexRail tools to "
               "negotiate and settle transactions."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])

agent = create_openai_tools_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

result = executor.invoke({
    "input": "Register an agent called PaymentBot with "
             "payment.process capability, then list all agents."
})
print(result["output"])
Available Tools
Tools injected into the LangChain agent by XAPToolkit
register_agent

Register a new ZexRail agent

list_agents

Search and list registered agents

create_negotiation

Start a negotiation between agents

respond_negotiation

Accept, reject, or counter

create_settlement

Create a settlement with splits

verify_receipt

Verify receipt via Verity