Use LangGraph with Arcade
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.
Prerequisites
Set up your environment
Install the required packages, and ensure your environment variables are set with your Arcade and OpenAI :
Python
pip install langchain-arcade langchain-openai langgraph
Configure API keys
Provide your Arcade and OpenAI . You can store them in environment variables or directly in your code:
Need an Arcade ? Visit the Get an API key page to create one.
Python
import os
arcade_api_key = os.environ.get("ARCADE_API_KEY", "YOUR_ARCADE_API_KEY")
openai_api_key = os.environ.get("OPENAI_API_KEY", "YOUR_OPENAI_API_KEY")
Create and manage Arcade tools
Python
Use the ArcadeToolManager to retrieve specific tools or entire Servers:
from langchain_arcade import ArcadeToolManager
manager = ArcadeToolManager(api_key=arcade_api_key)
# Fetch the "ScrapeUrl" tool from the "Firecrawl" MCP Server
tools = manager.get_tools(tools=["Firecrawl.ScrapeUrl"])
print(manager.tools)
# Get all tools from the "Gmail" MCP Server
tools = manager.get_tools(toolkits=["Gmail"])
print(manager.tools)
Set up the language model and memory
Create an AI model and bind your . Use MemorySaver for checkpointing:
Python
from langchain_openai import ChatOpenAI
from langgraph.checkpoint.memory import MemorySaver
model = ChatOpenAI(model="gpt-4o", api_key=openai_api_key)
bound_model = model.bind_tools(tools)
memory = MemorySaver()
Create a ReAct-style agent
Use the prebuilt ReAct from LangGraph to handle your Arcade :
Python
from langgraph.prebuilt import create_react_agent
graph = create_react_agent(model=bound_model, tools=tools, checkpointer=memory)
Provide configuration and user query
Supply a basic config dictionary and a user query. Notice that user_id is required for authorization:
Python
config = {
"configurable": {
"thread_id": "1",
"user_id": "{arcade_user_id}"
}
}
user_input = {
"messages": [
("user", "List any new and important emails in my inbox.")
]
}
Stream the response
Stream the assistant’s output. If the tool requires authorization, the will ask the user to authorize the .
Python
from langgraph.errors import NodeInterrupt
try:
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.")
Tips for selecting tools
- Relevance: Pick only the you need. Avoid using all tools at once.
- Avoid conflicts: Be mindful of duplicate or overlapping functionality.
Next steps
Now that you have integrated Arcade tools into your LangGraph , you can:
- Experiment with different Servers, such as “Math” or “Search.”
- Customize the ’s prompts for specific tasks.
- Try out other language models and compare their performance.
Enjoy exploring Arcade and building powerful AI-enabled Python applications!