Agent frameworks (Vercel AI SDK, LangChain, OpenAI, ElizaOS, AgentKit, GOAT)
Add LayerHop swaps, quotes, deposit addresses and checkout to agents built with the Vercel AI SDK, LangChain, OpenAI, ElizaOS, Coinbase AgentKit or GOAT. The tools hold no keys and only hand unsigned transactions to your own signer.
LayerHop ships first-class tool packages for the agent frameworks crypto developers use. Every package wraps the same tool core (@layerhop/ai, built on @layerhop/sdk), so validation, wording and safety rules match the MCP server. LayerHop never holds keys: tools return quotes and unsigned transactions, and only a wallet you control signs.
| Framework | Package | Import |
|---|---|---|
| Vercel AI SDK (v6, v7) | @layerhop/ai |
createVercelTools from @layerhop/ai/vercel |
LangChain JS / LangGraph (@langchain/core 1.x) |
@layerhop/ai |
createLangChainTools from @layerhop/ai/langchain |
| OpenAI function calling (Chat Completions, Responses) | @layerhop/ai |
createOpenAITools from @layerhop/ai/openai |
OpenAI Agents SDK (@openai/agents) |
@layerhop/ai |
createOpenAIAgentsTools from @layerhop/ai/openai-agents |
| ElizaOS 1.x | @layerhop/plugin-elizaos |
layerhopPlugin |
| Coinbase AgentKit 0.10 | @layerhop/agentkit |
layerhopActionProvider |
| GOAT SDK 0.5 | @layerhop/goat |
layerhop |
| Anything else | @layerhop/ai |
createLayerHopTools (name, description, zod schema, run) |
The framework libraries are optional peer dependencies: install only the one you use.
Which tools do agents get?#
| Tool | What it does |
|---|---|
list_chains |
Every chain LayerHop routes, with slug, id and VM. |
list_tokens |
Built-in tokens on a chain, or a search by symbol, name or address (query). |
get_prices |
USD prices for up to 25 tokens. |
get_quote |
Best price across every provider, with human amounts, minimum received, every fee, ETA and a swap link. |
build_transaction |
The unsigned transaction for a quote, plus transactionRequests: the ordered list (ERC-20 approval, swap, extra calls) to hand to your signer. |
simulate_transaction |
Dry-run a quote's transaction without sending anything. |
report_submitted |
Tell LayerHop the tx hash after your wallet broadcast it, so the order is tracked and webhooks fire. |
get_order_status |
Pending, filled, refunded or failed. |
get_swap_link |
A layerhop.com link the user opens to review and sign in their own wallet. |
create_deposit_address, get_deposit_address |
Deposit addresses (API key required). |
create_checkout_session |
A hosted checkout link to get paid in USDC or USDT (API key required). |
Amounts in tool inputs are human decimals ("100" = 100 USDC). Every tool validates its input with zod and returns errors as text the model can act on, for example a missing recipient on an EVM to Solana swap. AGENT_INSTRUCTIONS (exported by every adapter) is a ready-made system prompt with the safe workflow.
How do I earn partner fees from my agent?#
Pass integrator (your partner id) and optionally integratorFeeBps to any package. Every quote carries them on the api fee channel, so your agent's swaps earn your partner fee on top of LayerHop's. integratorFeeBps is honored with your partner API key, within your maximum. The same options are read from the LAYERHOP_INTEGRATOR and LAYERHOP_INTEGRATOR_FEE_BPS settings in ElizaOS.
Vercel AI SDK#
import { generateText, stepCountIs } from "ai";
import { createVercelTools, AGENT_INSTRUCTIONS } from "@layerhop/ai/vercel";
const { text } = await generateText({
model: "openai/gpt-5",
system: AGENT_INSTRUCTIONS,
tools: createVercelTools({ integrator: "myapp", apiKey: process.env.LAYERHOP_API_KEY }),
stopWhen: stepCountIs(5),
prompt: "Quote 100 USDC on Base to SOL. Sender 0xd8dA…6045, recipient 9WzD…AWWM.",
});LangChain#
import { createLangChainTools } from "@layerhop/ai/langchain";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
const agent = createReactAgent({ llm, tools: createLangChainTools({ integrator: "myapp" }) });OpenAI#
Plain function calling works with the openai package or any OpenAI-compatible API:
import OpenAI from "openai";
import { createOpenAITools } from "@layerhop/ai/openai";
const layerhop = createOpenAITools({ integrator: "myapp" });
const res = await new OpenAI().chat.completions.create({ model: "gpt-5", messages, tools: layerhop.chatCompletionsTools });
for (const call of res.choices[0].message.tool_calls ?? []) {
messages.push({ role: "tool", tool_call_id: call.id, content: await layerhop.handleToolCall(call.function.name, call.function.arguments) });
}With the OpenAI Agents SDK:
import { Agent, run } from "@openai/agents";
import { createOpenAIAgentsTools, AGENT_INSTRUCTIONS } from "@layerhop/ai/openai-agents";
const agent = new Agent({ name: "Swapper", instructions: AGENT_INSTRUCTIONS, tools: createOpenAIAgentsTools({ integrator: "myapp" }) });
const result = await run(agent, "What's the best route for 1 ETH on Arbitrum to USDC on Solana?");ElizaOS#
import { layerhopPlugin } from "@layerhop/plugin-elizaos";
export const character = { name: "Hopper", plugins: ["@layerhop/plugin-elizaos"] };
// or, in code: new AgentRuntime({ character, plugins: [layerhopPlugin] })Actions: LAYERHOP_GET_QUOTE, LAYERHOP_PREPARE_SWAP, LAYERHOP_CONFIRM_SWAP, LAYERHOP_CANCEL_SWAP, LAYERHOP_ORDER_STATUS, LAYERHOP_GET_PRICES, LAYERHOP_CREATE_DEPOSIT_ADDRESS, LAYERHOP_CREATE_CHECKOUT, plus the LAYERHOP provider (safety rules and the pending swap). Settings: LAYERHOP_API_KEY, LAYERHOP_INTEGRATOR, LAYERHOP_INTEGRATOR_FEE_BPS, LAYERHOP_SIGNER_SERVICE, LAYERHOP_API_URL.
Without LAYERHOP_SIGNER_SERVICE the agent never signs: it answers with the swap link or the unsigned transaction. When it names a runtime service that implements LayerHopSignerService (your wallet plugin), LAYERHOP_PREPARE_SWAP stores the prepared swap and asks the user to reply "confirm". Only LAYERHOP_CONFIRM_SWAP, triggered by that user's explicit confirmation, hands the unsigned transactions to the service. A confirmation is single-use and expires after five minutes.
Coinbase AgentKit#
import { AgentKit, CdpEvmWalletProvider } from "@coinbase/agentkit";
import { layerhopActionProvider } from "@layerhop/agentkit";
const agentkit = await AgentKit.from({
walletProvider: await CdpEvmWalletProvider.configureWithWallet({ networkId: "base-mainnet" }),
actionProviders: [layerhopActionProvider({ integrator: "myapp" })],
});The provider adds the tools above as layerhop_* actions plus layerhop_execute_swap. In AgentKit's model the wallet provider signs with your own wallet (a CDP wallet or your key), so layerhop_execute_swap builds the confirmed quote, sends the ERC-20 approval only when the allowance is short, waits for it, sends the swap with walletProvider.sendTransaction, and reports the hash. Solana wallet providers sign the serialized transaction. LayerHop never sees keys. The action refuses unless userConfirmed is true, the quote was made for the wallet's own address, it has not expired and the wallet is on the right chain. Pass enableSwapExecution: false for a quote-only agent.
GOAT SDK#
import { getOnChainTools } from "@goat-sdk/adapter-vercel-ai";
import { viem } from "@goat-sdk/wallet-viem";
import { layerhop } from "@layerhop/goat";
const tools = await getOnChainTools({ wallet: viem(walletClient), plugins: [layerhop({ integrator: "myapp" })] });Same tools as layerhop_*, plus layerhop_execute_swap for EVM wallet clients, with the same guards as AgentKit. Swaps are signed by the GOAT wallet client you configured.
How do agents stay safe?#
- No keys. No package asks for, stores or accepts a private key or seed phrase. Signing happens only in the wallet you pass in (AgentKit wallet provider, GOAT wallet client, ElizaOS signing service) or in the user's own wallet through the swap link.
- Explicit confirmation. Tool descriptions tell the model to show the output, minimum, every fee and the ETA and to get explicit confirmation. Execution tools require
userConfirmed: true; the ElizaOS plugin requires a separate "confirm" message from the same user. - Test mode is safe. With an
lh_test_key, built transactions are placeholders: execution tools refuse to send them. See Test mode. - Tracked. After sending, the hash is reported so the order shows up in your dashboard and triggers webhooks.
Can I use the tools without a framework?#
Yes. createLayerHopTools(options) from @layerhop/ai returns plain definitions: name, description, a zod schema, execute(input) and a never-throwing run(input). toJsonSchema(tool) gives the JSON Schema for any host that wants one, and zodV3Schemas() the same schemas for toolkits still on zod v3. For an MCP client, use the MCP server instead.
Last updated