YUNOVA · AI Agents
Module 11: LangChain and LangGraph
What LangChain and LangGraph are
Key points
- LangChain LLM applications बनाने का framework है, जिसमें models, prompts, tools और retrievers के तैयार हिस्से मिलते हैं।
- LangGraph agents को graph के रूप में बनाता है: nodes (steps), edges (रास्ते) और साझा state।
- LangSmith उसी टीम का tool है जो tracing, debugging और evaluation के लिए इस्तेमाल होता है।
Chains and runnables
Key points
- LangChain में Runnable एक साझा interface है, जिसमें invoke, batch और stream जैसे methods होते हैं।
- Prompt, model और output parser सभी Runnables हैं और इन्हें जोड़कर chain बनती है।
- LCEL में | (pipe) operator से Runnables जोड़े जाते हैं, जैसे prompt | model | parser।
Building a graph of steps
Key points
- LangGraph में हर node एक function है जो state लेता है और state का update लौटाता है।
- Edges तय करते हैं कि एक node के बाद कौन-सा node चलेगा; conditional edges state देखकर रास्ता चुनते हैं।
- Graph बनाकर compile किया जाता है और फिर invoke करके चलाया जाता है।
State and checkpoints in LangGraph
Key points
- State वह data है जो graph के सभी nodes के बीच साझा होता है, जैसे messages की list।
- Checkpointer हर step के बाद state save करता है, जिससे बातचीत thread_id के हिसाब से बाद में जारी रह सकती है।
- Checkpoints से रुका हुआ run दोबारा शुरू करना और human approval के लिए बीच में रुकना संभव होता है।
Multi-agent setups
Key points
- Multi-agent setup में काम कई विशेष agents में बँटता है, जैसे research agent और writer agent।
- Supervisor pattern में एक मुख्य agent तय करता है कि कौन-सा agent अगला काम करेगा।
- LangGraph में हर agent को एक node या subgraph बनाकर जोड़ा जा सकता है।
- ज़्यादा agents से cost और जटिलता बढ़ती है, इसलिए ज़रूरत होने पर ही इस्तेमाल करें।