shekkari21 commited on
Commit
0cb7ee0
·
1 Parent(s): 77eb1b0

added few files

Browse files
misc/JOB_SEARCH_SCHEDULE.md ADDED
@@ -0,0 +1,468 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Job Search Schedule: February 1 - June 1, 2026
2
+
3
+ **Goal:** Land a $150k+ Applied AI/ML Engineer role before OPT grace period ends.
4
+
5
+ ---
6
+
7
+ ## Daily Structure
8
+
9
+ | Time | Activity |
10
+ |------|----------|
11
+ | 5:00 AM | Wake up |
12
+ | 5:00 - 6:00 AM | Morning routine, coffee |
13
+ | 6:00 - 9:00 AM | **Deep Work Block 1** (LeetCode/Technical) |
14
+ | 9:00 - 9:30 AM | Break |
15
+ | 9:30 - 12:30 PM | **Deep Work Block 2** (Learning/Projects) |
16
+ | 12:30 - 1:30 PM | Lunch |
17
+ | 1:30 - 4:30 PM | **Deep Work Block 3** (Job Applications/Networking) |
18
+ | 4:30 - 7:00 PM | Gym (2.5 hours) |
19
+ | 7:00 - 8:00 PM | Dinner |
20
+ | 8:00 - 10:00 PM | Light work (applications, reading, prep) |
21
+ | 10:00 - 11:00 PM | Wind down |
22
+ | 11:00 PM | Sleep |
23
+
24
+ **Tuesday Exception:** Class 7-10 PM (no gym, shift blocks earlier)
25
+
26
+ ---
27
+
28
+ ## Phase Overview
29
+
30
+ | Phase | Weeks | Focus |
31
+ |-------|-------|-------|
32
+ | **Phase 1** | Week 1-4 (Feb) | Foundation + Start Applications |
33
+ | **Phase 2** | Week 5-8 (Mar) | LangChain + Interview Prep Ramp |
34
+ | **Phase 3** | Week 9-12 (Apr) | System Design + Mock Interviews |
35
+ | **Phase 4** | Week 13-17 (May-Jun 1) | Interview Mode + Final Push |
36
+
37
+ ---
38
+
39
+ # PHASE 1: Foundation (February)
40
+
41
+ ## Week 1: Feb 1-7
42
+ ### Theme: Finish Agent Framework + Start Everything
43
+
44
+ | Block | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
45
+ |-------|-----|-----|-----|-----|-----|-----|-----|
46
+ | 6-9 AM | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x3 | Rest |
47
+ | 9:30-12:30 | Agent Framework | Agent Framework | Agent Framework | Agent Framework | Agent Framework | Review week | Rest |
48
+ | 1:30-4:30 | Resume update | 5 applications | 5 applications | 5 applications | 5 applications | Network LinkedIn | Rest |
49
+ | 8-10 PM | ML review | (Class) | ML review | ML review | ML review | Applications | Rest |
50
+
51
+ ### Deliverables Week 1:
52
+ - [ ] Agent framework 100% complete
53
+ - [ ] LeetCode: 12 problems solved (Arrays, Strings focus)
54
+ - [ ] Resume updated with agent framework project
55
+ - [ ] 20+ job applications submitted
56
+ - [ ] LinkedIn profile updated
57
+ - [ ] 5 LinkedIn connection requests to recruiters
58
+
59
+ ---
60
+
61
+ ## Week 2: Feb 8-14
62
+ ### Theme: LangChain Basics + Application Momentum
63
+
64
+ | Block | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
65
+ |-------|-----|-----|-----|-----|-----|-----|-----|
66
+ | 6-9 AM | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x3 | Rest |
67
+ | 9:30-12:30 | LangChain basics | LangChain basics | LangChain chains | LangChain chains | LangChain agents | Build project | Rest |
68
+ | 1:30-4:30 | 5 applications | 5 applications | 5 applications | 5 applications | 5 applications | Network | Rest |
69
+ | 8-10 PM | ML review | (Class) | ML review | ML review | ML review | Behavioral prep | Rest |
70
+
71
+ ### Deliverables Week 2:
72
+ - [ ] LeetCode: 12 more problems (Total: 24) - Trees, Linked Lists
73
+ - [ ] LangChain fundamentals understood (chains, prompts, output parsers)
74
+ - [ ] 25+ job applications submitted (Total: 45+)
75
+ - [ ] Started tracking applications in spreadsheet
76
+ - [ ] 3 Pfizer contacts messaged for referrals
77
+
78
+ ---
79
+
80
+ ## Week 3: Feb 15-21
81
+ ### Theme: LangGraph + First Responses
82
+
83
+ | Block | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
84
+ |-------|-----|-----|-----|-----|-----|-----|-----|
85
+ | 6-9 AM | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x3 | Rest |
86
+ | 9:30-12:30 | LangGraph basics | LangGraph state | LangGraph edges | LangGraph project | LangGraph project | Complete project | Rest |
87
+ | 1:30-4:30 | 5 applications | 5 applications | 5 applications | 5 applications | 5 applications | Network | Rest |
88
+ | 8-10 PM | ML review | (Class) | RAG concepts | RAG concepts | Project polish | Behavioral prep | Rest |
89
+
90
+ ### Deliverables Week 3:
91
+ - [ ] LeetCode: 12 more problems (Total: 36) - Graphs, BFS/DFS
92
+ - [ ] LangGraph multi-agent project complete
93
+ - [ ] Project deployed (Streamlit or FastAPI)
94
+ - [ ] 25+ applications (Total: 70+)
95
+ - [ ] First phone screens scheduled (hopefully)
96
+ - [ ] Pfizer STAR story written out
97
+
98
+ ---
99
+
100
+ ## Week 4: Feb 22-28
101
+ ### Theme: RAG Deep Dive + Interview Prep Start
102
+
103
+ | Block | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
104
+ |-------|-----|-----|-----|-----|-----|-----|-----|
105
+ | 6-9 AM | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x3 | Rest |
106
+ | 9:30-12:30 | RAG architecture | Vector DBs | Chunking strategies | Retrieval patterns | RAG evaluation | Build RAG project | Rest |
107
+ | 1:30-4:30 | 5 applications | 5 applications | 5 applications | 5 applications | 5 applications | Mock interview | Rest |
108
+ | 8-10 PM | Interview prep | (Class) | Interview prep | Interview prep | Interview prep | Rest | Rest |
109
+
110
+ ### Deliverables Week 4:
111
+ - [ ] LeetCode: 12 more problems (Total: 48) - DP basics
112
+ - [ ] RAG system built (with evaluation)
113
+ - [ ] Added to portfolio
114
+ - [ ] 25+ applications (Total: 95+)
115
+ - [ ] First mock interview completed
116
+ - [ ] ML fundamentals flashcards created
117
+
118
+ ---
119
+
120
+ ## February Checkpoint ✓
121
+
122
+ **By Feb 28:**
123
+ - [ ] 48+ LeetCode problems solved
124
+ - [ ] Agent framework complete + deployed
125
+ - [ ] LangGraph project complete + deployed
126
+ - [ ] RAG project complete
127
+ - [ ] 95+ job applications
128
+ - [ ] 2-3 phone screens scheduled
129
+ - [ ] Pfizer story polished
130
+
131
+ ---
132
+
133
+ # PHASE 2: LangChain Mastery + Interview Ramp (March)
134
+
135
+ ## Week 5: Mar 1-7
136
+ ### Theme: Advanced RAG + Phone Screens
137
+
138
+ | Block | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
139
+ |-------|-----|-----|-----|-----|-----|-----|-----|
140
+ | 6-9 AM | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x3 | Rest |
141
+ | 9:30-12:30 | Self-correcting RAG | Multi-query RAG | Hybrid search | GraphRAG intro | GraphRAG build | Project polish | Rest |
142
+ | 1:30-4:30 | Applications | Applications | Phone screen prep | Applications | Applications | Network | Rest |
143
+ | 8-10 PM | ML interview Q's | (Class) | ML interview Q's | ML interview Q's | Behavioral prep | Rest | Rest |
144
+
145
+ ### Deliverables Week 5:
146
+ - [ ] LeetCode: 12 more (Total: 60)
147
+ - [ ] Advanced RAG patterns implemented
148
+ - [ ] GraphRAG basic understanding
149
+ - [ ] 20+ applications (Total: 115+)
150
+ - [ ] 1-2 phone screens completed
151
+ - [ ] ML fundamentals review: supervised learning
152
+
153
+ ---
154
+
155
+ ## Week 6: Mar 8-14
156
+ ### Theme: Production Patterns + Technical Screens
157
+
158
+ | Block | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
159
+ |-------|-----|-----|-----|-----|-----|-----|-----|
160
+ | 6-9 AM | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x3 | Rest |
161
+ | 9:30-12:30 | Streaming patterns | Fallback chains | Caching | Memory patterns | Production deploy | System design | Rest |
162
+ | 1:30-4:30 | Applications | Applications | Applications | Applications | Applications | Mock interview | Rest |
163
+ | 8-10 PM | DL/Transformer Q's | (Class) | DL/Transformer Q's | Interview prep | Interview prep | Rest | Rest |
164
+
165
+ ### Deliverables Week 6:
166
+ - [ ] LeetCode: 12 more (Total: 72)
167
+ - [ ] Production-ready LangChain app
168
+ - [ ] Streaming + caching implemented
169
+ - [ ] 20+ applications (Total: 135+)
170
+ - [ ] 2 mock interviews completed
171
+ - [ ] ML fundamentals review: deep learning basics
172
+
173
+ ---
174
+
175
+ ## Week 7: Mar 15-21
176
+ ### Theme: System Design Intro + More Interviews
177
+
178
+ | Block | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
179
+ |-------|-----|-----|-----|-----|-----|-----|-----|
180
+ | 6-9 AM | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x3 | Rest |
181
+ | 9:30-12:30 | ML System Design book | Design: Rec system | Design: Search | Design: RAG system | Design: Agent | Practice designs | Rest |
182
+ | 1:30-4:30 | Applications | Applications | Applications | Applications | Applications | Mock interview | Rest |
183
+ | 8-10 PM | RAG interview Q's | (Class) | Agent interview Q's | Interview prep | Interview prep | Rest | Rest |
184
+
185
+ ### Deliverables Week 7:
186
+ - [ ] LeetCode: 12 more (Total: 84)
187
+ - [ ] 3 ML system designs practiced
188
+ - [ ] System design framework memorized
189
+ - [ ] 20+ applications (Total: 155+)
190
+ - [ ] Technical screen(s) completed
191
+ - [ ] ML fundamentals review: NLP/Transformers
192
+
193
+ ---
194
+
195
+ ## Week 8: Mar 22-28
196
+ ### Theme: Interview Prep Intensity
197
+
198
+ | Block | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
199
+ |-------|-----|-----|-----|-----|-----|-----|-----|
200
+ | 6-9 AM | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x3 | Rest |
201
+ | 9:30-12:30 | System design practice | System design practice | ML interview Q's | ML interview Q's | Mock interview | Mock interview | Rest |
202
+ | 1:30-4:30 | Applications | Applications | Applications | Applications | Applications | Rest | Rest |
203
+ | 8-10 PM | Behavioral prep | (Class) | Behavioral prep | Interview prep | Rest | Rest | Rest |
204
+
205
+ ### Deliverables Week 8:
206
+ - [ ] LeetCode: 12 more (Total: 96)
207
+ - [ ] 5+ system designs practiced
208
+ - [ ] 15+ applications (Total: 170+)
209
+ - [ ] 3+ mock interviews total
210
+ - [ ] Ready for technical rounds
211
+
212
+ ---
213
+
214
+ ## March Checkpoint ✓
215
+
216
+ **By Mar 31:**
217
+ - [ ] 96+ LeetCode problems solved
218
+ - [ ] Advanced RAG + LangGraph projects complete
219
+ - [ ] 5+ system designs practiced
220
+ - [ ] 170+ total applications
221
+ - [ ] 5+ phone/technical screens completed
222
+ - [ ] On-site interviews scheduled (hopefully)
223
+
224
+ ---
225
+
226
+ # PHASE 3: Interview Mode (April)
227
+
228
+ ## Week 9: Apr 1-7
229
+ ### Theme: Mock Interviews + Real Interviews
230
+
231
+ | Block | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
232
+ |-------|-----|-----|-----|-----|-----|-----|-----|
233
+ | 6-9 AM | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | LeetCode x2 | Rest |
234
+ | 9:30-12:30 | Mock coding | Mock system design | Mock ML | Interview prep | Interview prep | Mock full loop | Rest |
235
+ | 1:30-4:30 | Applications | Applications | Applications | Applications | Applications | Rest | Rest |
236
+ | 8-10 PM | Review weak areas | (Class) | Review weak areas | Prep for interviews | Prep for interviews | Rest | Rest |
237
+
238
+ ### Deliverables Week 9:
239
+ - [ ] LeetCode: 10 more (Total: 106)
240
+ - [ ] 2 full mock interview loops
241
+ - [ ] 10+ applications (Total: 180+)
242
+ - [ ] Identify and fix weak areas
243
+
244
+ ---
245
+
246
+ ## Week 10: Apr 8-14
247
+ ### Theme: On-sites Begin
248
+
249
+ | Block | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
250
+ |-------|-----|-----|-----|-----|-----|-----|-----|
251
+ | 6-9 AM | LeetCode x2 | Interview prep | LeetCode x2 | Interview prep | LeetCode x2 | Review | Rest |
252
+ | 9:30-12:30 | Prep for specific company | INTERVIEW | Prep | INTERVIEW | Prep | Mock | Rest |
253
+ | 1:30-4:30 | Applications | Follow-up | Applications | Follow-up | Applications | Rest | Rest |
254
+ | 8-10 PM | Company research | (Class) | Company research | Behavioral prep | Rest | Rest | Rest |
255
+
256
+ ### Deliverables Week 10:
257
+ - [ ] LeetCode: 6 more (Total: 112)
258
+ - [ ] 2+ on-site/virtual on-site interviews
259
+ - [ ] Thank you emails sent
260
+ - [ ] Continue applications pipeline
261
+
262
+ ---
263
+
264
+ ## Week 11: Apr 15-21
265
+ ### Theme: Interview Sprint
266
+
267
+ | Block | Focus |
268
+ |-------|-------|
269
+ | All week | Interviews, prep between interviews, light applications |
270
+
271
+ ### Deliverables Week 11:
272
+ - [ ] 2-3 more interviews completed
273
+ - [ ] Follow-up on all interviews
274
+ - [ ] Continue pipeline
275
+
276
+ ---
277
+
278
+ ## Week 12: Apr 22-28
279
+ ### Theme: Interview Sprint Continues
280
+
281
+ | Block | Focus |
282
+ |-------|-------|
283
+ | All week | Interviews, negotiations prep if offers coming |
284
+
285
+ ### Deliverables Week 12:
286
+ - [ ] More interviews
287
+ - [ ] Start seeing results (offers or rejections)
288
+ - [ ] Learn from rejections, iterate
289
+
290
+ ---
291
+
292
+ ## April Checkpoint ✓
293
+
294
+ **By Apr 30:**
295
+ - [ ] 110+ LeetCode problems solved
296
+ - [ ] 5-10 on-site interviews completed
297
+ - [ ] 190+ total applications
298
+ - [ ] Hopefully 1+ offers in pipeline
299
+ - [ ] Clear understanding of weak areas
300
+
301
+ ---
302
+
303
+ # PHASE 4: Final Push (May)
304
+
305
+ ## Week 13: May 1-7
306
+ ### Theme: Close Deals or Intensify Search
307
+
308
+ **If you have offers:**
309
+ - Negotiate
310
+ - Compare offers
311
+ - Make decision
312
+
313
+ **If no offers yet:**
314
+ - Analyze feedback from rejections
315
+ - Intensify applications
316
+ - More mock interviews
317
+
318
+ ### Deliverables Week 13:
319
+ - [ ] Decision on any offers OR
320
+ - [ ] 20+ more applications
321
+ - [ ] More interviews scheduled
322
+
323
+ ---
324
+
325
+ ## Week 14: May 8-14
326
+ ### Theme: Pre-Graduation Push
327
+
328
+ | Block | Focus |
329
+ |-------|-------|
330
+ | Continue interviews | Focus on closing |
331
+ | Applications | Maintain pipeline |
332
+ | Prep for graduation | Logistics |
333
+
334
+ ### Deliverables Week 14:
335
+ - [ ] Interviews ongoing
336
+ - [ ] Offer negotiations if applicable
337
+
338
+ ---
339
+
340
+ ## Week 15: May 15-21
341
+ ### Theme: Graduation Week
342
+
343
+ | Block | Focus |
344
+ |-------|-------|
345
+ | May 23 | GRADUATION 🎓 |
346
+ | Rest of week | Interviews, decisions |
347
+
348
+ ### Deliverables Week 15:
349
+ - [ ] Graduate!
350
+ - [ ] Close any pending offers
351
+ - [ ] Prepare for OPT start
352
+
353
+ ---
354
+
355
+ ## Week 16: May 22-28
356
+ ### Theme: Post-Graduation, OPT Transition
357
+
358
+ | Block | Focus |
359
+ |-------|-------|
360
+ | OPT paperwork | Get EAD card |
361
+ | Interviews | Continue if needed |
362
+ | Start date discussions | If offers accepted |
363
+
364
+ ### Deliverables Week 16:
365
+ - [ ] OPT paperwork filed
366
+ - [ ] Job offer accepted OR
367
+ - [ ] Intensive job search continues
368
+
369
+ ---
370
+
371
+ ## Week 17: May 29 - Jun 1
372
+ ### Theme: June 1 Target
373
+
374
+ ### Deliverables:
375
+ - [ ] **JOB OFFER ACCEPTED** (Target!)
376
+ - [ ] Start date confirmed
377
+ - [ ] OPT employment verified
378
+
379
+ ---
380
+
381
+ # Tracking Spreadsheet
382
+
383
+ Create a spreadsheet with these columns:
384
+
385
+ | Company | Role | Applied Date | Status | Next Step | Notes |
386
+ |---------|------|--------------|--------|-----------|-------|
387
+ | Google | Applied AI Engineer | Feb 3 | Applied | Wait | Referral from X |
388
+ | Anthropic | ML Engineer | Feb 5 | Phone Screen | Feb 15 | Prep RAG questions |
389
+
390
+ ---
391
+
392
+ # Weekly Metrics to Track
393
+
394
+ | Metric | Week 1 Target | Week 8 Target | Week 17 Target |
395
+ |--------|---------------|---------------|----------------|
396
+ | LeetCode Total | 12 | 96 | 120 |
397
+ | Applications Total | 20 | 170 | 220 |
398
+ | Phone Screens | 0 | 8 | 15 |
399
+ | Technical Screens | 0 | 5 | 12 |
400
+ | On-sites | 0 | 2 | 8 |
401
+ | Offers | 0 | 0 | 1+ |
402
+
403
+ ---
404
+
405
+ # Emergency Backup Plans
406
+
407
+ ## If no interviews by Week 6:
408
+ - Resume review with mentor/professional
409
+ - Expand to Tier 2/3 companies
410
+ - More networking, less applications
411
+ - Consider contracting roles
412
+
413
+ ## If no offers by Week 12:
414
+ - Lower target salary temporarily
415
+ - Consider smaller companies
416
+ - Look at contract-to-hire roles
417
+ - Leverage Pfizer network harder
418
+
419
+ ## If no offers by Week 16:
420
+ - Start date flexibility with any offer
421
+ - Consider any legitimate offer
422
+ - Plan for extended search during OPT
423
+
424
+ ---
425
+
426
+ # Resources to Use
427
+
428
+ **LeetCode:**
429
+ - NeetCode 150 (structured)
430
+ - Grind 75 (time-efficient)
431
+ - Company-specific lists
432
+
433
+ **System Design:**
434
+ - "Designing Machine Learning Systems" - Chip Huyen
435
+ - "ML System Design Interview" - Ali Aminian
436
+ - YouTube: System Design Interview channel
437
+
438
+ **Behavioral:**
439
+ - Write out 5 STAR stories
440
+ - Pfizer project (main story)
441
+ - Agent framework (technical depth)
442
+ - Conflict resolution story
443
+ - Failure and learning story
444
+
445
+ **Mock Interviews:**
446
+ - Pramp (free)
447
+ - Interviewing.io (free/paid)
448
+ - Friends/classmates
449
+
450
+ ---
451
+
452
+ # Key Success Factors
453
+
454
+ 1. **Start applications NOW** - Don't wait until "ready"
455
+ 2. **Consistent LeetCode** - 2 problems/day minimum
456
+ 3. **Track everything** - Spreadsheet is your friend
457
+ 4. **Network aggressively** - Referrals > cold applications
458
+ 5. **Learn from rejections** - Ask for feedback
459
+ 6. **Stay healthy** - Gym, sleep, breaks matter
460
+
461
+ ---
462
+
463
+ **You've got this. 4 months is enough with focused execution. Start today.**
464
+
465
+ ---
466
+
467
+ *Last updated: February 1, 2026*
468
+
misc/tutorials/LANGCHAIN_LANGSERVE_PATTERNS.md ADDED
@@ -0,0 +1,782 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # LangChain & LangServe: Advanced Patterns and Nuances
2
+
3
+ A comprehensive reference for building production-ready agentic systems with LangChain and LangServe.
4
+
5
+ ---
6
+
7
+ ## Table of Contents
8
+
9
+ 1. [LangGraph - Stateful Agent Workflows](#1-langgraph---stateful-agent-workflows)
10
+ 2. [Agentic RAG Patterns](#2-agentic-rag-patterns)
11
+ 3. [Human-in-the-Loop Workflows](#3-human-in-the-loop-workflows)
12
+ 4. [Streaming Patterns](#4-streaming-patterns)
13
+ 5. [Fallback and Routing Chains](#5-fallback-and-routing-chains)
14
+ 6. [Structured Output Patterns](#6-structured-output-patterns)
15
+ 7. [Tool Orchestration](#7-tool-orchestration)
16
+ 8. [Multi-Agent Patterns](#8-multi-agent-patterns)
17
+ 9. [Production Patterns](#9-production-patterns)
18
+ 10. [Evaluation Patterns](#10-evaluation-patterns)
19
+ 11. [Advanced Memory Patterns](#11-advanced-memory-patterns)
20
+ 12. [Advanced Retrieval Patterns](#12-advanced-retrieval-patterns)
21
+ 13. [Callbacks and Observability](#13-callbacks-and-observability)
22
+ 14. [Dynamic Tool Generation](#14-dynamic-tool-generation)
23
+ 15. [Complex Chain Patterns](#15-complex-chain-patterns)
24
+ 16. [LangGraph Advanced Patterns](#16-langgraph-advanced-patterns)
25
+ 17. [Guardrails and Safety](#17-guardrails-and-safety)
26
+ 18. [Advanced Prompting Patterns](#18-advanced-prompting-patterns)
27
+ 19. [Testing Patterns](#19-testing-patterns)
28
+ 20. [LangServe Deployment Nuances](#20-langserve-deployment-nuances)
29
+
30
+ ---
31
+
32
+ ## 1. LangGraph - Stateful Agent Workflows
33
+
34
+ LangGraph enables complex, stateful workflows with cycles and conditional routing.
35
+
36
+ ### Key Concepts
37
+ - **StateGraph**: Define a graph with typed state that flows between nodes
38
+ - **Nodes**: Functions that process and transform state
39
+ - **Edges**: Connections between nodes (can be conditional)
40
+ - **Cycles**: Loops in the graph for iterative refinement
41
+ - **Checkpointing**: Persist state for resumption
42
+
43
+ ### What to Master
44
+ - State management across nodes
45
+ - Conditional edge routing based on state
46
+ - Implementing cycles for iterative improvement
47
+ - Human-in-the-loop breakpoints
48
+ - State persistence and recovery
49
+ - Subgraphs for modular workflows
50
+
51
+ ### Interview-Worthy Projects
52
+ - Multi-agent research assistant with supervisor coordination
53
+ - Self-correcting RAG with review loop
54
+ - Code generation with test → fix → retry cycles
55
+
56
+ ---
57
+
58
+ ## 2. Agentic RAG Patterns
59
+
60
+ Beyond basic RAG - agents that reason about retrieval.
61
+
62
+ ### Key Patterns
63
+
64
+ **Self-Correcting RAG**
65
+ - Initial retrieval
66
+ - Generate answer
67
+ - Self-check for hallucinations
68
+ - Re-retrieve with refined query if needed
69
+
70
+ **Query Transformation**
71
+ - Query expansion (multiple variations)
72
+ - Query decomposition (break into sub-queries)
73
+ - Query refinement based on initial results
74
+
75
+ **Adaptive Retrieval**
76
+ - Decide when to retrieve vs use knowledge
77
+ - Multi-hop reasoning for complex questions
78
+ - Corrective RAG (re-retrieval on failure)
79
+
80
+ **HyDE (Hypothetical Document Embeddings)**
81
+ - Generate hypothetical answer first
82
+ - Use it to retrieve similar real documents
83
+ - Better semantic matching
84
+
85
+ ### What to Master
86
+ - When to retrieve vs when to answer directly
87
+ - How to evaluate retrieval quality
88
+ - Multi-step retrieval strategies
89
+ - Combining retrieval with reasoning
90
+
91
+ ---
92
+
93
+ ## 3. Human-in-the-Loop Workflows
94
+
95
+ Real production systems need human oversight.
96
+
97
+ ### Key Patterns
98
+
99
+ **Interrupts**
100
+ - Pause execution at specific nodes
101
+ - Wait for human approval
102
+ - Resume with modified state if needed
103
+
104
+ **State Persistence**
105
+ - Save state across sessions
106
+ - Allow humans to review async
107
+ - Resume from any checkpoint
108
+
109
+ **Approval Workflows**
110
+ - Single approval gates
111
+ - Multi-level approval chains
112
+ - Conditional approval based on risk
113
+
114
+ **Feedback Incorporation**
115
+ - Collect human corrections
116
+ - Learn from feedback
117
+ - Improve over time
118
+
119
+ ### What to Master
120
+ - Designing breakpoints in workflows
121
+ - State serialization for persistence
122
+ - Multi-turn approval processes
123
+ - Feedback loop architecture
124
+
125
+ ---
126
+
127
+ ## 4. Streaming Patterns
128
+
129
+ Not just streaming text - structured streaming for complex chains.
130
+
131
+ ### Key Patterns
132
+
133
+ **Event Streaming**
134
+ - Stream events from nested chains
135
+ - Fine-grained control over what to stream
136
+ - Different event types (tool start, LLM chunk, retriever end)
137
+
138
+ **Progress Updates**
139
+ - Stream status during long operations
140
+ - Partial results as they become available
141
+ - Error events for graceful handling
142
+
143
+ **Multi-Agent Streaming**
144
+ - Stream from multiple agents simultaneously
145
+ - Coordinate streaming across agents
146
+ - Aggregate and present coherently
147
+
148
+ ### What to Master
149
+ - `astream_events()` for fine-grained control
150
+ - Streaming in multi-agent systems
151
+ - Progress updates during long operations
152
+ - Partial results streaming
153
+ - Error streaming and recovery
154
+
155
+ ---
156
+
157
+ ## 5. Fallback and Routing Chains
158
+
159
+ Build resilient systems with intelligent routing.
160
+
161
+ ### Key Patterns
162
+
163
+ **Fallback Chains**
164
+ - Primary chain fails → try fallback
165
+ - Multiple fallback levels
166
+ - Graceful degradation
167
+
168
+ **Semantic Routing**
169
+ - Route based on query meaning
170
+ - Different chains for different intents
171
+ - Dynamic chain selection
172
+
173
+ **Model Routing**
174
+ - Simple queries → cheap model
175
+ - Complex queries → powerful model
176
+ - Cost-aware routing
177
+
178
+ **Latency-Based Routing**
179
+ - Fast model for time-sensitive queries
180
+ - Slow model for quality-critical queries
181
+
182
+ ### What to Master
183
+ - Designing fallback hierarchies
184
+ - Semantic similarity for routing
185
+ - Cost vs quality tradeoffs
186
+ - Error handling at each level
187
+
188
+ ---
189
+
190
+ ## 6. Structured Output Patterns
191
+
192
+ Getting reliable, typed outputs from LLMs.
193
+
194
+ ### Key Patterns
195
+
196
+ **Pydantic Output Parsing**
197
+ - Define schema with Pydantic
198
+ - Parse LLM output into typed objects
199
+ - Validation and error handling
200
+
201
+ **Nested Structures**
202
+ - Complex nested schemas
203
+ - Lists and optional fields
204
+ - Recursive structures
205
+
206
+ **Partial Parsing for Streaming**
207
+ - Parse incomplete JSON during streaming
208
+ - Show progress while parsing
209
+ - Handle malformed chunks
210
+
211
+ **Error Recovery**
212
+ - Retry on parse failure
213
+ - Ask LLM to fix output
214
+ - Fallback to simpler schema
215
+
216
+ ### What to Master
217
+ - Designing robust schemas
218
+ - Handling validation errors
219
+ - Streaming with structured output
220
+ - Combining multiple structured outputs
221
+
222
+ ---
223
+
224
+ ## 7. Tool Orchestration
225
+
226
+ Advanced patterns for tool usage.
227
+
228
+ ### Key Patterns
229
+
230
+ **Tool Dependencies**
231
+ - Tools that call other tools
232
+ - Sequential tool chains
233
+ - Parallel tool execution
234
+
235
+ **Conditional Tool Usage**
236
+ - Select tools based on context
237
+ - Skip tools when not needed
238
+ - Dynamic tool availability
239
+
240
+ **Tool Selection Strategies**
241
+ - Semantic matching to select relevant tools
242
+ - Limit tools based on query type
243
+ - Dynamic tool generation
244
+
245
+ **Tool Error Handling**
246
+ - Retry failed tools
247
+ - Fallback tools
248
+ - Graceful degradation
249
+
250
+ ### What to Master
251
+ - Designing tool interfaces
252
+ - Managing tool dependencies
253
+ - Error handling and retries
254
+ - Tool result validation
255
+
256
+ ---
257
+
258
+ ## 8. Multi-Agent Patterns
259
+
260
+ Coordinating multiple agents for complex tasks.
261
+
262
+ ### Key Patterns
263
+
264
+ **Supervisor Pattern**
265
+ - Manager agent coordinates workers
266
+ - Routes tasks to appropriate agents
267
+ - Synthesizes results
268
+
269
+ **Debate Pattern**
270
+ - Multiple agents discuss/debate
271
+ - Reach consensus
272
+ - Synthesize best answer
273
+
274
+ **Pipeline Pattern**
275
+ - Sequential agent handoffs
276
+ - Each agent specializes
277
+ - Pass context along
278
+
279
+ **Hierarchical Teams**
280
+ - Manager decomposes task
281
+ - Workers execute subtasks
282
+ - Manager synthesizes
283
+
284
+ **Collaborative Agents**
285
+ - Agents work together
286
+ - Shared state
287
+ - Complementary skills
288
+
289
+ **Competitive Agents**
290
+ - Multiple solutions
291
+ - Evaluate and select best
292
+ - Diverse approaches
293
+
294
+ ### What to Master
295
+ - Agent communication protocols
296
+ - State sharing strategies
297
+ - Conflict resolution
298
+ - Coordination overhead management
299
+
300
+ ---
301
+
302
+ ## 9. Production Patterns
303
+
304
+ Building systems that work in the real world.
305
+
306
+ ### Key Patterns
307
+
308
+ **Caching**
309
+ - Semantic caching (similar queries → cached result)
310
+ - Exact match caching
311
+ - Cache invalidation strategies
312
+
313
+ **Rate Limiting**
314
+ - Per-user limits
315
+ - Per-model limits
316
+ - Graceful handling when limited
317
+
318
+ **Retry Strategies**
319
+ - Exponential backoff
320
+ - Jitter to prevent thundering herd
321
+ - Max retry limits
322
+
323
+ **Cost Tracking**
324
+ - Token usage per request
325
+ - Cost per user/session
326
+ - Budget enforcement
327
+
328
+ **Batch Processing**
329
+ - Batch similar requests
330
+ - Efficient API usage
331
+ - Queue management
332
+
333
+ ### What to Master
334
+ - Caching strategies for LLM calls
335
+ - Rate limiting architecture
336
+ - Cost optimization
337
+ - Monitoring and alerting
338
+
339
+ ---
340
+
341
+ ## 10. Evaluation Patterns
342
+
343
+ Measuring and improving agent quality.
344
+
345
+ ### Key Patterns
346
+
347
+ **LLM-as-Judge**
348
+ - Use LLM to evaluate outputs
349
+ - Define evaluation criteria
350
+ - Score and compare
351
+
352
+ **Custom Evaluators**
353
+ - Domain-specific metrics
354
+ - Task-specific evaluation
355
+ - Automated scoring
356
+
357
+ **A/B Testing**
358
+ - Compare different agents
359
+ - Statistical significance
360
+ - User preference tracking
361
+
362
+ **Regression Testing**
363
+ - Maintain test suite
364
+ - Detect regressions
365
+ - Continuous evaluation
366
+
367
+ **Human Feedback**
368
+ - Collect user ratings
369
+ - Incorporate corrections
370
+ - Improve over time
371
+
372
+ ### What to Master
373
+ - Designing evaluation criteria
374
+ - Building test datasets
375
+ - Interpreting evaluation results
376
+ - Continuous improvement loops
377
+
378
+ ---
379
+
380
+ ## 11. Advanced Memory Patterns
381
+
382
+ Beyond basic conversation memory.
383
+
384
+ ### Key Patterns
385
+
386
+ **Cross-Session Memory**
387
+ - Remember across conversations
388
+ - User-specific memory
389
+ - Relevant context retrieval
390
+
391
+ **Entity Memory**
392
+ - Track entities (people, places, things)
393
+ - Update entity knowledge
394
+ - Retrieve entity context
395
+
396
+ **Summary + Buffer Hybrid**
397
+ - Recent messages in full
398
+ - Older messages summarized
399
+ - Token-efficient
400
+
401
+ **Vector Store Memory**
402
+ - All conversations in vector DB
403
+ - Semantic search for relevant context
404
+ - Scalable long-term memory
405
+
406
+ ### What to Master
407
+ - Memory type selection
408
+ - Token budget management
409
+ - Memory persistence
410
+ - Privacy considerations
411
+
412
+ ---
413
+
414
+ ## 12. Advanced Retrieval Patterns
415
+
416
+ Sophisticated retrieval strategies.
417
+
418
+ ### Key Patterns
419
+
420
+ **Multi-Query Retrieval**
421
+ - Generate multiple query variations
422
+ - Retrieve for all variations
423
+ - Combine results
424
+
425
+ **Contextual Compression**
426
+ - Retrieve documents
427
+ - Extract only relevant parts
428
+ - Reduce context size
429
+
430
+ **Parent Document Retrieval**
431
+ - Index small chunks
432
+ - Retrieve full parent documents
433
+ - Best of both worlds
434
+
435
+ **Ensemble Retrieval**
436
+ - Combine semantic + keyword search
437
+ - Weighted combination
438
+ - Better recall
439
+
440
+ **Reranking**
441
+ - Initial retrieval
442
+ - Rerank with cross-encoder
443
+ - Better precision
444
+
445
+ ### What to Master
446
+ - Choosing retrieval strategies
447
+ - Combining multiple approaches
448
+ - Evaluating retrieval quality
449
+ - Optimizing for latency vs quality
450
+
451
+ ---
452
+
453
+ ## 13. Callbacks and Observability
454
+
455
+ Understanding what your agents are doing.
456
+
457
+ ### What to Track
458
+ - Token usage (cost)
459
+ - Latency per step
460
+ - Tool execution times
461
+ - Error rates
462
+ - Retrieval quality
463
+ - User satisfaction
464
+
465
+ ### Integration Points
466
+ - LangSmith for tracing
467
+ - Custom logging
468
+ - Metrics systems
469
+ - Alerting
470
+
471
+ ### What to Master
472
+ - Designing callback handlers
473
+ - Async callbacks for non-blocking
474
+ - Aggregating metrics
475
+ - Setting up alerts
476
+
477
+ ---
478
+
479
+ ## 14. Dynamic Tool Generation
480
+
481
+ Tools that create themselves.
482
+
483
+ ### Key Patterns
484
+
485
+ **API-Based Tools**
486
+ - Generate tools from OpenAPI specs
487
+ - Database schema to tools
488
+ - Dynamic API discovery
489
+
490
+ **Dynamic Tool Selection**
491
+ - Too many tools → select dynamically
492
+ - Semantic matching to query
493
+ - Limit active tools
494
+
495
+ **Tool Composition**
496
+ - Combine tools into workflows
497
+ - Meta-tools that orchestrate
498
+ - Adaptive tool creation
499
+
500
+ ### What to Master
501
+ - API spec parsing
502
+ - Dynamic function generation
503
+ - Tool relevance scoring
504
+ - Managing tool explosion
505
+
506
+ ---
507
+
508
+ ## 15. Complex Chain Patterns
509
+
510
+ Advanced chain compositions.
511
+
512
+ ### Key Patterns
513
+
514
+ **Map-Reduce**
515
+ - Process chunks in parallel (map)
516
+ - Combine results (reduce)
517
+ - Good for large documents
518
+
519
+ **Refine**
520
+ - Iteratively refine answer
521
+ - Each document improves result
522
+ - Good for synthesis
523
+
524
+ **Branching**
525
+ - Conditional paths
526
+ - Multiple parallel branches
527
+ - Merge results
528
+
529
+ ### What to Master
530
+ - Choosing the right pattern
531
+ - Handling large inputs
532
+ - Parallel execution
533
+ - Result aggregation
534
+
535
+ ---
536
+
537
+ ## 16. LangGraph Advanced Patterns
538
+
539
+ Deep LangGraph knowledge.
540
+
541
+ ### Key Patterns
542
+
543
+ **Subgraphs**
544
+ - Nested graphs for modularity
545
+ - Reusable workflow components
546
+ - Clean separation of concerns
547
+
548
+ **Parallel Execution**
549
+ - Fan out to multiple nodes
550
+ - Process in parallel
551
+ - Fan in to merge
552
+
553
+ **Time Travel**
554
+ - Replay from any checkpoint
555
+ - Debug by stepping through
556
+ - Modify and replay
557
+
558
+ **Conditional Cycles**
559
+ - Loop until condition met
560
+ - Self-improvement loops
561
+ - Bounded iteration
562
+
563
+ ### What to Master
564
+ - Graph design patterns
565
+ - State serialization
566
+ - Checkpoint management
567
+ - Debugging complex graphs
568
+
569
+ ---
570
+
571
+ ## 17. Guardrails and Safety
572
+
573
+ Keeping agents safe.
574
+
575
+ ### Key Patterns
576
+
577
+ **Constitutional AI**
578
+ - Self-critique
579
+ - Revise harmful outputs
580
+ - Principle-based filtering
581
+
582
+ **Input Validation**
583
+ - Check inputs before processing
584
+ - Reject unsafe requests
585
+ - Log suspicious activity
586
+
587
+ **Output Filtering**
588
+ - Check outputs before returning
589
+ - Remove sensitive information
590
+ - Ensure policy compliance
591
+
592
+ **Rate Limiting**
593
+ - Prevent abuse
594
+ - Per-user limits
595
+ - Anomaly detection
596
+
597
+ ### What to Master
598
+ - Designing safety principles
599
+ - Input/output validation
600
+ - PII detection and removal
601
+ - Audit logging
602
+
603
+ ---
604
+
605
+ ## 18. Advanced Prompting Patterns
606
+
607
+ Sophisticated prompt engineering.
608
+
609
+ ### Key Patterns
610
+
611
+ **Few-Shot Learning**
612
+ - Include examples in prompt
613
+ - Dynamic example selection
614
+ - Semantic similarity for selection
615
+
616
+ **Chain of Thought**
617
+ - Step-by-step reasoning
618
+ - Show work before answer
619
+ - Better for complex tasks
620
+
621
+ **Self-Consistency**
622
+ - Generate multiple answers
623
+ - Vote on best
624
+ - Higher reliability
625
+
626
+ **Role Prompting**
627
+ - Assign specific roles
628
+ - Expert personas
629
+ - Behavior shaping
630
+
631
+ ### What to Master
632
+ - Example selection strategies
633
+ - Prompt templates
634
+ - Dynamic prompt construction
635
+ - Prompt optimization
636
+
637
+ ---
638
+
639
+ ## 19. Testing Patterns
640
+
641
+ Ensuring quality.
642
+
643
+ ### Key Patterns
644
+
645
+ **Unit Testing**
646
+ - Test individual components
647
+ - Mock LLM responses
648
+ - Fast feedback
649
+
650
+ **Integration Testing**
651
+ - Test full chains
652
+ - Real LLM calls
653
+ - End-to-end verification
654
+
655
+ **Regression Testing**
656
+ - Maintain golden dataset
657
+ - Detect quality drops
658
+ - Continuous monitoring
659
+
660
+ **Load Testing**
661
+ - Test under load
662
+ - Find bottlenecks
663
+ - Capacity planning
664
+
665
+ ### What to Master
666
+ - Mocking LLM calls
667
+ - Test dataset curation
668
+ - Evaluation metrics
669
+ - CI/CD integration
670
+
671
+ ---
672
+
673
+ ## 20. LangServe Deployment Nuances
674
+
675
+ Production deployment details.
676
+
677
+ ### Key Patterns
678
+
679
+ **Custom Endpoints**
680
+ - Custom input/output schemas
681
+ - Disable playground in production
682
+ - Custom error handling
683
+
684
+ **Authentication**
685
+ - Middleware for auth
686
+ - Token validation
687
+ - Role-based access
688
+
689
+ **Batch Endpoints**
690
+ - Automatic batch support
691
+ - Efficient processing
692
+ - Queue management
693
+
694
+ **Scaling**
695
+ - Horizontal scaling
696
+ - Load balancing
697
+ - Connection pooling
698
+
699
+ ### What to Master
700
+ - FastAPI middleware
701
+ - Authentication patterns
702
+ - Performance tuning
703
+ - Monitoring and logging
704
+
705
+ ---
706
+
707
+ ## Key Nuances Summary
708
+
709
+ | Area | Critical Nuance |
710
+ |------|-----------------|
711
+ | **LangGraph** | State must be serializable; use Pydantic |
712
+ | **Streaming** | Use `astream_events` for fine control |
713
+ | **Memory** | Token counting is crucial for long chats |
714
+ | **RAG** | Chunk size dramatically affects retrieval quality |
715
+ | **Tools** | Too many tools confuses the LLM (keep under 10-15) |
716
+ | **Callbacks** | Use async callbacks for non-blocking |
717
+ | **Caching** | Semantic cache > exact match cache |
718
+ | **Fallbacks** | Order matters; try cheapest/fastest first |
719
+ | **Evaluation** | LLM-as-judge is powerful but needs calibration |
720
+ | **Multi-agent** | Communication overhead can dominate |
721
+
722
+ ---
723
+
724
+ ## Interview-Worthy Project Ideas
725
+
726
+ 1. **LangGraph Multi-Agent Research System**
727
+ - Supervisor coordinates researcher, writer, reviewer agents
728
+ - Human approval before publishing
729
+ - Self-correction loop
730
+
731
+ 2. **Self-Correcting RAG System**
732
+ - Hallucination detection
733
+ - Automatic re-retrieval
734
+ - Quality scoring
735
+
736
+ 3. **Production Chatbot**
737
+ - Memory across sessions
738
+ - Streaming with progress
739
+ - Fallback chains
740
+ - Cost tracking
741
+
742
+ 4. **Code Assistant**
743
+ - Generate code
744
+ - Run tests
745
+ - Fix failures
746
+ - Iterate until passing
747
+
748
+ 5. **Research Agent**
749
+ - Web search
750
+ - Document analysis
751
+ - Citation tracking
752
+ - Human-in-the-loop approval
753
+
754
+ ---
755
+
756
+ ## What Interviewers Look For
757
+
758
+ | Question They Ask | What Impresses |
759
+ |-------------------|----------------|
760
+ | "How does it handle failures?" | Fallback chains, retries, graceful degradation |
761
+ | "How do you ensure quality?" | Self-checking, evaluation, human-in-the-loop |
762
+ | "How does it scale?" | Caching, batching, async, connection pooling |
763
+ | "How do agents coordinate?" | LangGraph, state machines, message passing |
764
+ | "How do you monitor it?" | LangSmith, custom callbacks, cost tracking |
765
+ | "How do you test it?" | Unit tests, regression tests, evaluation suites |
766
+
767
+ ---
768
+
769
+ ## Learning Path
770
+
771
+ 1. **Start**: Basic chains and prompts
772
+ 2. **Add**: Tools and agents
773
+ 3. **Upgrade**: RAG with advanced retrieval
774
+ 4. **Advanced**: LangGraph for stateful workflows
775
+ 5. **Production**: Streaming, caching, monitoring
776
+ 6. **Scale**: Multi-agent, human-in-the-loop
777
+ 7. **Master**: Evaluation, optimization, safety
778
+
779
+ ---
780
+
781
+ *Last Updated: February 2026*
782
+
my_practice/first_llm_call.ipynb ADDED
@@ -0,0 +1,276 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "f25e9940",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "from litellm import completion\n",
11
+ "\n",
12
+ "\n",
13
+ "result = completion(\n",
14
+ " model = 'gpt-4o',\n",
15
+ " messages = [{'role':'user', 'content' : 'Hello'}]\n",
16
+ "\n",
17
+ ")\n",
18
+ "\n",
19
+ "\n"
20
+ ]
21
+ },
22
+ {
23
+ "cell_type": "code",
24
+ "execution_count": 2,
25
+ "id": "fba08f3a",
26
+ "metadata": {},
27
+ "outputs": [
28
+ {
29
+ "data": {
30
+ "text/plain": [
31
+ "'Hello! How can I assist you today?'"
32
+ ]
33
+ },
34
+ "execution_count": 2,
35
+ "metadata": {},
36
+ "output_type": "execute_result"
37
+ }
38
+ ],
39
+ "source": [
40
+ "result.choices[0].message.content"
41
+ ]
42
+ },
43
+ {
44
+ "cell_type": "markdown",
45
+ "id": "c283cf21",
46
+ "metadata": {},
47
+ "source": [
48
+ "Building data models"
49
+ ]
50
+ },
51
+ {
52
+ "cell_type": "code",
53
+ "execution_count": null,
54
+ "id": "f4a41257",
55
+ "metadata": {},
56
+ "outputs": [],
57
+ "source": [
58
+ "from typing import Union, Literal\n",
59
+ "from dataclasses import dataclass, field\n",
60
+ "from pydantic import BaseModel, Field, List, Dict, Any, Optional, BaseTool\n",
61
+ "import uuid\n",
62
+ "from datetime import datetime\n",
63
+ "import json\n",
64
+ "\n",
65
+ "## agent models\n",
66
+ "\n",
67
+ "class Message(BaseModel):\n",
68
+ "\n",
69
+ " \"\"\"A text message in the conversation.\"\"\"\n",
70
+ " type: Literal[\"message\"] = \"message\"\n",
71
+ " role: Literal[\"system\", \"user\", \"assistant\"]\n",
72
+ " content: str\n",
73
+ "\n",
74
+ "class ToolCall(BaseModel): \n",
75
+ " \"\"\"LLM's request to execute a tool.\"\"\"\n",
76
+ " type: Literal[\"tool_call\"] = \"tool_call\"\n",
77
+ " tool_call_id: str\n",
78
+ " name: str\n",
79
+ " arguments: dict\n",
80
+ " \n",
81
+ "\n",
82
+ "class ToolResult(BaseModel):\n",
83
+ " \"\"\"Result from tool execution.\"\"\"\n",
84
+ " type: Literal[\"tool_result\"] = \"tool_result\"\n",
85
+ " tool_call_id: str\n",
86
+ " name: str\n",
87
+ " status: Literal[\"success\", \"error\"]\n",
88
+ " content: list\n",
89
+ "\n",
90
+ "class ToolConfirmation(BaseModel): ## this is temperory so not in union (user to agent)\n",
91
+ " \"\"\"User's decision on a pending tool call.\"\"\"\n",
92
+ " tool_call_id: str\n",
93
+ " approved: bool\n",
94
+ " modified_arguments: dict | None = None\n",
95
+ " reason: str | None = None # Reason for rejection (if not approved)\n",
96
+ "\n",
97
+ "class PendingToolCall(BaseModel): ## this is temperory so not in union(agent to user)\n",
98
+ " \"\"\"A tool call awaiting user confirmation.\"\"\"\n",
99
+ " \n",
100
+ " tool_call: ToolCall\n",
101
+ " confirmation_message: str\n",
102
+ "\n",
103
+ "## every request returns with these things so union all of them\n",
104
+ "ContentItem = Union[Message, ToolCall, ToolResult, ToolConfirmation] ## keep adding if there is more\n",
105
+ "\n",
106
+ "class Event(BaseModel):\n",
107
+ " \"\"\"A recorded occurrence during agent execution.\"\"\"\n",
108
+ " id: str = Field(default_factory=lambda: str(uuid.uuid4()))\n",
109
+ " execution_id: str\n",
110
+ " timestamp: float = Field(default_factory=lambda: datetime.now().timestamp())\n",
111
+ " author: str # \"user\" or agent name\n",
112
+ " content: List[ContentItem] = Field(default_factory=list)\n",
113
+ "\n",
114
+ "@dataclass\n",
115
+ "class ExecutionContext: ## there will be frequent modifications to this, so not basemodel\n",
116
+ " \"\"\"Central storage for all execution state.\"\"\"\n",
117
+ " \n",
118
+ " execution_id: str = field(default_factory=lambda: str(uuid.uuid4()))\n",
119
+ " events: List[Event] = field(default_factory=list)\n",
120
+ " current_step: int = 0\n",
121
+ " state: Dict[str, Any] = field(default_factory=dict)\n",
122
+ " final_result: Optional[str | BaseModel] = None\n",
123
+ " session_id: Optional[str] = None # Link to session for persistence\n",
124
+ "\n",
125
+ "\n",
126
+ "\n",
127
+ "### lets do LLM models\n",
128
+ "\n",
129
+ "class LlmRequest(BaseModel):\n",
130
+ " \"\"\"Request object for LLM calls.\"\"\"\n",
131
+ " instructions: List[str] = Field(default_factory=list)\n",
132
+ " contents: List[ContentItem] = Field(default_factory=list)\n",
133
+ " tools: List[BaseTool] = Field(default_factory=list)\n",
134
+ " tool_choice: Optional[str] = 'auto'\n",
135
+ "\n",
136
+ "class LlmResponse(BaseModel):\n",
137
+ " \"\"\"Response object from LLM calls.\"\"\"\n",
138
+ " content: List[ContentItem] = Field(default_factory=list)\n",
139
+ " error_message: Optional[str] = None\n",
140
+ " usage_metadata: Dict[str, Any] = Field(default_factory=dict)\n",
141
+ "\n",
142
+ "class LlmClient(BaseModel):\n",
143
+ " def _parse_response(self, response) -> LlmResponse:\n",
144
+ " \"\"\"Convert API response to LlmResponse.\"\"\"\n",
145
+ " choice = response.choices[0]\n",
146
+ " content_items = []\n",
147
+ " \n",
148
+ " # Parse message content\n",
149
+ " if choice.message.content:\n",
150
+ " content_items.append(Message(\n",
151
+ " role=\"assistant\",\n",
152
+ " content=choice.message.content\n",
153
+ " ))\n",
154
+ "\n",
155
+ " # Parse tool calls\n",
156
+ " if choice.message.tool_calls:\n",
157
+ " for tc in choice.message.tool_calls:\n",
158
+ " content_items.append(ToolCall(\n",
159
+ " tool_call_id=tc.id,\n",
160
+ " name=tc.function.name,\n",
161
+ " arguments=json.loads(tc.function.arguments)\n",
162
+ " ))\n",
163
+ " \n",
164
+ " return LlmResponse(\n",
165
+ " content=content_items,\n",
166
+ " usage_metadata={\n",
167
+ " \"input_tokens\": response.usage.prompt_tokens,\n",
168
+ " \"output_tokens\": response.usage.completion_tokens,\n",
169
+ " }\n",
170
+ " ) ## this is internal method to parse toolcalls, reasoning, message content\n",
171
+ " \n",
172
+ "\n",
173
+ "def build_messages(request: LlmRequest) -> List[dict]: ## will be reused everywhere\n",
174
+ " \"\"\"Convert LlmRequest to API message format.\"\"\"\n",
175
+ " messages = []\n",
176
+ " \n",
177
+ " # Add system instructions\n",
178
+ " for instruction in request.instructions:\n",
179
+ " messages.append({\"role\": \"system\", \"content\": instruction})\n",
180
+ " \n",
181
+ " # Convert content items\n",
182
+ " for item in request.contents:\n",
183
+ " if isinstance(item, Message):\n",
184
+ " messages.append({\"role\": item.role, \"content\": item.content})\n",
185
+ " \n",
186
+ " elif isinstance(item, ToolCall):\n",
187
+ " tool_call_dict = {\n",
188
+ " \"id\": item.tool_call_id,\n",
189
+ " \"type\": \"function\",\n",
190
+ " \"function\": {\n",
191
+ " \"name\": item.name,\n",
192
+ " \"arguments\": json.dumps(item.arguments)\n",
193
+ " }\n",
194
+ " }\n",
195
+ " # Append to previous assistant message if exists\n",
196
+ " if messages and messages[-1][\"role\"] == \"assistant\":\n",
197
+ " messages[-1].setdefault(\"tool_calls\", []).append(tool_call_dict)\n",
198
+ " else:\n",
199
+ " messages.append({\n",
200
+ " \"role\": \"assistant\",\n",
201
+ " \"content\": None,\n",
202
+ " \"tool_calls\": [tool_call_dict]\n",
203
+ " })\n",
204
+ " \n",
205
+ " elif isinstance(item, ToolResult):\n",
206
+ " messages.append({\n",
207
+ " \"role\": \"tool\",\n",
208
+ " \"tool_call_id\": item.tool_call_id,\n",
209
+ " \"content\": str(item.content[0]) if item.content else \"\"\n",
210
+ " })\n",
211
+ " \n",
212
+ " return messages\n",
213
+ "\n"
214
+ ]
215
+ },
216
+ {
217
+ "cell_type": "markdown",
218
+ "id": "d4b6afba",
219
+ "metadata": {},
220
+ "source": [
221
+ "Building our Agent"
222
+ ]
223
+ },
224
+ {
225
+ "cell_type": "code",
226
+ "execution_count": null,
227
+ "id": "2d7d0140",
228
+ "metadata": {},
229
+ "outputs": [],
230
+ "source": [
231
+ "from dataclasses import dataclass\n",
232
+ "from typing import List, Optional\n",
233
+ "from .llm import LlmClient\n",
234
+ "from .models import ExecutionContext\n",
235
+ "\n",
236
+ "class Agent:\n",
237
+ " \"\"\"Agent that can reason and use tools to solve tasks.\"\"\"\n",
238
+ " \n",
239
+ " def __init__(\n",
240
+ " self,\n",
241
+ " model: LlmClient,\n",
242
+ " tools: List[BaseTool] = None,\n",
243
+ " instructions: str = \"\",\n",
244
+ " max_steps: int = 5,\n",
245
+ " name: str = \"agent\"\n",
246
+ " ):\n",
247
+ " self.model = model\n",
248
+ " self.instructions = instructions\n",
249
+ " self.max_steps = max_steps\n",
250
+ " self.name = name\n",
251
+ " self.tools = tools or []"
252
+ ]
253
+ }
254
+ ],
255
+ "metadata": {
256
+ "kernelspec": {
257
+ "display_name": ".venv",
258
+ "language": "python",
259
+ "name": "python3"
260
+ },
261
+ "language_info": {
262
+ "codemirror_mode": {
263
+ "name": "ipython",
264
+ "version": 3
265
+ },
266
+ "file_extension": ".py",
267
+ "mimetype": "text/x-python",
268
+ "name": "python",
269
+ "nbconvert_exporter": "python",
270
+ "pygments_lexer": "ipython3",
271
+ "version": "3.12.11"
272
+ }
273
+ },
274
+ "nbformat": 4,
275
+ "nbformat_minor": 5
276
+ }
my_practice/pydantic.ipynb ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 16,
6
+ "id": "ff3b1200",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stdout",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "msg1.role: user\n",
14
+ "msg2.role: assistant\n",
15
+ "msg3.role: system\n",
16
+ "\n",
17
+ "Validation error: 1 validation error for Message\n",
18
+ "role\n",
19
+ " Input should be 'user', 'assistant' or 'system' [type=literal_error, input_value='admin', input_type=str]\n",
20
+ " For further information visit https://errors.pydantic.dev/2.11/v/literal_error\n",
21
+ "\n",
22
+ "Missing field error: 1 validation error for Message\n",
23
+ "content\n",
24
+ " Field required [type=missing, input_value={'role': 'user'}, input_type=dict]\n",
25
+ " For further information visit https://errors.pydantic.dev/2.11/v/missing\n"
26
+ ]
27
+ }
28
+ ],
29
+ "source": [
30
+ "from pydantic import BaseModel, ValidationError\n",
31
+ "from typing import Literal\n",
32
+ "\n",
33
+ "# Create a Message model like in your framework\n",
34
+ "class Message(BaseModel):\n",
35
+ " role: Literal[\"user\", \"assistant\", \"system\"]\n",
36
+ " content: str\n",
37
+ "\n",
38
+ "# Test 1: Valid messages\n",
39
+ "msg1 = Message(role=\"user\", content=\"Hello\")\n",
40
+ "msg2 = Message(role=\"assistant\", content=\"Hi there!\")\n",
41
+ "msg3 = Message(role=\"system\", content=\"You are helpful\")\n",
42
+ "\n",
43
+ "print(f\"msg1.role: {msg1.role}\")\n",
44
+ "print(f\"msg2.role: {msg2.role}\")\n",
45
+ "print(f\"msg3.role: {msg3.role}\")\n",
46
+ "\n",
47
+ "# Test 2: What happens with invalid role?\n",
48
+ "try:\n",
49
+ " bad_msg = Message(role=\"admin\", content=\"test\")\n",
50
+ "except ValidationError as e:\n",
51
+ " print(f\"\\nValidation error: {e}\")\n",
52
+ "\n",
53
+ "# Test 3: What happens with missing content?\n",
54
+ "try:\n",
55
+ " incomplete = Message(role=\"user\")\n",
56
+ "except ValidationError as e:\n",
57
+ " print(f\"\\nMissing field error: {e}\")"
58
+ ]
59
+ },
60
+ {
61
+ "cell_type": "code",
62
+ "execution_count": 27,
63
+ "id": "811107f4",
64
+ "metadata": {},
65
+ "outputs": [
66
+ {
67
+ "name": "stdout",
68
+ "output_type": "stream",
69
+ "text": [
70
+ "{\"role\":\"user\",\"content\":\"My Name is Akhil\",\"timestamp\":1769878310.697898}\n",
71
+ "{'role': 'user', 'content': 'My Name is Akhil', 'timestamp': 1769878310.697898}\n",
72
+ "user\n"
73
+ ]
74
+ }
75
+ ],
76
+ "source": [
77
+ "import datetime\n",
78
+ "from typing import Optional, List, Any, Dict\n",
79
+ "import uuid\n",
80
+ "from pydantic import Field\n",
81
+ "\n",
82
+ "class ChatMessage(BaseModel):\n",
83
+ " role : Literal[\"user\", \"assistant\", \"system\"]\n",
84
+ " content : str \n",
85
+ " timestamp : float = Field(default_factory=lambda: datetime.datetime.now().timestamp())\n",
86
+ "\n",
87
+ "class ChatSession(BaseModel):\n",
88
+ " session_id: str = Field(default_factory=lambda: str(uuid.uuid4()))\n",
89
+ " user_name : str\n",
90
+ " messages : List[ChatMessage] = Field(default_factory=list)\n",
91
+ " metadata : Dict[str, Any] = Field(default_factory=dict)\n",
92
+ "\n",
93
+ " def add_message(self, role: Literal[\"user\", \"assistant\", \"system\"], content: str):\n",
94
+ " self.messages.append(ChatMessage(role = role, content = content))\n",
95
+ "\n",
96
+ "\n",
97
+ "\n",
98
+ "chat = ChatMessage(role = \"user\", content = \"My Name is Akhil\")\n",
99
+ "\n",
100
+ "print(chat.model_dump_json())\n",
101
+ "print(chat.model_dump())\n",
102
+ "\n",
103
+ "msg2 = ChatMessage.model_validate({\"role\": \"user\", \"content\": \"hi\"})\n",
104
+ "print(msg2.role)\n",
105
+ "\n",
106
+ "\n",
107
+ "\n"
108
+ ]
109
+ },
110
+ {
111
+ "cell_type": "code",
112
+ "execution_count": 28,
113
+ "id": "a38ac16e",
114
+ "metadata": {},
115
+ "outputs": [
116
+ {
117
+ "name": "stdout",
118
+ "output_type": "stream",
119
+ "text": [
120
+ "Starting API 1...\n",
121
+ "Finished API 1\n",
122
+ "Starting API 2...\n",
123
+ "Finished API 2\n",
124
+ "Starting API 3...\n",
125
+ "Finished API 3\n",
126
+ "\n",
127
+ "Total time: 6.0 seconds\n",
128
+ "Results: Result from API 1, Result from API 2, Result from API 3\n"
129
+ ]
130
+ }
131
+ ],
132
+ "source": [
133
+ "import time\n",
134
+ "\n",
135
+ "def slow_api_call(name: str) -> str:\n",
136
+ " \"\"\"Simulate a slow API call (like calling OpenAI)\"\"\"\n",
137
+ " print(f\"Starting {name}...\")\n",
138
+ " time.sleep(2) # Blocks for 2 seconds\n",
139
+ " print(f\"Finished {name}\")\n",
140
+ " return f\"Result from {name}\"\n",
141
+ "\n",
142
+ "# Sequential calls - takes 6 seconds total\n",
143
+ "start = time.time()\n",
144
+ "\n",
145
+ "result1 = slow_api_call(\"API 1\")\n",
146
+ "result2 = slow_api_call(\"API 2\")\n",
147
+ "result3 = slow_api_call(\"API 3\")\n",
148
+ "\n",
149
+ "print(f\"\\nTotal time: {time.time() - start:.1f} seconds\")\n",
150
+ "print(f\"Results: {result1}, {result2}, {result3}\")"
151
+ ]
152
+ },
153
+ {
154
+ "cell_type": "code",
155
+ "execution_count": 32,
156
+ "id": "afc59f41",
157
+ "metadata": {},
158
+ "outputs": [
159
+ {
160
+ "name": "stdout",
161
+ "output_type": "stream",
162
+ "text": [
163
+ "Starting API 1...\n",
164
+ "Starting API 2...\n",
165
+ "Starting API 3...\n",
166
+ "Finished API 1\n",
167
+ "Finished API 2\n",
168
+ "Finished API 3\n",
169
+ "\n",
170
+ "Total time: 2.0 seconds\n",
171
+ "Results: ['Result from API 1', 'Result from API 2', 'Result from API 3'], Result from API 2, Result from API 3\n"
172
+ ]
173
+ }
174
+ ],
175
+ "source": [
176
+ "import time\n",
177
+ "import asyncio\n",
178
+ "\n",
179
+ "async def slow_api_call(name: str) -> str:\n",
180
+ " \"\"\"Simulate a slow API call (like calling OpenAI)\"\"\"\n",
181
+ " print(f\"Starting {name}...\")\n",
182
+ " await asyncio.sleep(2) # Blocks for 2 seconds\n",
183
+ " print(f\"Finished {name}\")\n",
184
+ " return f\"Result from {name}\"\n",
185
+ "\n",
186
+ "# Sequential calls - takes 6 seconds total\n",
187
+ "start = time.time()\n",
188
+ "\n",
189
+ "result1 = await asyncio.gather(\n",
190
+ " slow_api_call(\"API 1\"),\n",
191
+ "slow_api_call(\"API 2\"),\n",
192
+ "slow_api_call(\"API 3\")\n",
193
+ ")\n",
194
+ "\n",
195
+ "print(f\"\\nTotal time: {time.time() - start:.1f} seconds\")\n",
196
+ "print(f\"Results: {result1}, {result2}, {result3}\")"
197
+ ]
198
+ },
199
+ {
200
+ "cell_type": "code",
201
+ "execution_count": 34,
202
+ "id": "144c73f9",
203
+ "metadata": {},
204
+ "outputs": [
205
+ {
206
+ "name": "stdout",
207
+ "output_type": "stream",
208
+ "text": [
209
+ "['hi', 'hi', 'hi']\n"
210
+ ]
211
+ }
212
+ ],
213
+ "source": [
214
+ "async def fetch_weather(city: str) -> str:\n",
215
+ " await asyncio.sleep(2)\n",
216
+ " return \"hi\"\n",
217
+ "\n",
218
+ "async def fetch_news(news: str) -> str:\n",
219
+ " await asyncio.sleep(1.5)\n",
220
+ " return \"hi\"\n",
221
+ "\n",
222
+ "async def fetch_stock(symbool: str) -> str:\n",
223
+ " await asyncio.sleep(1)\n",
224
+ " return \"hi\"\n",
225
+ "\n",
226
+ "\n",
227
+ "results = await asyncio.gather(\n",
228
+ " fetch_weather(\"hyd\"), fetch_news(\"hyd\"), fetch_stock(\"hyd\")\n",
229
+ " )\n",
230
+ "print(results)\n"
231
+ ]
232
+ }
233
+ ],
234
+ "metadata": {
235
+ "kernelspec": {
236
+ "display_name": ".venv",
237
+ "language": "python",
238
+ "name": "python3"
239
+ },
240
+ "language_info": {
241
+ "codemirror_mode": {
242
+ "name": "ipython",
243
+ "version": 3
244
+ },
245
+ "file_extension": ".py",
246
+ "mimetype": "text/x-python",
247
+ "name": "python",
248
+ "nbconvert_exporter": "python",
249
+ "pygments_lexer": "ipython3",
250
+ "version": "3.12.11"
251
+ }
252
+ },
253
+ "nbformat": 4,
254
+ "nbformat_minor": 5
255
+ }