Skip to content

Commit 3e20cf7

Browse files
committed
chore: fix readme for subgraphs demo
1 parent d22718f commit 3e20cf7

File tree

3 files changed

+64
-152
lines changed

3 files changed

+64
-152
lines changed

typescript-sdk/apps/dojo/src/app/[integrationId]/feature/layout.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,11 @@ export default function FeatureLayout({ children, params }: Props) {
5757
}
5858
}, [children, codeFiles, readme, view])
5959

60-
return <div className="bg-white rounded-lg w-full h-full">{content}</div>;
60+
return (
61+
<div className="bg-white rounded-lg w-full h-full overflow-hidden">
62+
<div className="flex flex-col h-full overflow-auto">
63+
{content}
64+
</div>
65+
</div>
66+
);
6167
}

typescript-sdk/apps/dojo/src/app/[integrationId]/feature/subgraphs/README.mdx

Lines changed: 54 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This demo showcases **LangGraph subgraphs** through an interactive travel planni
55
## What are LangGraph Subgraphs? 🤖
66

77
**Subgraphs** are the key to building modular, scalable AI systems in LangGraph. A subgraph is essentially "a graph that is used as a node in another graph" - enabling powerful encapsulation and reusability.
8+
For more info, check out the [LangGraph docs](https://langchain-ai.github.io/langgraph/concepts/subgraphs/).
89

910
### Key Concepts
1011

@@ -15,172 +16,77 @@ This demo showcases **LangGraph subgraphs** through an interactive travel planni
1516

1617
## Demo Architecture 🗺️
1718

18-
This travel planner demonstrates both **shared state** and **specialized routing** patterns:
19+
This travel planner demonstrates **supervisor-coordinated subgraphs** with **human-in-the-loop** decision making:
1920

20-
### Parent Graph: Trip Coordinator
21-
- **Role**: Analyzes user requests and routes to appropriate travel specialists
22-
- **Intelligence**: Uses keyword analysis to determine which specialist to activate
23-
- **State Management**: Maintains the complete travel plan across all subgraphs
21+
### Parent Graph: Travel Supervisor
22+
- **Role**: Coordinates the travel planning process and routes to specialized agents
23+
- **State Management**: Maintains a shared itinerary object across all subgraphs
24+
- **Intelligence**: Determines what's needed and when each agent should be called
2425

25-
### Subgraph 1: 🚗 Transportation Specialist
26-
- **Specialization**: Flights, trains, car rentals, buses, cruises, and travel logistics
27-
- **Triggers**: "flight", "train", "car rental", "transportation", "departure", "arrival"
28-
- **Tools**: `update_transportation()` with booking tips and cost optimization
26+
### Subgraph 1: ✈️ Flights Agent
27+
- **Specialization**: Finding and booking flight options
28+
- **Process**: Presents flight options from Amsterdam to San Francisco with recommendations
29+
- **Interaction**: Uses interrupts to let users choose their preferred flight
30+
- **Data**: Static flight options (KLM, United) with pricing and duration
2931

30-
### Subgraph 2: 🏨 Accommodation Expert
31-
- **Specialization**: Hotels, Airbnb, resorts, hostels, camping, and lodging options
32-
- **Triggers**: "hotel", "accommodation", "stay", "room", "airbnb", "resort"
33-
- **Tools**: `update_accommodation()` with location and amenities optimization
32+
### Subgraph 2: 🏨 Hotels Agent
33+
- **Specialization**: Finding and booking accommodation
34+
- **Process**: Shows hotel options in San Francisco with different price points
35+
- **Interaction**: Uses interrupts for user to select their preferred hotel
36+
- **Data**: Static hotel options (Hotel Zephyr, Ritz-Carlton, Hotel Zoe)
3437

35-
### Subgraph 3: 🎯 Activities Planner
36-
- **Specialization**: Attractions, restaurants, tours, cultural experiences, entertainment
37-
- **Triggers**: "activities", "attractions", "restaurant", "sightseeing", "tour", "experience"
38-
- **Tools**: `update_activities()` with local insights and time optimization
38+
### Subgraph 3: 🎯 Experiences Agent
39+
- **Specialization**: Curating restaurants and activities
40+
- **Process**: AI-powered recommendations based on selected flights and hotels
41+
- **Features**: Combines 2 restaurants and 2 activities with location-aware suggestions
42+
- **Data**: Static experiences (Pier 39, Golden Gate Bridge, Swan Oyster Depot, Tartine Bakery)
3943

4044
## How It Works 🔄
4145

42-
1. **User Input**: "Plan a 5-day trip to Paris for 2 people"
43-
2. **Coordinator Analysis**: Determines this requires all three subgraphs
44-
3. **Intelligent Routing**: Distributes specialized requests to each subgraph:
45-
- Transportation: "Find flights to Paris and local transport"
46-
- Accommodation: "Find hotels in central Paris for 2 guests"
47-
- Activities: "Plan 5 days of Paris attractions and dining"
48-
4. **Parallel Processing**: All subgraphs work simultaneously
49-
5. **State Synchronization**: Each subgraph updates its portion of the travel plan
50-
6. **Visual Feedback**: UI shows which subgraphs are active and updating
46+
1. **User Request**: "Help me plan a trip to San Francisco"
47+
2. **Supervisor Analysis**: Determines what travel components are needed
48+
3. **Sequential Routing**: Routes to each agent in logical order:
49+
- First: Flights Agent (get transportation sorted)
50+
- Then: Hotels Agent (book accommodation)
51+
- Finally: Experiences Agent (plan activities)
52+
4. **Human Decisions**: Each agent presents options and waits for user choice via interrupts
53+
5. **State Building**: Selected choices are stored in the shared itinerary object
54+
6. **Completion**: All agents report back to supervisor for final coordination
5155

5256
## State Communication Patterns 📊
5357

5458
### Shared State Schema
55-
```typescript
56-
interface TravelPlan {
57-
destination: string;
58-
travel_dates: string;
59-
duration: string;
60-
travelers: number;
61-
budget: string;
62-
transportation: Transportation; // Owned by Transportation subgraph
63-
accommodation: Accommodation; // Owned by Accommodation subgraph
64-
activities: Activity[]; // Owned by Activities subgraph
65-
travel_notes: string[]; // Shared across all
66-
}
67-
```
68-
69-
### Domain-Specific Updates
70-
Each subgraph only modifies its own domain while preserving the complete travel plan:
71-
72-
- **Transportation Subgraph**: Updates `travel_plan.transportation` object
73-
- **Accommodation Subgraph**: Updates `travel_plan.accommodation` object
74-
- **Activities Subgraph**: Updates `travel_plan.activities` array
59+
All subgraph agents share and contribute to a common state object. When any agent updates the shared state, these changes are immediately reflected in the frontend through real-time syncing. This ensures that:
7560

76-
## Try These Examples! 💡
77-
78-
### Transportation Focus
79-
- "Find me flights from New York to Tokyo"
80-
- "I want to take the train through Europe"
81-
- "Plan a road trip from Los Angeles to San Francisco"
82-
83-
### Accommodation Focus
84-
- "Find luxury hotels in downtown Manhattan"
85-
- "I want to camp in Yosemite National Park"
86-
- "Book an Airbnb near the Eiffel Tower"
87-
88-
### Activities Focus
89-
- "What are the must-see attractions in Rome?"
90-
- "Find the best restaurants in Tokyo"
91-
- "Plan adventure activities in Costa Rica"
92-
93-
### Multi-Domain Requests
94-
- "Plan a romantic weekend in Santorini"
95-
- "Organize a family vacation to Disney World"
96-
- "Create a backpacking itinerary through Southeast Asia"
97-
98-
## Visual Features 👁️
99-
100-
### Real-Time Subgraph Activity
101-
- **Glowing indicators** show which subgraph is currently active
102-
- **Animated routing paths** display request flow from coordinator to subgraphs
103-
- **Live travel plan updates** as each subgraph contributes
104-
105-
### Travel Plan Visualization
106-
- **Dynamic travel overview** with destination and traveler indicators
107-
- **Comprehensive travel details** showing transportation, accommodation, and activities
108-
- **Smart destination emojis** that match popular travel destinations
109-
- **Planning progress tracking** across all travel aspects
110-
111-
### Mobile Responsive
112-
- **Collapsible chat interface** for mobile users
113-
- **Touch-friendly controls** with gesture support
114-
- **Optimized layouts** for different screen sizes
115-
116-
## Technical Implementation ⚙️
117-
118-
### Backend (Python)
119-
- **LangGraph workflow** with embedded subgraphs
120-
- **Smart routing logic** using travel-specific keyword analysis
121-
- **State management** with shared travel plan object
122-
- **Tool definitions** for each travel domain specialist
123-
- **Event streaming** for real-time UI updates
61+
- **Flight selections** from the Flights Agent are visible to subsequent agents
62+
- **Hotel choices** influence the Experiences Agent's recommendations
63+
- **All updates** are synchronized with the frontend UI in real-time
64+
- **State persistence** maintains the travel itinerary throughout the workflow
12465

125-
### Frontend (React + TypeScript)
126-
- **CopilotKit integration** for seamless chat experience
127-
- **Real-time state synchronization** with `useCoAgent`
128-
- **Animated UI components** showing subgraph activity
129-
- **Travel-themed design** with destination recognition
130-
- **Custom travel data models** for type safety
66+
### Human-in-the-Loop Pattern
67+
Two of the specialist agents use **interrupts** to pause execution and gather user preferences:
13168

132-
## Learning Outcomes 🎯
69+
- **Flights Agent**: Presents options → interrupt → waits for selection → continues
70+
- **Hotels Agent**: Shows hotels → interrupt → waits for choice → continues
13371

134-
After exploring this demo, you'll understand:
135-
136-
1. **Subgraph Architecture**: How to structure travel planning with specialized components
137-
2. **State Patterns**: When to use shared travel state vs. different schemas
138-
3. **Routing Logic**: How to intelligently direct travel requests to appropriate subgraphs
139-
4. **Visual Representation**: Making AI travel planning visible to users
140-
5. **Real-World Applications**: Practical patterns for multi-specialist systems
141-
142-
## Why Travel Planning Works So Well 🌟
143-
144-
Travel planning is perfect for demonstrating subgraphs because:
145-
146-
- **Clear Domain Separation**: Everyone understands transportation ≠ accommodation ≠ activities
147-
- **Real-World Relevance**: Everyone has planned a trip and can relate to the process
148-
- **Complex Coordination**: Shows how specialists must work together for optimal results
149-
- **Visual Appeal**: Travel plans are naturally visual and engaging
150-
- **Immediate Value**: Users can actually use this for real travel planning!
151-
152-
## Next Steps 🚀
153-
154-
Ready to build your own subgraph systems? Consider these patterns:
155-
156-
- **E-commerce**: Product Finder → Inventory Checker → Price Calculator → Order Processor
157-
- **Healthcare**: Symptom Analyzer → Treatment Planner → Medication Manager → Appointment Scheduler
158-
- **Education**: Course Planner → Content Creator → Assessment Designer → Progress Tracker
159-
- **Content Creation**: Research → Writing → Editing → Publishing
160-
161-
The possibilities are endless when you can compose specialized AI agents into powerful workflows! ⚡
162-
163-
## Example Conversations 💬
164-
165-
### Complete Trip Planning
166-
**User**: "Plan a 7-day trip to Japan for my honeymoon"
72+
## Try These Examples! 💡
16773

168-
**Trip Coordinator**: *Routes to Transportation Specialist*
169-
**🚗 Transportation**: "I'll find flights to Tokyo and plan your internal travel"
74+
### Getting Started
75+
- "Help me plan a trip to San Francisco"
76+
- "I want to visit San Francisco from Amsterdam"
77+
- "Plan my travel itinerary"
17078

171-
**Trip Coordinator**: *Routes to Accommodation Specialist*
172-
**🏨 Accommodation**: "Let me find romantic hotels and ryokans for your stay"
79+
### During the Process
80+
When the Flights Agent presents options:
81+
- Choose between KLM ($650, 11h 30m) or United ($720, 12h 15m)
17382

174-
**Trip Coordinator**: *Routes to Activities Specialist*
175-
**🎯 Activities**: "I'll curate amazing experiences from temples to cuisine"
83+
When the Hotels Agent shows accommodations:
84+
- Select from Hotel Zephyr, The Ritz-Carlton, or Hotel Zoe
17685

177-
### Specific Domain Updates
178-
**User**: "Actually, let's fly business class"
179-
**Trip Coordinator**: *Routes to Transportation Specialist*
180-
**🚗 Transportation**: "Upgrading your flights to business class with better timing"
86+
The Experiences Agent will then provide tailored recommendations based on your choices!
18187

182-
**User**: "Find activities near our hotel"
183-
**Trip Coordinator**: *Routes to Activities Specialist*
184-
**🎯 Activities**: "Adding nearby attractions and restaurants to your itinerary"
88+
## Frontend Capabilities 👁️
18589

186-
This natural conversation flow demonstrates how subgraphs enable truly intelligent, specialized assistance! 🎉
90+
- **Human-in-the-loop with interrupts** from subgraphs for user decision making
91+
- **Subgraphs detection and streaming** to show which agent is currently active
92+
- **Real-time state updates** as the shared itinerary is built across agents

0 commit comments

Comments
 (0)