langgraph — Cursor rule: build agent graphs that stay readable
A Cursor rule with LangGraph practices: how to split nodes, state and subgraphs in a Python project.
.cursor/rules/langgraph.mdcWhat langgraph does
The rule attaches to **/*.py files and sets a style for LangGraph work. The core idea: one job per node, and repeated pieces move into subgraphs. Graphs should stay acyclic where possible, with cycles reserved for feedback loops that actually need them.
Inside are code samples: StateGraph, a TypedDict for state, node functions that return updated state, and a subgraph wired with add_node, add_edge, set_entry_point and set_finish_point. This is not a library or a plugin — it is a rules file Cursor reads as context. So installing it means dropping langgraph.mdc into .cursor/rules/.
The rule is tied to Python, so it does nothing in a TypeScript project. And keep in mind it is advice, not a type checker: Cursor nudges the model toward these patterns, and the model can still drift.
What it helps with
- split agent logic into nodes with one job each
- move repeated steps into a reusable subgraph
- describe agent state with
TypedDict - wire a graph with an entry point and a finish point
- decide when a cycle in the graph earns its place
Example prompts for the agent
- build a LangGraph graph for request handling: a fetch node, an analyze node, an edge between them
- move context preparation into a subgraph and plug it into the main graph
- define the agent state with TypedDict and add a node that appends messages
How to install langgraph
Manually: put the files in place
.cursor/rules/langgraph.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.claude/rules/langgraph.mdThe paths frontmatter field limits the files: move globs from the source into paths
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.github/instructions/langgraph.instructions.mdThe applyTo field sets which files it applies to: move globs from the source into applyTo
Manually: put the files in place
.devin/rules/langgraph.mdManually: put the files in place
.clinerules/langgraph.mdStep by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules
Questions about langgraph
How do I install langgraph in Cursor?
Create .cursor/rules/langgraph.mdc in your project root and paste the rule contents into it. Cursor picks it up automatically for files matching **/*.py.
What does this rule do?
It sets practices for building LangGraph agent graphs: one responsibility per node, subgraphs for repeated patterns, a preference for acyclic graphs. Python examples with StateGraph are included.
Which files does the rule apply to?
The glob **/*.py, so Python files in the project. It does not apply in projects written in other languages.
Source text
langgraph.mdc · CC0-1.0
---
description: This guide provides definitive best practices for building robust, maintainable, and performant AI agent workflows using LangGraph.
globs: **/*.py
---
# langgraph Best Practices
## Code Organization and Structure
### 1. Explicit Graph Topology & Modularity
Define clear, single responsibilities for each node. Encapsulate common patterns into reusable subgraphs. Prefer Directed Acyclic Graphs (DAGs); use cycles only when essential for feedback loops.
✅ GOOD: Focused nodes, composable subgraphs
```python
from langgraph.graph import StateGraph, END
from typing import TypedDict, List
class AgentState(TypedDict):
messages: List[str]
tool_output: str | None
def fetch_data_node(state: AgentState) -> AgentState:
return {"messages": state["messages"] + ["Data fetched."]}
def analyze_data_node(state: AgentState) -> AgentState:
return {"messages": state["messages"] + ["Data analyzed."]}
def build_subgraph():
builder = StateGraph(AgentState)
builder.add_node("fetch", fetch_data_node)
builder.add_node("analyze", analyze_data_node)
builder.add_edge("fetch", "analyze")
builder.set_entry_point("fetch")
builder.set_finish_point("analyze")
return builder.compile()
```
### 2. Functional API Preference
Prior
© sanjeed5 · CC0-1.0 · sanjeed5/awesome-cursor-rules-mdc