Install
pip install -U langchain-cleavePython 3.10 or later. No API key is needed.
Example
This example also needs langchain and a chat model package:
pip install -U langchain-cleave langchain "langchain[anthropic]"from langchain.agents import create_agent
from langchain_cleave import CleaveToolkit
agent = create_agent(
model="claude-sonnet-4-6",
tools=CleaveToolkit().get_tools(),
)
agent.invoke(
{
"messages": [
{
"role": "user",
"content": (
"Plan a swap of 25 USDC to WETH on Base for wallet "
"0x00000000000000000000000000000000000A11cE"
),
}
]
}
)The four tools
The tools have the same names, inputs and answers as the tools of the MCP server, and call the keyless Agent REST API. CleaveToolkit().get_tools() returns all four.
| Tool | Class | What it does |
|---|---|---|
cleave_plan_swap | CleavePlanSwap | Plans a swap on one chain, a cross-chain swap or a bridge, and returns unsigned calls in signing order |
cleave_track_swap | CleaveTrackSwap | Reports the state of a sent plan or a gas order, and what arrived |
cleave_find_token | CleaveFindToken | Finds a token by symbol or address and flags look-alikes |
cleave_get_gas | CleaveGetGas | Offers native gas for USDC; with the relay turned on, passes the order the wallet signed to Cleave's relayer |
What the tools return
cleave_plan_swapreturns a plan whosecallsare unsigned and in signing order. The user's own wallet signs and sends them.- The tools never take a private key. They sign nothing; the only thing they send is a gas order the wallet has signed, and only when the gas relay is turned on.
- Read a plan in this order:
blockedandnotices, thenrequiresConfirmation, thenroute.outcomeKindandreceive, thenfees, thenvalidUntil. feeslists costs charged by others, such as a bridge fee. Cleave's fees are included in the price.
The gas relay is off by default
cleave_get_gasreturns offers. A call withofferorsignaturecomes back as a refusal with coderelay_disabled, without a request.- Turn the relay on in code, not from the agent, with
include_gas_relay=True:
from langchain_cleave import CleaveGetGas, CleaveToolkit
tools = CleaveToolkit(include_gas_relay=True).get_tools()
gas = CleaveGetGas(allow_relay=True)With the relay on, HumanInTheLoopMiddleware(interrupt_on={"cleave_get_gas": True}) pauses the agent so a person approves each signed order before it is sent; the agent needs a checkpointer. An authorization that is never submitted never debits the wallet.
Before signing
- Do not act on a blocked plan.
- Before any wallet signs, show the user the warnings, the recipient, the amounts and the slippage, and get their confirmation. Do not raise slippage above the default 50 bps without the user's consent.
- Never change the recipient or raise slippage to get past a refusal or a warning.
blocked,requiresConfirmationand the notices are advisory. They bind only if your application, or the signer it uses, enforces them.
Track with cleave_track_swap before sending a plan again: a plan still in flight that is sent twice can pay twice.
Server side only
Call the API from a server, bot or agent process. The Agent REST API refuses requests that carry an Origin header, as browsers send, with 403 and code forbidden_origin.
Links
Terms of use
Use of the API, the partner API and the MCP server is subject to the Terms of Use and the Privacy Policy. By sending requests or connecting a client after this notice, you accept them.
If an agent or other software calls Cleave, its operator accepts them and is responsible for what it does. Partner and agent keys are issued only after the key holder accepts them. Stay within the published rate limits.