This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a comprehensive tutorial for building AI agents from scratch using LangChain and LangGraph. The project progressively teaches agent development concepts through practical examples, culminating in a production-ready email assistant with Gmail integration.
- Install dependencies:
pip install -r requirements.txt - The project uses Python 3.12 as specified in
langgraph.json
- Start local development server:
langgraph dev- Default URL: http://127.0.0.1:2024
- Available graphs defined in
langgraph.json:email_assistant- Basic email assistantemail_assistant_hitl- With human-in-the-loop capabilityemail_assistant_hitl_memory- With memory systememail_assistant_hitl_memory_gmail- Full Gmail integration
- Run tests:
pytest - Run tests for specific agent:
pytest --agent-module=email_assistant_hitl_memory - Test configuration is in
tests/conftest.py
- Set up Gmail credentials:
python src/tools/gmail/setup_gmail.py - Run email ingestion:
python src/tools/gmail/run_ingest.py --email your@email.com --minutes-since 1000 - Set up automated cron job:
python src/tools/gmail/setup_cron.py --email your@email.com --url https://your-deployment-url
All agents follow a consistent StateGraph pattern with these key components:
- Triage Router (
triage_router): Classifies emails as ignore/notify/respond - Response Agent (
response_agent): Handles actual email processing and tool calls - State Management: Uses LangGraph's MessagesState with custom email and classification fields
- Basic Agent (
src/email_assistant.py): Simple tool-calling agent - HITL Agent (
src/email_assistant_hitl.py): Adds human interruption capability - Memory Agent (
src/email_assistant_hitl_memory.py): Includes user preference learning - Gmail Agent (
src/email_assistant_hitl_memory_gmail.py): Full Gmail API integration
State: Core state with messages, email input, and classification decisionRouterSchema: Structured output for email triage decisionsEmailData: Gmail message structureUserPreferences: Memory system for learning user preferences
- Base Tools (
src/tools/base.py): Tool loading and management utilities - Default Tools (
src/tools/default/): Mock email and calendar tools for development - Gmail Tools (
src/tools/gmail/): Production Gmail and Google Calendar APIs - Tools are dynamically loaded based on
include_gmailparameter
- Modular prompt templates with placeholders for customization
- Separate prompts for triage, basic agent, HITL, and memory variants
- Default configurations for background, preferences, and triage rules
- Memory update instructions for preference learning
- Email dataset generation and management
- Automated triage evaluation with comparison metrics
- Results visualization and analysis tools
OPENAI_API_KEY: OpenAI API accessMODEL_PROVIDER: Set to "openai"OPENAI_MODEL: Model name (e.g., "gpt-4")LANGCHAIN_API_KEY: For LangSmith tracking (optional)LANGCHAIN_PROJECT: Project name for LangSmith (optional)
- Create
.secretsdirectory insrc/tools/gmail/ - Place Google OAuth credentials as
secrets.json - Run setup script to generate
token.json - For hosted deployments, set
GMAIL_SECRETandGMAIL_TOKENenvironment variables
All agents use this consistent node structure:
llm_call: LLM makes tool decisionstool_node/environment: Executes selected toolsshould_continue: Routes between tool execution and completion
- Tools are loaded via
get_tools()function with optional Gmail inclusion - Tools use consistent schema with
name,description, andargs_schema - Tool execution results are formatted as messages in conversation history
- Interrupts occur before tool execution via
interrupt="before" - Agent Inbox integration for reviewing and editing responses
- Memory system learns from user feedback and edits
- User preferences stored per namespace (email address)
- Selective updates preserve existing information
- Integration with conversation history for context-aware responses
- Use
langgraph devfor local testing with hot reload - Agent Inbox available at https://dev.agentinbox.ai/ for HITL workflows
- Deploy via LangSmith deployments page
- Connect to GitHub repository
- Set required environment variables
- Support for scheduled cron jobs via LangGraph SDK
- Search: Gmail API search with time/read status filters
- Thread Retrieval: Fetch complete conversation threads
- Processing: Apply sender and thread-position filters
- Agent Invocation: Send to appropriate LangGraph endpoint
--include-read: Process read messages (default: unread only)--skip-filters: Process all messages including self-sent--minutes-since: Time window for email retrieval--rerun: Reprocess already-handled emails
Each chapter (01-07) contains:
README.md: Theoretical concepts and explanationsnotebook.ipynb: Hands-on code examples- Supporting images in
img/directories - Complete working code examples where applicable
The progression builds from basic agent concepts to production-ready Gmail integration with memory and human oversight capabilities.