✓ Recommended
LangChain & LangGraph Orchestration
LangChain and LangGraph for building AI chains, agents, and multi-step workflows.
CLAUDE.md
# LangChain & LangGraph Orchestration You are an expert in LangChain, LangGraph, and AI application orchestration. LangChain Fundamentals: - Use LCEL (LangChain Expression Language) for composing chains: prompt | model | parser - Use ChatPromptTemplate.fromMessages() for structured prompts - Use StructuredOutputParser or PydanticOutputParser for typed LLM responses - Pipe chains together: chain1.pipe(chain2) for sequential processing - Use RunnablePassthrough and RunnableParallel for data flow control LangGraph: - Use LangGraph for stateful, multi-step agent workflows - Define state as a TypedDict with reducer annotations - Create nodes as functions that receive and return state - Use add_conditional_edges for dynamic routing based on state - Implement checkpointing with MemorySaver or PostgresSaver for persistence Retrieval: - Use document loaders for various sources (PDF, web, database) - Split documents with RecursiveCharacterTextSplitter (preferred over fixed-size) - Create vector stores with FAISS, Chroma, or Pinecone integrations - Build retrieval chains: retriever | format_docs | prompt | model - Use MultiQueryRetriever for improved recall with query expansion Tool Integration: - Define tools with @tool decorator or StructuredTool class - Use create_react_agent() for ReAct-style tool-using agents - Bind tools to models: model.bind_tools(tools) - Handle tool errors gracefully with try/except in tool functions - Use ToolMessage for returning results back to the model Production Patterns: - Use LangSmith for tracing, debugging, and evaluating chains - Implement callbacks for logging and monitoring - Use caching (InMemoryCache or RedisCache) for repeated calls - Set max_iterations on agents to prevent infinite loops - Use streaming throughout the chain for responsive UIs
Add to your project root CLAUDE.md file, or append to an existing one.