Skip to content

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.

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 list
const tools = new AgentkitToolkit(agentkit).getTools();

getTools() returns an array of DynamicStructuredTool[] — LangChain’s native class for function tools. Each tool contains:

  1. name: E.g., smart_transfer, pay_api, search_tools.
  2. description: A detailed instructional string telling the LLM exactly when to use this tool and what the formatting constraints are.
  3. schema: A Zod schema defining the expected arguments.
  4. func: The executable callback that runs the underlying Agentkit action with the configured wallet/policy context.

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 actions
const readOnlyTools = allTools.filter((tool) =>
["get_balance", "get_address", "get_agent_wallet", "get_spend_status"].includes(tool.name)
);
// Now inject readOnlyTools into your LangGraph agent

Every 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.

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
});