Skip to main content

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:

  1. API Key: Go to xpander Settings โ†’ API Keys
  2. Organization ID: Found in your organization settings or browser URL
  3. 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:
  1. Create a new agent or use an existing one
  2. 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
  3. Configure tool output filtering to optimize performance
  4. Set up agent instructions and goals

Step 4: Create the Integration

Create a new Python file langchain_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
Configure this in your xpander agentโ€™s tool settings.

Step 6: Running Your Agent

Execute your agent:
You should see output similar to:

Available Tools

This example includes powerful pre-configured tools:

Customization Options

Adding More Tools

  1. Go to your xpander agent configuration
  2. Browse the tool library (2000+ available tools)
  3. Add tools to your agent
  4. Theyโ€™ll automatically be available in your LangChain agent

Using Different Models

Custom Message Handling

Troubleshooting

Common Issues

Environment Variable Errors
โ†’ Ensure all required variables are set in your .env file Tool Configuration Errors
โ†’ Check your tool configuration in the xpander platform Authentication Errors
โ†’ Verify your API keys are correct and have proper permissions

Performance Tips

  1. Use Output Filtering: Configure tool output schemas to reduce token usage
  2. Set Tool Dependencies: Ensure proper execution order in xpander platform
  3. Optimize System Prompts: Keep instructions clear and concise
  4. Monitor Usage: Track API usage in both OpenAI and xpander dashboards

Whatโ€™s Next?

Now that you have a working LangChain + LangGraph integration:
  1. ๐Ÿ”ง Add More Tools: Explore xpanderโ€™s 2000+ tool library
  2. โš™๏ธ Configure Advanced Features: Set up output filtering and dependencies
  3. ๐Ÿ—๏ธ Build Complex Workflows: Create multi-step agent processes
  4. ๐Ÿ“Š Monitor Performance: Use xpanderโ€™s analytics dashboard
  5. ๐Ÿš€ 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

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 ๐Ÿš€