Overview
The Travel Planner is a full-featured application that demonstrates:- Multi-agent architecture with LangGraph
- Real-time map integration using Leaflet
- Google Maps API integration for place search
- Human-in-the-loop workflows for trip approvals
- Shared state management between agents and UI
- Streaming intermediate state for progress updates
- Context-aware chat suggestions
What You’ll Learn
This example teaches you how to:- Build multi-agent systems with LangGraph
- Implement agent routing and node coordination
- Set up human-in-the-loop interrupts
- Share state between agents and React UI
- Stream intermediate agent state to the frontend
- Integrate external APIs (Google Maps) into agents
- Create context-aware chat suggestions
- Build generative UI for approval workflows
Prerequisites
- Node.js 18 or higher
- Python 3.11+ with uv package manager
- npm, yarn, or pnpm
- OpenAI API Key
- Google Maps API Key
Installation
Start the Development Server
Using other package managers
Using other package managers
Open the Application
Navigate to http://localhost:3000 in your browser.
Architecture Overview
The Travel Planner uses a multi-node agent graph with specialized nodes for different tasks:Agent Nodes
- chat_node - Main conversational interface
- trips_node - Handles trip CRUD operations (requires approval)
- search_node - Searches for places using Google Maps API
- perform_trips_node - Executes approved trip changes
Key Implementation Details
1. Agent Graph Definition
File:agent/src/agent.py
- Conditional routing based on tool calls
- Human-in-the-loop via
interrupt_afteron trips_node - State persistence with MemorySaver checkpointer
- Modular design with separate nodes for each concern
2. Shared State with useAgent
File:lib/hooks/use-trips.tsx
useAgentprovides bidirectional state sync- Agent updates automatically trigger UI re-renders
- UI updates are reflected in agent state
- Type-safe state management with TypeScript
3. Human-in-the-Loop Approvals
File:lib/hooks/use-trips.tsx
components/humanInTheLoop/AddTrips.tsx
4. Streaming Search Progress
Backend - File:agent/src/search.py
lib/hooks/use-trips.tsx
5. Context-Aware Chat Suggestions
File:lib/hooks/use-trips.tsx
- “Add a restaurant to your Paris trip”
- “Find hotels near the Eiffel Tower”
- “What’s the weather like in your destination?“
6. Google Maps Integration
File:agent/src/search.py
Expected Behavior
When you run the application, you should be able to:- View the map with existing trip markers
- Chat with the AI to plan trips
- Add trips - AI suggests trips, you approve them
- Search for places - See real-time search progress
- Update trips - Modify trip details with AI assistance
- Delete trips - Remove trips with confirmation
- See suggestions - Get context-aware action suggestions
Try It Yourself
Example interactions to try:Advanced Features
LangGraph Studio
For debugging and visualizing your agent:- Install LangGraph Studio
- Load the
agent/directory - Visualize the agent graph and state transitions
- Debug tool calls and routing logic
Checkpointing
The agent uses checkpointing for state persistence:PostgresSaver.
Multi-Turn Conversations
The agent maintains conversation context across multiple turns, enabling natural follow-up questions:Troubleshooting
Agent Connection Issues
Agent Connection Issues
If you see “I’m having trouble connecting to my tools”:
- Make sure the LangGraph agent is running on port 8000
- Check that your OpenAI API key is set correctly
- Verify both frontend and agent servers started successfully
- Check the console for any Python errors
Google Maps Not Working
Google Maps Not Working
Verify:
- Your Google Maps API key is valid
- The Places API is enabled in Google Cloud Console
- The API key has the correct restrictions/permissions
- The key is properly set in the
.envfile
Human-in-the-Loop Not Showing
Human-in-the-Loop Not Showing
Check:
- The agent graph is compiled with
interrupt_after=["trips_node"] - The
renderfunction is used inuseHumanInTheLoop - The action names match between agent and frontend
- The approval components are properly imported
State Not Syncing
State Not Syncing
Ensure:
useAgentis properly initialized with the agent ID- The agent name matches in both frontend and backend
- State types are consistent between TypeScript and Python
- The CopilotKit provider wraps the application
Next Steps
Human-in-the-Loop
Deep dive into approval workflows
Shared State
Learn more about state management patterns
LangGraph Guide
Complete guide to building LangGraph agents
useAgent
Reference documentation for useAgent
