A progressive workshop showcasing LangChain v1 capabilities, building from a simple agent to a sophisticated multi-agent system with memory, middleware, and MCP integration.
This workshop consists of 12 progressive steps, each building upon the previous:
- agent_01_basic.py - Basic calendar agent with tools
- agent_02_memory.py - Adds conversational memory with MemorySaver
- Step 2.1 (Optional): LangSmith Thread View - Visualize and debug agent execution
- agent_03_human_in_loop_interrupt.py - Human-in-the-loop with interrupt pattern
- Step 3.1 (Optional): LangSmith Studio - Visual testing and iteration
- agent_04_middleware_tool_confirmation.py - Prebuilt middleware for tool confirmation
- agent_05_structured_output_mcp.py - Structured output with MCP integration
- agent_06_supervisor_multi_agent.py - Supervisor pattern with sub-agents as tools
- agent_07_guardrail_middleware.py - Custom middleware for security guardrails
- agent_08_image_handling.py - Image analysis with custom middleware
- agent_09_long_term_memory.py - Long-term memory with Store
- agent_10_intro_deep_agents.py - Introduction to Deep Agents with built-in capabilities
- agent_11_deep_agents_subagents.py - Adding specialized subagents to deep agents
- agent_12_deep_agents_middleware.py - Custom middleware with deep agents
- Python 3.10+
- uv package manager
- Install dependencies using uv:
uv sync- Create a
.envfile (copy from.env.example):
cp .env.example .env- Add your API keys to
.env:
OPENAI_API_KEY=your_openai_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here
TAVILY_API_KEY=your_tavily_api_key_here
LANGSMITH_API_KEY=your_langsmith_api_key_here # Optional: for LangSmith Thread View
Note: For LangSmith Thread View (Step 2.1) and LangSmith Studio (Step 3.1), you'll need to:
- Sign up at smith.langchain.com
- Create an API key in Settings → API Keys
- Add
LANGSMITH_API_KEYto your.envfile
Each agent script can be run independently:
# Run with uv
uv run python agents/agent_01_basic.py
uv run python agents/agent_02_memory.py
# ... etcOr activate the virtual environment and run directly:
source .venv/bin/activate # On macOS/Linux
python agents/agent_01_basic.pyFor interactive testing and debugging:
- Ensure
langgraph.jsonexists in the project root - Sign up to LangSmith if you haven't already
- Run:
uv run langgraph dev - Open the Studio interface in your browser
- Select an agent from the dropdown and test it interactively
See Step 3.1 in the notebook for details.
All agents use a centralized model configuration in agents/models.py. By default, agents use gpt-4o-mini, but you can switch to other models (Anthropic Claude, GPT OSS 120B) by editing agents/models.py.
- Simple calendar agent with
read_calendarandwrite_calendartools - Demonstrates the basic
create_agentpattern - No memory - each invocation is independent
- Adds
MemorySaverfor conversational memory - Introduces
thread_idfor conversation continuity - Agent can now remember previous interactions
- Adds
ask_for_helptool usinginterrupt - Agent can pause execution and wait for user input
- Useful for conflict resolution
- Adds
reschedule_calendartool - Uses
HumanInTheLoopMiddlewarefor tool confirmation - Demonstrates prebuilt middleware
- Web search agent using Tavily MCP server
- Returns structured output (EventList with List[EventInfo])
- Demonstrates real MCP integration and
ToolStrategy - Requires TAVILY_API_KEY in .env
- Supervisor agent that uses sub-agents as tools
- Calendar agent and web search agent as sub-agents
- Demonstrates multi-agent coordination
- Advanced: Shows how to surface subagent interrupts to supervisor level using custom middleware
- See docs/subagent_interrupt_surfacing.md for detailed explanation
- Custom middleware for security
- Analyzes user queries before agent execution
- Blocks malicious or irrelevant requests
- Custom middleware for image analysis
- Extends state schema to accept images
- Demonstrates content blocks in LangChain v1
- Adds
Storefor long-term memory - User data persists across conversations/threads
- Distinguishes short-term (checkpointer) vs long-term (store) memory
- Introduces
create_deep_agentfrom thedeepagentspackage - Built-in capabilities: planning (write_todos), file system tools, subagents
- Automatic context management with file eviction and summarization
- Shows the difference between regular agents and deep agents
- Demonstrates built-in subagent capabilities
- Define specialized subagents with custom tools and prompts
- Use the
tasktool for delegation and context isolation - Compare with manual supervisor pattern (agent_06)
- Shows how to add custom middleware to deep agents
- Deep agents come with TodoListMiddleware, FilesystemMiddleware, and SubAgentMiddleware
- Add HumanInTheLoopMiddleware via
interrupt_onparameter - Integrate custom middleware like SecurityGuardrailMiddleware
The langgraph.json file is configured for deployment to LangSmith. The final agent (agent_09_long_term_memory.py) is set as the main graph.
To deploy:
- Push to GitHub
- Link repository in LangSmith
- Select deployment type (dev/prod)
- Agent will be deployed with Redis and Postgres instances
- Agents: Basic agent creation with
create_agent - Tools: Creating and using tools with
@tooldecorator - Memory: Short-term (checkpointer) and long-term (store) memory
- Human-in-the-Loop: Interrupts and middleware for user interaction
- Middleware: Prebuilt and custom middleware for agent behavior modification
- MCP: Model Context Protocol integration for external tools
- Structured Output: Returning structured data instead of plain text
- Multi-Agent: Supervisor pattern with sub-agents as tools
- Security: Guardrails and request filtering
- Content Blocks: Image handling and analysis
- Deep Agents: Agent harness with built-in planning, file system, and subagents
- Planning: Automatic task decomposition with
write_todostool - File System: Built-in tools for context management (ls, read_file, write_file, edit_file)
- Subagents: Built-in task delegation with specialized subagents
- Context Management: Automatic eviction of large tool results and conversation summarization
- Backends: Pluggable storage (StateBackend, FilesystemBackend, StoreBackend, CompositeBackend)
- Middleware Composition: Combining built-in and custom middleware
When building supervisor-subagent architectures, you may want subagents to interrupt for user input (approval, clarification, etc.). The challenge is surfacing these interrupts to the supervisor level.
Solution: Use custom middleware that detects subagent interrupts and propagates them to the supervisor.
See:
- docs/subagent_interrupt_surfacing.md - Detailed explanation
- examples/subagent_interrupt_surfacing.py - Standalone example
- agents/agent_06_supervisor_multi_agent.py - Implementation in workshop
- All agents use mock calendar storage for demonstration
- Agent 05+ require TAVILY_API_KEY for MCP web search integration
- Image handling (agent 08) requires vision-capable models
- Long-term memory (agent 09) uses InMemoryStore (use DB-backed store in production)
- Deep agents (agent 10-12) require the
deepagentspackage (already in pyproject.toml)
When to use Deep Agents:
- Complex, multi-step tasks requiring planning
- Large context management needs
- Tasks benefiting from subagent delegation
- Long-running research or analysis tasks
When to use Regular Agents:
- Simple, single-purpose agents
- Direct tool-calling patterns
- Fine-grained control over execution
- Lightweight applications
Deep agents build on top of LangGraph and include middleware for planning, file systems, and subagents out of the box. Regular agents (create_agent) provide the basic agent loop and require manual setup for advanced features.