Skip to content

LangChain — Python Tools

Connect any LangChain agent to DPX by wrapping the oracle REST endpoints with the @tool decorator. No SDK or API key required — all pricing endpoints are public.

Terminal window
pip install langchain langchain-openai httpx
import httpx
from langchain_core.tools import tool
STABILITY_URL = "https://stability.untitledfinancial.com"
ESG_URL = "https://esg.untitledfinancial.com"
@tool
def dpx_get_quote(amount_usd: float, has_fx: bool = False, esg_score: int = 75) -> dict:
"""Get a binding DPX fee quote for a settlement. Returns core, FX, ESG, and license components plus a quoteId valid for 300 seconds."""
r = httpx.get(f"{STABILITY_URL}/quote", params={
"amountUsd": amount_usd,
"hasFx": str(has_fx).lower(),
"esgScore": esg_score
})
return r.json()
@tool
def dpx_get_reliability() -> dict:
"""Check current peg stability and oracle health before a large settlement. Returns stability score, peg deviation, and confidence level."""
return httpx.get(f"{STABILITY_URL}/reliability").json()
@tool
def dpx_get_esg_score() -> dict:
"""Get live Environmental, Social, and Governance scores from the DPX ESG Oracle. Returns E, S, G sub-scores and the current ESG fee component."""
return httpx.get(f"{ESG_URL}/esg-score").json()
@tool
def dpx_get_manifest() -> dict:
"""Get the DPX protocol manifest — contract addresses, fee configuration, and supported capabilities."""
return httpx.get(f"{STABILITY_URL}/manifest").json()
@tool
def dpx_verify_fees() -> dict:
"""Verify that the current fee quote matches on-chain enforcement via the deployed smart contracts."""
return httpx.get(f"{STABILITY_URL}/verify-fees").json()
dpx_tools = [
dpx_get_quote,
dpx_get_reliability,
dpx_get_esg_score,
dpx_get_manifest,
dpx_verify_fees,
]
from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate
llm = ChatOpenAI(model="gpt-5.1")
prompt = ChatPromptTemplate.from_messages([
("system", "You are a treasury intelligence assistant with access to DPX settlement pricing tools."),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
])
agent = create_tool_calling_agent(llm, dpx_tools, prompt)
executor = AgentExecutor(agent=agent, tools=dpx_tools, verbose=True)
result = executor.invoke({
"input": "Price a $2M cross-border settlement with ESG score 75 and check if stability is healthy enough to proceed."
})
print(result["output"])
AGENT_URL = "https://agent.untitledfinancial.com"
COMPLIANCE_URL = "https://compliance.untitledfinancial.com"
@tool
def dpx_route(amount: float, from_currency: str, to_currency: str) -> dict:
"""Rank USDC, EURC, and USDT for this currency pair. Returns recommended token and settleBody."""
return httpx.get(f"{AGENT_URL}/route", params={
"amount": amount, "from": from_currency, "to": to_currency
}).json()
@tool
def dpx_screen_counterparty(address: str, lei: str = "") -> dict:
"""AML/sanctions/FATF screen. Returns APPROVED, FLAGGED, or BLOCKED with risk signals."""
params = {"address": address}
if lei:
params["lei"] = lei
return httpx.get(f"{COMPLIANCE_URL}/compliance/screen", params=params).json()
@tool
def dpx_vendor_risk(name: str, address: str = "", lei: str = "") -> dict:
"""Composite 0–100 vendor risk score (65% compliance + 35% ESG). Returns tier: LOW/MODERATE/ELEVATED/HIGH."""
return httpx.post(f"{COMPLIANCE_URL}/vendor-risk", json={
"name": name, "wallet": address, "lei": lei
}).json()

A typed state-graph implementation is in the DPX Python SDK:

Terminal window
git clone https://github.com/untitledfinancial/dpx-protocol
cd dpx-protocol/dpx-python-sdk
pip install langgraph langchain-anthropic httpx
python examples/langgraph_settlement_agent.py

The graph runs: flow_check → [PROCEED → settle → done] | [HOLD/BLOCKED → blocked → done]

A single flow_check node replaces what was previously three nodes (screen → esg_score → route), running all three checks in parallel on the server and returning a ready-to-use settle body on PROCEED.

from langgraph.graph import StateGraph, END
builder = StateGraph(SettlementState)
builder.add_node("flow_check", node_flow_check)
builder.add_node("settle", node_settle)
builder.add_node("blocked", node_blocked)
builder.set_entry_point("flow_check")
builder.add_conditional_edges("flow_check", route_after_flow_check,
{"settle": "settle", "blocked": "blocked"})
builder.add_edge("settle", END)
builder.add_edge("blocked", END)

flow_check calls GET /flow-check — one request covering AML screening, ESG score, oracle stability, and stablecoin routing. Returns PROCEED, HOLD, or BLOCKED. On PROCEED, state includes settle_body with the recommended token and a ready-to-POST payload. Any BRL corridor also includes a regulatoryWarning with the BCB Resolution 561 deadline.

No API key required. Settlement node requires x402 payment in live mode (SANDBOX=false).

ToolEndpointAuth
dpx_get_quotestability.untitledfinancial.com/quoteNone
dpx_get_reliabilitystability.untitledfinancial.com/reliabilityNone
dpx_get_esg_scorestability.untitledfinancial.com/esg/scoreNone
dpx_get_manifeststability.untitledfinancial.com/manifestNone
dpx_verify_feesstability.untitledfinancial.com/verify-feesNone
dpx_flow_checkagent.untitledfinancial.com/flow-checkNone
dpx_routeagent.untitledfinancial.com/routeNone
dpx_screen_counterpartycompliance.untitledfinancial.com/compliance/screenNone
dpx_vendor_riskcompliance.untitledfinancial.com/vendor-riskNone

For LangChain agents that need to call Claude or run alongside Claude Desktop, use the MCP integration instead — it gives schema updates automatically and works natively with all MCP-compatible hosts.

Terminal window
STABILITY_ORACLE_URL=https://stability.untitledfinancial.com
ESG_ORACLE_URL=https://esg.untitledfinancial.com

Both endpoints are public. No API key required for pricing and monitoring.