langgraph学习案例
- Python 100%
| 01-basics | ||
| 02-langgraph-core | ||
| 03-langgraph-advanced | ||
| 04-rag | ||
| 05-agents | ||
| 06-multi-agent | ||
| common | ||
| tests | ||
| .gitignore | ||
| CLAUDE.md | ||
| langgraph.json | ||
| pyproject.toml | ||
| README.md | ||
| run_gateway.py | ||
| TODO.md | ||
| uv.lock | ||
LangGraph Examples
LangGraph & LangChain 教学示例集,从基础到进阶,每个示例独立可运行。
项目结构
├── 01-basics/ # LangChain 基础
│ ├── 01_hello_llm.py # 最简 LLM 调用
│ ├── 02_prompt_template.py # Prompt 模板
│ ├── 03_chains.py # Chain 基础 (LCEL)
│ └── 04_output_parser.py # 结构化输出解析
│
├── 02-langgraph-core/ # LangGraph 核心
│ ├── 01_simple_graph.py # 最简 StateGraph
│ ├── 02_state.py # State 定义与累加
│ ├── 03_nodes_edges.py # 多节点管道
│ └── 04_conditional.py # 条件边/分支路由
│
├── 03-langgraph-advanced/ # LangGraph 进阶
│ ├── 01_cycle_loop.py # 循环图(迭代优化)
│ ├── 02_human_in_loop.py # 人在回路 (interrupt)
│ ├── 03_memory.py # 对话记忆 (checkpointer)
│ └── 04_streaming.py # 流式输出
│
├── 04-rag/ # RAG 检索增强
│ ├── 01_basic_rag.py # 基础 RAG 流程
│ ├── 02_vector_store.py # 文档切分与向量存储
│ └── 03_rag_graph.py # LangGraph 构建 RAG
│
├── 05-agents/ # Agent 智能体
│ ├── 01_tool_use.py # 工具调用
│ ├── 02_react_agent.py # ReAct 模式 Agent
│ └── 03_custom_tools.py # 自定义工具 (Pydantic)
│
└── 06-multi-agent/ # 多智能体
├── 01_supervisor.py # 监督者模式
├── 02_hierarchical.py # 层级模式
└── 03_swarm.py # Swarm 交接模式
快速开始
# 安装依赖
uv sync
# 运行任意示例
uv run python 01-basics/01_hello_llm.py
环境变量
export OPENAI_API_KEY="your-key"
参考文档
License
MIT