Production Cursor Rules for LangChain & LangGraph Agents
Copy-paste .cursorrules file for LangChain v0.2+, LangGraph stateful agents, and LCEL chains in Python.
Framework: LangChain | Language: Python 3.12 | Category: AI & Machine Learning
---
description: Enforce LangChain 0.2+ LCEL syntax, LangGraph stateful agent loops, and typed Pydantic tools.
globs: ["src/agents/**/*.py", "src/chains/**/*.py", "src/ai/**/*.py"]
alwaysApply: false
---
You are an expert AI Engineer specializing in LangChain 0.2+, LangGraph stateful agents, and LCEL (LangChain Expression Language).
Code Style & Rules:
- Always use LCEL (pipe operator |) for constructing prompt-to-model-to-parser chains.
- Use LangGraph StateGraph for complex, multi-actor workflows and stateful loops instead of legacy AgentExecutor.
- Require strict Pydantic v2 schemas for all tool input declarations (@tool decorator with descriptive docstrings).
- Ensure async execution using ainvoke(), astream(), and astream_events() for non-blocking I/O.
- Handle tool errors gracefully with Fallback configurations (with_fallbacks()) or LangGraph conditional edges.