A collection of practical examples demonstrating various agentic AI patterns and techniques using LangChain, LangGraph, and related technologies.
- Install uv:
pip install uv- Create and activate a virtual environment:
uv venv
source .venv/bin/activate # On Unix/macOS
# or
.venv\Scripts\activate # On Windows- Install dependencies:
uv sync- Environment Configuration
- Copy
.env.exampleto.envand add your API keys:OPENAI_API_KEY- OpenAI API key for OpenAI modelsANTHROPIC_API_KEY- Anthropic API key for Claude modelsTAVILY_API_KEY- Tavily API key for search functionalityGEMINI_API_KEY- Gemini API key for text extraction featuresVECTOR_STORE_TYPE- Set to 'pgvector', 'chroma', or 'qdrant'OPENAI_MODEL- OpenAI model selection (defaults to gpt-4o-mini)TOKENIZERS_PARALLELISM=False- Tokenizer configuration
- Copy
Project configuration is managed in pyproject.toml. This includes:
- Project metadata (name, version, authors)
- Python version requirements
- All project dependencies with their versions
- LangChain Ecosystem: Core orchestration, LangGraph workflows, supervisor patterns
- Vector Stores: PGVector, Chroma, Qdrant, LanceDB, SQLite-vec
- Validation: Guardrails for input/output validation
- Document Processing: Langextract for text extraction
- Multi-provider LLM: LiteLLM for unified API access
- Search: Tantivy search engine
- Evaluation: DeepEval for testing metrics
# Add the dependency to pyproject.toml under [project.dependencies], then run:
uv syncuv sync --upgradeSupervisor pattern with specialized agents (math/research experts) using LangGraph
Semantic search over tool descriptions with runtime tool binding
- Scratchpad (
examples/context/offloading.py): Persistent note-taking - Compression (
examples/context/compact.py): Output summarization - Pruning (
examples/context/pruning.py): Selective context retention
Converts Python functions to LangChain tools with semantic discovery
- Weather Server (
examples/mcp/weather_server.py): NWS API integration - Math Server (
examples/mcp/math_server.py): Arithmetic operations
Unified interface for PGVector and Chroma vector stores
Text and image embeddings with Qdrant for retrieval-augmented generation
Processes and stores documents with both text and image components
LangGraph conversational agents with JSON-RPC communication
Semantic search for storing and retrieving personal user memories
Advanced retrieval with semantic similarity, importance scores, and temporal decay
LLM-rated importance scoring with timestamped memory storage
Team-wide knowledge sharing with personal and shared memory stores
ReAct pattern implementation with tool routing and reasoning capabilities
Multi-provider LLM support using LiteLLM for unified API access
- PDF to Images (
examples/document/pdf2images.py): PDF image extraction with OpenAI vision analysis - Text Extraction (
examples/document/text_extract.py): Text extraction using langextract library
- Cross-modal Retrieval (
examples/store/vector_retriever.py): Text-to-image and image-to-text search - Vector Consistency (
examples/store/verify_vector_consistency.py): Vector normalization verification - Blog Retriever Tool (
examples/tools/retriever_tool.py): Blog post retrieval tool
Guardrails integration for input/output validation and filtering
Multi-server MCP client integration with REACT agents
DeepEval integration for comprehensive testing metrics
- Language Models: Uses
langchain.chat_models.init_chat_model()for multiple providers (Anthropic, OpenAI, Gemini) - Tools: Dynamic tool registry system in
tools.registrywith semantic search via vector embeddings - Workflows: LangGraph StateGraph-based agents with different patterns
- Context Management: Various strategies for handling context window limitations
-
Multi-Agent Coordination (
examples/agents/multi_agents.py):- Supervisor pattern with specialized agents (math expert, research expert)
- Uses
langgraph_supervisorfor agent delegation - Clear role separation and coordination
-
ReAct Agent Pattern (
examples/agents/react_agent.py):- Reasoning and acting capabilities with tool routing
- Dynamic tool selection based on reasoning
- Integration with MCP servers for enhanced functionality
-
LLM Proxy Pattern (
examples/agents/llm_proxy.py):- Multi-provider support through LiteLLM
- Unified API access across different LLM providers
- Fallback and routing capabilities
-
Dynamic Tool Selection (
examples/context/tools_call.py):- Semantic search over tool descriptions using embeddings
- Runtime tool binding based on query relevance
- Vector store with
InMemoryStorefor tool indexing
-
Context Management Strategies:
- Scratchpad (
examples/context/offloading.py): Persistent note-taking within conversation threads - Compression (
examples/context/compact.py): Tool output summarization using separate LLM - Pruning (
examples/context/pruning.py): Selective context retention
- Scratchpad (
-
Input/Output Validation (
examples/validation/validators.py):- Guardrails integration for data validation
- Input filtering and output sanitization
- Custom validation rules and constraints
-
Document Processing Pipeline:
- PDF Processing (
examples/document/pdf2images.py): Extract images from PDFs and analyze with vision models - Text Extraction (
examples/document/text_extract.py): Extract structured text using langextract - Multimodal Analysis: Combine text and image processing capabilities
- PDF Processing (
-
Cross-modal Retrieval (
examples/store/vector_retriever.py):- Text-to-image and image-to-text search capabilities
- Unified embedding space for multimodal content
- Advanced similarity matching across modalities
-
Qdrant-based Memory Agents:
- Intelligent Memory Agent (
examples/agents/intelligent_memory_agent.py): Hybrid memory system with automatic importance scoring and timestamping - Shared Memory Agents (
examples/agents/shared_memory_agents.py): Multi-agent system with personal and team-wide memory sharing - Weighted Search: Advanced retrieval considering semantic similarity, importance scores, and temporal decay
- Intelligent Memory Agent (
The examples/tools/registry.py module provides:
- Automatic conversion of Python math functions to LangChain tools
- UUID-based tool registry for efficient lookup
- Vector embeddings for semantic tool discovery
init_tools()function to populate the search index
- Weather Server (
examples/mcp/weather_server.py): National Weather Service API integration with async tool definitions for weather alerts and forecasts - Math Server (
examples/mcp/math_server.py): Basic arithmetic operations exposed as MCP tools - Enhanced MCP Integration (
examples/mcp/mcp_agents.py): Multi-server client with REACT agent pattern for complex tool orchestration
- Agents (
examples/agents/a2a/agents.py): LangGraph A2A conversational agent supporting messages input for conversational interactions - Agent Communication (
examples/agents/a2a_agents.py): Example implementation for communication between A2A agents using JSON-RPC protocol
- Semantic Search: Enables agents to store and retrieve personal user memories and information (
examples/context/ltm.py) - Memory Storage: Uses InMemoryStore with embedding-based indexing for similarity search
- Qdrant-based Storage: Advanced memory storage using Qdrant vector database with importance scoring and timestamping
- Hybrid Memory: Combination of short-term memory (in-memory) and long-term memory (persistent Qdrant storage)
- Shared Memory: Team-wide memory sharing between agents with personal and shared memory stores
- Context Injection: Automatically retrieves relevant memories to enhance responses
- DeepEval Integration (
examples/evals/test_deepeval.py): Comprehensive testing metrics and evaluation - Performance Metrics: Automated evaluation of agent responses
- Quality Assurance: Systematic testing of agent capabilities
The project follows Python best practices with an examples layout:
examples/
├── agents/ # Multi-agent coordination implementations
│ ├── intelligent_memory_agent.py # Intelligent memory agent with Qdrant
│ ├── shared_memory_agents.py # Shared memory agents with team/personal stores
│ ├── react_agent.py # ReAct pattern implementation
│ └── llm_proxy.py # Multi-provider LLM proxy
├── context/ # Context management strategies
├── document/ # Document processing pipeline
│ ├── pdf2images.py # PDF image extraction with vision analysis
│ └── text_extract.py # Text extraction using langextract
├── mcp/ # Model Context Protocol servers
│ ├── weather_server.py # NWS API integration
│ ├── math_server.py # Arithmetic operations
│ └── mcp_agents.py # Multi-server MCP client
├── rag/ # Retrieval-Augmented Generation implementations
├── store/ # Embedding store implementations
│ ├── embedding_store.py # PGVector and Chroma store abstraction
│ ├── multimodal_store.py # Multimodal store with Qdrant for text and image embeddings
│ ├── qdrant_store_adapter.py # Qdrant store adapter with weighted search
│ ├── vector_retriever.py # Cross-modal retrieval capabilities
│ └── verify_vector_consistency.py # Vector normalization verification
├── tools/ # Tool implementations
│ ├── registry.py # Dynamic tool registry
│ └── retriever_tool.py # Blog post retriever
├── evals/ # Evaluation implementations
│ └── test_deepeval.py # DeepEval integration
├── validation/ # Input/output validation
│ ├── validators.py # Guardrails integration
│ ├── inputs.py # Input validation utilities
│ └── outputs.py # Output validation utilities
├── ltm/ # Long-term memory implementations
│ └── ltm.py # Long-term memories with semantic search
├── http/ # HTTP utilities
│ └── responses.py # Response formatting utilities
└── a2a/ # A2A protocol implementation
└── agents.py # A2A conversational agents