langgraph-patterns
Skill4 starsChanged 8 months agoMITArchived repositoryView on GitHub
Load when working with: LangGraph state machines, agent nodes, tool definitions, checkpointers, human-in-the-loop interrupts, multi-agent coordination. LangGraph >=0.2.0 (langgraph-checkpoint for persistence). Always pin exact version in pyproject.toml. LangGraph models agent workflows as directed graphs: - State: typed dict passed between nodes (the single source of truth) - Nodes: Python async functions that receive and return state updates - Edges: routing logic — conditional or unconditional - Checkpointer: persistence layer for long-running agents (SQLite locally, PostgreSQL in production) Use Annotated[list, operator.add]…
3 other projects use a version of this.
Adopted by
Most recently taken up by
- frankxai/skillstheir own version, first seen Sep 30, 2026
- Bbar0n234/learnflow-aitheir own version, first seen Aug 11, 2026
- kaushik-holla/agent-skillstheir own version, first seen Jun 2, 2026
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- Bbar0n234/learnflow-ai★ 35same name
- kaushik-holla/agent-skills★ 2same name
- frankxai/skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository23 other files it gives its agents.
- .claude/CLAUDE.mdCLAUDE.md
- llms.txtllms.txt
- claude-api-patternsSkill
- critical-analysisSkill
- database-migration-safetySkill
- data-validationSkill
- design-doc-creatorSkill
- experiment-trackingSkill
- fastapi-patternsSkill
- github-actionsSkill
- htmx-frontendSkill
- infra-yandex-cloudSkill
- ml-data-handlingSkill
- multimodal-routerSkill
- nlp-slm-patternsSkill
- predictive-analyticsSkill
- prompt-engineeringSkill
- python-project-standardsSkill
- rag-vector-dbSkill
- skill-developerSkill
- supply-chain-auditorSkill
- test-first-patternsSkill
- windows-developerSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 10
Always pin exact version in pyproject.toml.
- Very specific: line 54
Use Annotated[list, operator.add] for lists that nodes append to.
- Distinctive: line 55
Use plain types for values that nodes replace entirely.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
LangGraph Patterns
When to Load This Skill
Load when working with: LangGraph state machines, agent nodes, tool definitions, checkpointers, human-in-the-loop interrupts, multi-agent coordination.
Current Version
LangGraph >=0.2.0 (langgraph-checkpoint for persistence).
Always pin exact version in pyproject.toml.
Core Concepts
LangGraph models agent workflows as directed graphs:
- State: typed dict passed between nodes (the single source of truth)
- Nodes: Python async functions that receive and return state updates
- Edges: routing logic — conditional or unconditional
- Checkpointer: persistence layer for long-running agents (SQLite locally, PostgreSQL in production)
Standard Project Structure
src/{project_name}/
├── agents/
│ ├── __init__.py
│ ├── graph.py # graph assembly
│ ├── state.py # TypedDict state definition
│ ├── nodes/
│ │ ├── __init__.py
│ │ ├── analyst.py
│ │ └── writer.py
│ └── tools/
│ ├── __init__.py
│ └── search.pyState Definition Pattern
from typing import Annotated
from typing_extensions import TypedDict
import operator
class AgentState(TypedDict):
messages: Annotated[list[dict], operator.add]
user_input: str
retrieved_context: list[str]
final_answer: str | None
error: str | None
iteration_count: intUse Annotated[list, operator.add] for lists that nodes append to.
Use plain types for values that nodes replace entirely.
Node Pattern
from langchain_core.messages import AIMessage
from src.project_name.agents.state import AgentState
from src.project_name.adapters.llm.claude_adapter import ClaudeAdapter
async def analyst_node(state: AgentState) -> dict:
adapter = ClaudeAdapter()
response = await adapter.invoke(
system="You are a precise analyst. Answer based only on retrieved context.",
messages=state["messages"],
context=state["retrieved_context"],
)
return {
"messages": [AIMessage(content=response)],
"final_answer": response,
}Nodes return ONLY the fields they modify — LangGraph merges the rest automatically.
Graph Assembly Pattern
from langgraph.graph import END, StateGraph
from langgraph.checkpoint.sqlite.aio import AsyncSqliteSaver
from src.project_name.agents.state import AgentState
from src.project_name.agents.nodes.analyst import analyst_node
from src.project_name.agents.nodes.retriever import retriever_node
def should_continue(state: AgentState) -> str:
if state.get("error"):
return "handle_error"
if state.get("final_answer"):
return END
return "analyst"
def build_graph(checkpointer=None) -> StateGraph:
graph = StateGraph(AgentState)
graph.add_node("retriever", retriever_node)
graph.add_node("analyst", analyst_node)
graph.set_entry_point("retriever")
graph.add_edge("retriever", "analyst")
graph.add_conditional_edges("analyst", should_continue)
return graph.compile(checkpointer=checkpointer)Checkpointer Setup (Production)
from langgraph.checkpoint.postgres.aio import AsyncPostgresSaver
async def get_checkpointer(connection_string: str) -> AsyncPostgresSaver:
checkpointer = AsyncPostgresSaver.from_conn_string(connection_string)
await checkpointer.setup()
return checkpointerFor local development, use AsyncSqliteSaver:
from langgraph.checkpoint.sqlite.aio import AsyncSqliteSaver
checkpointer = AsyncSqliteSaver.from_conn_string("checkpoints.db")Human-in-the-Loop Pattern
from langgraph.types import interrupt
async def approval_node(state: AgentState) -> dict:
decision = interrupt({
"question": "Approve this action?",
"proposed_action": state["planned_action"],
})
return {"approved": decision == "yes"}Resume after human input:
graph.invoke(
None,
config={"configurable": {"thread_id": thread_id}},
command={"resume": "yes"},
)Claude Adapter for LangGraph
from anthropic import AsyncAnthropic
from src.project_name.core.config import settings
class ClaudeAdapter:
def __init__(self) -> None:
self._client = AsyncAnthropic()
async def invoke(
self,
system: str,
messages: list[dict],
context: list[str] | None = None,
) -> str:
system_prompt = system
if context:
system_prompt += f"\n\nContext:\n" + "\n".join(context)
response = await self._client.messages.create(
model="claude-sonnet-4-6",
max_tokens=4096,
system=system_prompt,
messages=messages,
)
return response.content[0].textTool Definition Pattern
from langchain_core.tools import tool
@tool
async def search_knowledge_base(query: str) -> str:
"""Search the knowledge base for relevant documents.
Args:
query: The search query in natural language.
Returns:
Relevant document excerpts as a single string.
"""
results = await kb_adapter.search(query, top_k=5)
return "\n\n".join(r.text for r in results)FastAPI Integration
from fastapi import APIRouter
from langgraph.types import Command
router = APIRouter()
_graph = None
def get_graph():
global _graph
if _graph is None:
_graph = build_graph(checkpointer=get_checkpointer(...))
return _graph
@router.post("/chat")
async def chat(request: ChatRequest) -> ChatResponse:
graph = get_graph()
config = {"configurable": {"thread_id": request.thread_id}}
result = await graph.ainvoke(
{"user_input": request.message, "messages": []},
config=config,
)
return ChatResponse(answer=result["final_answer"])Further Resources
resources/streaming.md— SSE streaming responses from LangGraphresources/multi-agent.md— supervisor pattern for multi-agent coordinationresources/testing-agents.md— testing LangGraph graphs with pytest
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

