LangChain + LangGraph Integration with xpander.ai
This guide demonstrates how to integrate LangChain and LangGraph with xpander.ai to create powerful ReAct agents with access to over 2000 pre-built tools and services.🚀 Quick Start Template: Import this template directly into xpander.ai
📓 Prefer Jupyter Notebook? You can also follow along with our interactive notebook: LangChain + xpander.ai Example Notebook - it contains all the code and explanations in a single executable file.
What You’ll Build
By the end of this tutorial, you’ll have a LangChain ReAct agent that can:- 🔍 Search the web using Tavily Search with advanced filtering
- 📧 Send emails with rich formatting and attachments
- 🧠 Use intelligent reasoning through LangGraph’s ReAct pattern
- 🎯 Follow custom instructions from your xpander agent configuration
- ⚡ Optimize token usage with xpander’s output schema filtering
Prerequisites
Before starting, make sure you have:- xpander.ai account: Sign up here
- Python 3.8 or higher
- OpenAI API key
- Basic knowledge of Python and LangChain
Step 1: Installation
First, install the required dependencies:Step 2: Environment Setup
Create a.env
file in your project directory:
Where to find your xpander credentials:
- API Key: Go to xpander Settings → API Keys
- Organization ID: Found in your organization settings or browser URL
- Agent ID: Create or select an agent in the xpander platform
Make sure to add
.env
to your .gitignore
file to avoid committing sensitive credentials.Step 3: Set Up Your xpander Agent
In the xpander.ai platform:- Create a new agent or use an existing one
- Add tools to your agent:
- Tavily Search - for web search capabilities
- Send Email - for email functionality
- Any other tools you need from the 2000+ available
- Configure tool output filtering to optimize performance
- Set up agent instructions and goals
Step 4: Create the Integration
Create a new Python filelangchain_xpander_agent.py
:
Step 5: Advanced Features
Custom Agent Instructions
You can enhance your agent by adding custom instructions in the xpander platform:Multi-Tool Workflows
Your agent can chain multiple tools together:Output Schema Filtering
xpander’s advanced output schema filtering helps you:- Reduce token usage by removing unnecessary data
- Remove PII and sensitive information
- Focus AI attention on relevant response parts
- Prevent data exposure of irrelevant fields
Step 6: Running Your Agent
Execute your agent:Available Tools
This example includes powerful pre-configured tools:Tool | Description | Key Features |
---|---|---|
🔍 Tavily Search | Advanced web search | Configurable search depth, Result filtering, Answer generation, Topic-specific search |
📧 Send Email | Email capabilities | Rich text support, Attachment handling, Template support |
Customization Options
Adding More Tools
- Go to your xpander agent configuration
- Browse the tool library (2000+ available tools)
- Add tools to your agent
- They’ll automatically be available in your LangChain agent
Using Different Models
Custom Message Handling
Troubleshooting
Common Issues
Environment Variable Errors.env
file
Tool Configuration Errors
Performance Tips
- Use Output Filtering: Configure tool output schemas to reduce token usage
- Set Tool Dependencies: Ensure proper execution order in xpander platform
- Optimize System Prompts: Keep instructions clear and concise
- Monitor Usage: Track API usage in both OpenAI and xpander dashboards
What’s Next?
Now that you have a working LangChain + LangGraph integration:- 🔧 Add More Tools: Explore xpander’s 2000+ tool library
- ⚙️ Configure Advanced Features: Set up output filtering and dependencies
- 🏗️ Build Complex Workflows: Create multi-step agent processes
- 📊 Monitor Performance: Use xpander’s analytics dashboard
- 🚀 Deploy to Production: Use xpander’s cloud infrastructure
Additional Resources
- 📚 Documentation: docs.xpander.ai
- 💬 Discord Community: Join our Discord
- 🐛 GitHub Issues: Report bugs and request features
- ✉️ Support: Contact support through the xpander platform
Related Examples
Custom Tools Integration
Create and integrate custom tools with your AI agent
Smart Support Agent
Build an intelligent documentation support agent
Ready to build production-grade AI agents with LangChain and xpander? Start building today 🚀