Langchain Integration
If you are building an AI agent using LangChain or LangGraph, you don’t need to manually map JSON tool calls to Agentkit actions. We provide a single helper function to construct a list of LangChain-compatible DynamicStructuredTool objects.
getLangChainTools
Section titled “getLangChainTools”The @0xgasless/agent-sdk/langchain module exports getLangChainTools().
import { AgentKit } from "@0xgasless/agent-sdk";import { getLangChainTools } from "@0xgasless/agent-sdk/langchain";
// 1. Initialize AgentKit with the user's keysconst agentKit = new AgentKit({ apiKey: "YOUR_API_KEY",});
// 2. Generate the tools listconst tools = getLangChainTools(agentKit);What does this return?
Section titled “What does this return?”getLangChainTools returns an array of DynamicStructuredTool[]. This is LangChain’s native class for representing function tools.
Each tool contains:
- name: E.g.,
smart_transfer - description: A detailed instructional string telling the LLM exactly when to use this tool, and what the formatting constraints are. (e.g., “Use this tool to transfer ERC20 tokens or Native Assets…”).
- schema: A Zod schema defining the expected arguments.
- func: The executable callback that runs the specific
AgentKitaction (e.g., executingSmartTransferAction.invoke).
Filtering tools
Section titled “Filtering tools”By default, getLangChainTools returns every action available in Agentkit. Sometimes you want an agent to be restricted — for example, a “Balance Bot” that can only read balances but cannot transfer funds.
You can restrict the generated tools array using standard JavaScript array filtering.
import { GetBalanceAction, GetAddressAction } from "@0xgasless/agent-sdk";
const allTools = getLangChainTools(agentKit);
// Keep only read-only actionsconst readOnlyTools = allTools.filter(tool => { return ( tool.name === GetBalanceAction.name || tool.name === GetAddressAction.name );});
// Now inject readOnlyTools into your LangGraph agentEvery action in Agentkit exports a static .name property, which corresponds directly to the LangChain tool name string emitted by getLangChainTools.
Using tools with LangGraph
Section titled “Using tools with LangGraph”Once you have the tools array, inject it into the createReactAgent constructor (or any standard LangChain bind):
import { ChatOpenAI } from "@langchain/openai";import { createReactAgent } from "@langchain/langgraph/prebuilt";
const model = new ChatOpenAI({ modelName: "gpt-4o",});
const agent = createReactAgent({ llm: model, tools: tools, // Array of LangChain tools injected});