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. The AgentkitToolkit class
constructs a list of LangChain-compatible DynamicStructuredTool objects for
you.
AgentkitToolkit
Section titled “AgentkitToolkit”import { Agentkit, AgentkitToolkit } from "@0xgasless/agentkit";
// 1. Configure Agentkit (platform mode shown; configureWithWallet also works)const agentkit = await Agentkit.configureWithPlatform({ apiKey: process.env.OXGAS_API_KEY!, agentId: "my-agent", chain: "avalanche-fuji",});
// 2. Generate the tools listconst tools = new AgentkitToolkit(agentkit).getTools();What does this return?
Section titled “What does this return?”getTools() returns an array of DynamicStructuredTool[] — LangChain’s
native class for function tools. Each tool contains:
- name: E.g.,
smart_transfer,pay_api,search_tools. - description: A detailed instructional string telling the LLM exactly when to use this tool and what the formatting constraints are.
- schema: A Zod schema defining the expected arguments.
- func: The executable callback that runs the underlying Agentkit action with the configured wallet/policy context.
Filtering tools
Section titled “Filtering tools”By default the toolkit returns every action available in the current mode. Sometimes you want an agent to be restricted — for example, a “Balance Bot” that can read balances but never move funds.
Restrict the array with standard JavaScript filtering on the tool names:
const allTools = new AgentkitToolkit(agentkit).getTools();
// Keep only read-only actionsconst readOnlyTools = allTools.filter((tool) => ["get_balance", "get_address", "get_agent_wallet", "get_spend_status"].includes(tool.name));
// Now inject readOnlyTools into your LangGraph agentEvery Agentkit action has a name property that corresponds directly to the
LangChain tool name string. Call getAllAgentkitActions() (exported from the
package) to enumerate the full set at runtime.
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({ model: "gpt-4o" });
const agent = createReactAgent({ llm: model, tools: tools, // Array of LangChain tools injected});