A hands-on workshop for learning LangChain fundamentals with Azure OpenAI, building AI applications, and implementing agent patterns with Large Language Models (LLMs).
This workshop includes five progressive examples:
- Azure OpenAI Integration: Direct integration with Azure OpenAI using environment variables
- Basic LLM Interactions: Simple message handling and prompt templates
- Translation Example: English to Italian and German translation using system prompts
- Interactive Chatbot: Command-line chatbot with conversation loop
- Memory Management: Persistent conversation history using MemorySaver
- Message Trimming: Token management with configurable message limits
- Streaming Responses: Real-time response streaming with visual feedback
- ReAct Agent: Reasoning and Acting agent pattern implementation
- Web Search Integration: Tavily search tool for real-time information
- Conversation Memory: Thread-based conversation tracking
- Tool Usage: Autonomous tool selection and execution
- Function Calling: Native Python functions as LLM-callable tools
- Custom Tool Creation: Convert Python functions to agent tools automatically
- Multi-Step Operations: Sequential function execution with intermediate results
- Graph Workflows: Conditional routing between assistant and tool execution
- RAG Implementation: Retrieval-Augmented Generation with web content
- Web Content Loading: Extract and process content from Azure blogs
- Vector Embeddings: Create and store document embeddings for similarity search
- Document Chunking: Split large documents into manageable pieces
- Context-Aware Answers: Generate responses based on retrieved relevant content
- Python 3.8 or higher
- Git
- Code editor (VS Code recommended)
Install required packages using pip:
pip install -r requirements.txtThe workshop uses the following key dependencies:
- langchain: Core LangChain framework
- langchain-openai: Azure OpenAI integration
- langchain-anthropic: Anthropic Claude integration (for agents)
- langchain-core: Core LangChain components
- langgraph: Graph-based agent framework
- langchain-community: Community tools including Tavily search and web loaders
- tavily-python: Web search API integration
- langgraph-checkpoint-sqlite: Persistent memory storage
- python-dotenv: Environment variable management
- beautifulsoup4: HTML parsing for web content extraction
- langchain-text-splitters: Document chunking utilities
Creating and activating a virtual environment:
Windows (PowerShell):
# Create virtual environment
python -m venv .venv
# Activate virtual environment
.\.venv\Scripts\Activate.ps1
# Install dependencies
pip install -r requirements.txtWindows (Command Prompt):
# Create virtual environment
python -m venv .venv
# Activate virtual environment
.venv\Scripts\activate.bat
# Install dependencies
pip install -r requirements.txtmacOS/Linux:
# Create virtual environment
python3 -m venv .venv
# Activate virtual environment
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txtDeactivating virtual environment:
deactivateCreate a .env file in the project root to store your API keys and configuration:
# Azure OpenAI Configuration (Required)
AZURE_OPENAI_API_KEY=your_azure_openai_api_key_here
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_OPENAI_DEPLOYMENT_NAME=your_deployment_name
AZURE_OPENAI_MODEL_NAME=gpt-4
AZURE_OPENAI_API_VERSION=2024-02-15-preview
# Azure OpenAI Embeddings (Required for RAG Example)
AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME=your_embeddings_deployment_name
# LangSmith Tracing (Optional)
LANGSMITH_TRACING=true
LANGSMITH_API_KEY=your_langsmith_api_key_here
LANGSMITH_PROJECT=langchain-workshop
# Anthropic API (Required for Agent Example)
ANTHROPIC_API_KEY=your_anthropic_api_key_here
# Tavily Search API (Required for Agent Example)
TAVILY_API_KEY=your_tavily_api_key_here- NEVER commit your
.envfile to version control - Keep your API keys local and secure
- The
.envfile should be added to.gitignore - Consider using environment-specific configurations for different stages
-
Clone the repository:
git clone https://github.com/your-username/langchain-workshop.git cd langchain-workshop -
Set up virtual environment and install dependencies:
# Windows PowerShell python -m venv .venv .\.venv\Scripts\Activate.ps1 pip install -r requirements.txt
# macOS/Linux python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt
-
Configure environment variables:
# Create .env file with your API keys (see Environment Variables section) # Ensure you have Azure OpenAI, Anthropic, and Tavily API keys
-
Run workshop examples:
# Example 1: Simple LLM with Azure OpenAI python 01_simple-LLM-application/main.py # Example 2: Interactive chatbot with memory python 02_chatbot-application/main.py # Example 3: ReAct agent with web search python 03_simple-agent-application/main.py # Example 4: Function-calling agent with custom tools python 04_native-function-agent-application/main.py # Example 5: RAG system with web content python 05_simple-rag-application/main.py
LangSmith provides powerful debugging and monitoring capabilities for LangChain applications.
- Sign up at LangSmith
- Get your API key from the settings
- Add to your
.envfile:LANGSMITH_TRACING=true LANGSMITH_API_KEY=your_langsmith_api_key LANGSMITH_PROJECT=langchain-workshop
To run all workshop examples, you'll need:
-
Azure OpenAI (Required for examples 1, 2, 4 & 5):
- Create an Azure OpenAI resource in Azure Portal
- Deploy a GPT-4 model (for chat completions)
- Deploy an embeddings model (text-embedding-ada-002 for RAG example)
- Get endpoint, API key, and deployment names
-
Anthropic Claude (Required for example 3):
- Sign up at Anthropic
- Get your API key from the console
-
Tavily Search (Required for example 3):
- Sign up at Tavily
- Get your API key for web search functionality
Focus: Basic Azure OpenAI integration and prompt templates
Features:
- Direct Azure OpenAI model invocation
- System and user message handling
- Prompt templates with variable substitution
- Translation examples (English β Italian, German)
Run: python 01_simple-LLM-application/main.py
Focus: Interactive conversational AI with memory
Features:
- Command-line chat interface
- Persistent conversation memory using MemorySaver
- Token-based message trimming for context management
- Real-time streaming responses with visual feedback
- Conversation state management
Run: python 02_chatbot-application/main.py
Usage: Type messages and get responses. Type 'exit' to quit.
Focus: ReAct (Reasoning and Acting) agent with tool usage
Features:
- Anthropic Claude model for agent reasoning
- Tavily web search tool integration
- Autonomous tool selection and execution
- Memory-persistent agent conversations
- Multi-step reasoning and web search capabilities
Run: python 03_simple-agent-application/main.py
Example queries:
- "Hi, I'm Bob and I live in SF"
- "What's the weather where I live?"
Focus: Function calling with custom Python tools
Features:
- Native Python functions converted to LLM-callable tools
- Custom tool creation with automatic schema generation
- Multi-step arithmetic operations with function chaining
- Graph-based workflow with conditional tool routing
- Sequential function execution with intermediate results
Run: python 04_native-function-agent-application/main.py
Example output: Performs multi-step calculations: "Add 3 and 4. Multiply the output by 2. Divide the output by 5"
Focus: Retrieval-Augmented Generation with web content
Features:
- Web content loading from Azure Build 2025 blog posts
- Document chunking with RecursiveCharacterTextSplitter
- Vector embeddings using Azure OpenAI Embeddings
- In-memory vector store for similarity search
- Context-aware answer generation using retrieved documents
- Graph-based RAG workflow with LangGraph
Run: python 05_simple-rag-application/main.py
Example output: Answers questions about Azure Build 2025 announcements based on web content
1. Import Errors
# Solution: Ensure virtual environment is activated and dependencies installed
pip install -r requirements.txt2. API Key Issues
- Verify your
.envfile is in the project root - Check API key format and validity (no extra spaces or quotes)
- Ensure Azure OpenAI deployment name matches your actual deployment
- Verify Azure OpenAI endpoint URL format
3. Azure OpenAI Connection Issues
# Verify your Azure OpenAI configuration
# Check deployment name, endpoint, and API version
# Ensure your resource has the correct model deployed4. Agent/Search Tool Issues
- Verify Tavily API key is valid and has remaining credits
- Check Anthropic API key if agent fails to respond
- Ensure internet connection for web search functionality
5. Virtual Environment Issues
# Windows PowerShell - if activation fails
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
.\.venv\Scripts\Activate.ps1# If virtual environment is corrupted, recreate it
rm -rf .venv # or Remove-Item .venv -Recurse -Force on Windows
python -m venv .venv
# Then activate and reinstall dependencies6. Import or Module Errors
# Ensure virtual environment is activated
# Reinstall dependencies if needed
pip install --upgrade pip
pip install -r requirements.txt --force-reinstallpython -m venv --clear langchain-env
## π Useful Resources
### Documentation
- [LangChain Documentation](https://python.langchain.com/)
- [LangChain API Reference](https://api.python.langchain.com/)
- [LangSmith Documentation](https://docs.smith.langchain.com/)
### API Providers
- [OpenAI API](https://platform.openai.com/)
- [Anthropic API](https://console.anthropic.com/)
## π€ Contributing
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request