In this guide, let’s explore how to integrate Arcade into your LangGraph application. Follow the step-by-step instructions below. For complete working examples, see our Python and JavaScript examples.
Use the ArcadeToolManager to retrieve specific tools or entire Servers:
Python
from langchain_arcade import ArcadeToolManagermanager = ArcadeToolManager(api_key=arcade_api_key)# Fetch the "ScrapeUrl" tool from the "Firecrawl" MCP Servertools = manager.get_tools(tools=["Firecrawl.ScrapeUrl"])print(manager.tools)# Get all tools from the "Gmail" MCP Servertools = manager.get_tools(toolkits=["Gmail"])print(manager.tools)
JavaScript
Arcade offers methods to convert into Zod schemas, which is essential since LangGraph defines tools using Zod. The toZod method is particularly useful, as it simplifies this integration and makes it easier to use Arcade’s tools with LangGraph. Learn more about Arcade’s Zod integration options here.
JavaScript
import { Arcade } from "@arcadeai/arcadejs";import { executeOrAuthorizeZodTool, toZod } from "@arcadeai/arcadejs/lib";import { tool } from "@langchain/core/tools";// Initialize the Arcade clientconst arcade = new Arcade();// Get the Arcade tools, you can customize the MCP Server (e.g. "github", "notion", "gmail", etc.)const googleToolkit = await arcade.tools.list({ toolkit: "gmail", limit: 30 });const arcadeTools = toZod({ tools: googleToolkit.items, client: arcade, userId: "<YOUR_SYSTEM_USER_ID>", // Replace this with your application's user ID (e.g. email address, UUID, etc.)});// Convert Arcade tools to LangGraph toolsconst tools = arcadeTools.map(({ name, description, execute, parameters }) => tool(execute, { name, description, schema: parameters, }),);console.log(tools);
Set up the language model and memory
Create an AI model and bind your . Use MemorySaver for checkpointing:
Supply a basic config dictionary and a user query. Notice that user_id is required for tool authorization:
PythonJavaScript
Python
Python
config = { "configurable": { "thread_id": "1", "user_id": "{arcade_user_id}" }}user_input = { "messages": [ ("user", "List any new and important emails in my inbox.") ]}
JavaScript
JavaScript
const config = { configurable: { thread_id: "1", user_id: "{arcade_user_id}", }, streamMode: "values" as const,};const user_input = { messages: [ { role: "user", content: "List any new and important emails in my inbox.", }, ],};
Stream the response
Stream the assistant’s output. If the tool requires authorization, the agent will ask the user to authorize the tool.
PythonJavaScript
Python
Python
from langgraph.errors import NodeInterrupttry: for chunk in graph.stream(user_input, config, stream_mode="values"): chunk["messages"][-1].pretty_print()except NodeInterrupt as exc: print(f"\nNodeInterrupt occurred: {exc}") print("Please authorize the tool or update the request, then re-run.")