Skip to content

LangChain

LangChain Tools (langchain-cerebrus-pulse)

Section titled “LangChain Tools (langchain-cerebrus-pulse)”

langchain-cerebrus-pulse turns every Cerebrus Pulse endpoint into a LangChain tool. The tools share one cerebrus-pulse client: give it a wallet key and paid tools pay automatically, all under the same spend limits.

Terminal window
pip install "langchain-cerebrus-pulse>=0.4.0" # tools; paid ones report the price instead of paying
pip install "langchain-cerebrus-pulse[pay]>=0.4.0" # + automatic payment in USDC on Base
pip install "langchain-cerebrus-pulse[svm]>=0.4.0" # + automatic payment in USDC on Solana too

Keep the >=0.4.0: without it pip can settle on an older release, which has no pay or svm extra.

import os
from cerebrus_pulse import CerebrusPulse
from langchain_cerebrus_pulse import (
CerebrusListCoinsTool, CerebrusPulseTool, CerebrusScreenerTool,
CerebrusLiquidationsTool, CerebrusFundingTool, CerebrusBundleTool,
)
# A dedicated, low-balance Base wallet holding a little USDC. Omit wallet_key
# and paid tools return the price and payee instead of data.
client = CerebrusPulse(
wallet_key=os.environ["CEREBRUS_WALLET_KEY"],
max_payment_usd="0.10", # most one call may cost
max_spend_usd="1.00", # most this client may spend in total
)
tools = [
tool(client=client)
for tool in (
CerebrusListCoinsTool, CerebrusPulseTool, CerebrusScreenerTool,
CerebrusLiquidationsTool, CerebrusFundingTool, CerebrusBundleTool,
)
]
from langchain.agents import create_agent
agent = create_agent(
"openai:gpt-4o", # any chat model that supports tool calling
tools=tools,
system_prompt="You answer questions about Hyperliquid markets with Cerebrus Pulse data.",
)
result = agent.invoke({
"messages": [{"role": "user", "content": "Where are the modelled BTC liquidation clusters?"}]
})
print(result["messages"][-1].content)
print(f"Spent: ${client.spent_usd}")

When a paid tool cannot pay, it returns JSON the model can read: {"error": ..., "payment_required": true, "price_usd": "...", "payment_terms": [...]}. A refusal by the spend limits adds a reason, and nothing is signed.

Each paid tool costs what its endpoint costs; see the endpoint table.

ToolEndpoint
CerebrusListCoinsToolGET /coins (free)
CerebrusPulseToolGET /pulse/{coin}
CerebrusScreenerToolGET /screener
CerebrusLiquidationsToolGET /liquidations/{coin}
CerebrusStressToolGET /arb
CerebrusCexDexToolGET /cex-dex/{token}
CerebrusBasisToolGET /basis/{coin}
CerebrusDepegToolGET /depeg
CerebrusSentimentToolGET /sentiment
CerebrusFundingToolGET /funding/{coin}
CerebrusOIToolGET /oi/{coin}
CerebrusSpreadToolGET /spread/{coin}
CerebrusCorrelationToolGET /correlation
CerebrusBundleToolGET /bundle/{coin}

The spend limits also read CEREBRUS_MAX_PAYMENT_USD, CEREBRUS_MAX_SPEND_USD and CEREBRUS_ALLOWED_PAYTO; see the Python client.