Wallgent
Guides

Add Payments to Your LangChain Agent

Integrate Wallgent financial tools into a LangChain agent using Python.

The Wallgent Python SDK ships in Phase 4. This guide shows the planned API so you can plan your integration today. See the REST fallback section below to get started now.

Prerequisites

1. Install (Phase 4)

pip install wallgent langchain langchain-openai

2. Import Tools

from wallgent.langchain import WallgentToolkit
from langchain_openai import ChatOpenAI

toolkit = WallgentToolkit(api_key="wg_test_your_key_here")
tools = toolkit.get_tools()

The toolkit exposes the same operations as the TypeScript SDK: create wallets, check balances, send payments, manage policies, create invoices, and more.

3. Create an Agent

from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_core.prompts import ChatPromptTemplate

llm = ChatOpenAI(model="gpt-4o")

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a financial agent. Use Wallgent tools to manage wallets and payments."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])

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

4. Complete Example

# Create a wallet and fund it
result = executor.invoke({
    "input": "Create a wallet called 'Research Bot', fund it with $100, and check the balance."
})
print(result["output"])

# Send a payment
result = executor.invoke({
    "input": "Send $15 from the Research Bot wallet to wal_01JVENDOR for API access."
})
print(result["output"])

# Create an invoice
result = executor.invoke({
    "input": "Create a customer for alice@example.com and invoice them $50 for consulting."
})
print(result["output"])

REST Fallback

You can use Wallgent with LangChain today by wrapping REST API calls as LangChain Tool objects:

import requests
from langchain.tools import Tool

API_KEY = "wg_test_your_key_here"
BASE = "https://api.wallgent.com"
HEADERS = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json",
}


def create_wallet(name: str) -> str:
    """Create a Wallgent wallet. Pass the wallet name as input."""
    resp = requests.post(
        f"{BASE}/v1/wallets",
        headers=HEADERS,
        json={"name": name, "agentName": "langchain-bot"},
    )
    return resp.text


def check_balance(wallet_id: str) -> str:
    """Check the balance of a Wallgent wallet. Pass the wallet ID as input."""
    resp = requests.get(f"{BASE}/v1/wallets/{wallet_id}/balance", headers=HEADERS)
    return resp.text


def send_payment(args: str) -> str:
    """Send a payment. Pass JSON with from, to, amount, and description."""
    import json
    data = json.loads(args)
    resp = requests.post(f"{BASE}/v1/payments", headers=HEADERS, json=data)
    return resp.text


tools = [
    Tool(name="create_wallet", func=create_wallet, description=create_wallet.__doc__),
    Tool(name="check_balance", func=check_balance, description=check_balance.__doc__),
    Tool(name="send_payment", func=send_payment, description=send_payment.__doc__),
]

Use these tools with any LangChain agent:

from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate

llm = ChatOpenAI(model="gpt-4o")
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a financial agent. Use the available tools to manage wallets and payments."),
    ("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": "Create a wallet called 'LC Bot' and check its balance."})
print(result["output"])

Next Steps

On this page