[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-165e9879-72f3-477d-a32a-78db4a9034e2":3,"$foEKFnhFru_xtFTDdQ4HvT6JFnyfgSeLH1KERyL4pWJM":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"165e9879-72f3-477d-a32a-78db4a9034e2","langgraph","LangGraph专家 - 构建生产级框架的专家","cat_prod_data","mod_productivity","sickn33,productivity","---\nname: langgraph\ndescription: Expert in LangGraph - the production-grade framework for building\n  stateful, multi-actor AI applications. Covers graph construction, state\n  management, cycles and branches, persistence with checkpointers,\n  human-in-the-loop patterns, and the ReAct agent pattern.\nrisk: unknown\nsource: vibeship-spawner-skills (Apache 2.0)\ndate_added: 2026-02-27\n---\n\n# LangGraph\n\nExpert in LangGraph - the production-grade framework for building stateful, multi-actor\nAI applications. Covers graph construction, state management, cycles and branches,\npersistence with checkpointers, human-in-the-loop patterns, and the ReAct agent pattern.\nUsed in production at LinkedIn, Uber, and 400+ companies. This is LangChain's recommended\napproach for building agents.\n\n**Role**: LangGraph Agent Architect\n\nYou are an expert in building production-grade AI agents with LangGraph. You\nunderstand that agents need explicit structure - graphs make the flow visible\nand debuggable. You design state carefully, use reducers appropriately, and\nalways consider persistence for production. You know when cycles are needed\nand how to prevent infinite loops.\n\n### Expertise\n\n- Graph topology design\n- State schema patterns\n- Conditional branching\n- Persistence strategies\n- Human-in-the-loop\n- Tool integration\n- Error handling and recovery\n\n## Capabilities\n\n- Graph construction (StateGraph)\n- State management and reducers\n- Node and edge definitions\n- Conditional routing\n- Checkpointers and persistence\n- Human-in-the-loop patterns\n- Tool integration\n- Streaming and async execution\n\n## Prerequisites\n\n- 0: Python proficiency\n- 1: LLM API basics\n- 2: Async programming concepts\n- 3: Graph theory fundamentals\n- Required skills: Python 3.9+, langgraph package, LLM API access (OpenAI, Anthropic, etc.), Understanding of graph concepts\n\n## Scope\n\n- 0: Python-only (TypeScript in early stages)\n- 1: Learning curve for graph concepts\n- 2: State management complexity\n- 3: Debugging can be challenging\n\n## Ecosystem\n\n### Primary\n\n- LangGraph\n- LangChain\n- LangSmith (observability)\n\n### Common_integrations\n\n- OpenAI \u002F Anthropic \u002F Google\n- Tavily (search)\n- SQLite \u002F PostgreSQL (persistence)\n- Redis (state store)\n\n### Platforms\n\n- Python applications\n- FastAPI \u002F Flask backends\n- Cloud deployments\n\n## Patterns\n\n### Basic Agent Graph\n\nSimple ReAct-style agent with tools\n\n**When to use**: Single agent with tool calling\n\nfrom typing import Annotated, TypedDict\nfrom langgraph.graph import StateGraph, START, END\nfrom langgraph.graph.message import add_messages\nfrom langgraph.prebuilt import ToolNode\nfrom langchain_openai import ChatOpenAI\nfrom langchain_core.tools import tool\n\n# 1. Define State\nclass AgentState(TypedDict):\n    messages: Annotated[list, add_messages]\n    # add_messages reducer appends, doesn't overwrite\n\n# 2. Define Tools\n@tool\ndef search(query: str) -> str:\n    \"\"\"Search the web for information.\"\"\"\n    # Implementation here\n    return f\"Results for: {query}\"\n\n@tool\ndef calculator(expression: str) -> str:\n    \"\"\"Evaluate a math expression.\"\"\"\n    return str(eval(expression))\n\ntools = [search, calculator]\n\n# 3. Create LLM with tools\nllm = ChatOpenAI(model=\"gpt-4o\").bind_tools(tools)\n\n# 4. Define Nodes\ndef agent(state: AgentState) -> dict:\n    \"\"\"The agent node - calls LLM.\"\"\"\n    response = llm.invoke(state[\"messages\"])\n    return {\"messages\": [response]}\n\n# Tool node handles tool execution\ntool_node = ToolNode(tools)\n\n# 5. Define Routing\ndef should_continue(state: AgentState) -> str:\n    \"\"\"Route based on whether tools were called.\"\"\"\n    last_message = state[\"messages\"][-1]\n    if last_message.tool_calls:\n        return \"tools\"\n    return END\n\n# 6. Build Graph\ngraph = StateGraph(AgentState)\n\n# Add nodes\ngraph.add_node(\"agent\", agent)\ngraph.add_node(\"tools\", tool_node)\n\n# Add edges\ngraph.add_edge(START, \"agent\")\ngraph.add_conditional_edges(\"agent\", should_continue, [\"tools\", END])\ngraph.add_edge(\"tools\", \"agent\")  # Loop back\n\n# Compile\napp = graph.compile()\n\n# 7. Run\nresult = app.invoke({\n    \"messages\": [(\"user\", \"What is 25 * 4?\")]\n})\n\n### State with Reducers\n\nComplex state management with custom reducers\n\n**When to use**: Multiple agents updating shared state\n\nfrom typing import Annotated, TypedDict\nfrom operator import add\nfrom langgraph.graph import StateGraph\n\n# Custom reducer for merging dictionaries\ndef merge_dicts(left: dict, right: dict) -> dict:\n    return {**left, **right}\n\n# State with multiple reducers\nclass ResearchState(TypedDict):\n    # Messages append (don't overwrite)\n    messages: Annotated[list, add_messages]\n\n    # Research findings merge\n    findings: Annotated[dict, merge_dicts]\n\n    # Sources accumulate\n    sources: Annotated[list[str], add]\n\n    # Current step (overwrites - no reducer)\n    current_step: str\n\n    # Error count (custom reducer)\n    errors: Annotated[int, lambda a, b: a + b]\n\n# Nodes return partial state updates\ndef researcher(state: ResearchState) -> dict:\n    # Only return fields being updated\n    return {\n        \"findings\": {\"topic_a\": \"New finding\"},\n        \"sources\": [\"source1.com\"],\n        \"current_step\": \"researching\"\n    }\n\ndef writer(state: ResearchState) -> dict:\n    # Access accumulated state\n    all_findings = state[\"findings\"]\n    all_sources = state[\"sources\"]\n\n    return {\n        \"messages\": [(\"assistant\", f\"Report based on {len(all_sources)} sources\")],\n        \"current_step\": \"writing\"\n    }\n\n# Build graph\ngraph = StateGraph(ResearchState)\ngraph.add_node(\"researcher\", researcher)\ngraph.add_node(\"writer\", writer)\n# ... add edges\n\n### Conditional Branching\n\nRoute to different paths based on state\n\n**When to use**: Multiple possible workflows\n\nfrom langgraph.graph import StateGraph, START, END\n\nclass RouterState(TypedDict):\n    query: str\n    query_type: str\n    result: str\n\ndef classifier(state: RouterState) -> dict:\n    \"\"\"Classify the query type.\"\"\"\n    query = state[\"query\"].lower()\n    if \"code\" in query or \"program\" in query:\n        return {\"query_type\": \"coding\"}\n    elif \"search\" in query or \"find\" in query:\n        return {\"query_type\": \"search\"}\n    else:\n        return {\"query_type\": \"chat\"}\n\ndef coding_agent(state: RouterState) -> dict:\n    return {\"result\": \"Here's your code...\"}\n\ndef search_agent(state: RouterState) -> dict:\n    return {\"result\": \"Search results...\"}\n\ndef chat_agent(state: RouterState) -> dict:\n    return {\"result\": \"Let me help...\"}\n\n# Routing function\ndef route_query(state: RouterState) -> str:\n    \"\"\"Route to appropriate agent.\"\"\"\n    query_type = state[\"query_type\"]\n    return query_type  # Returns node name\n\n# Build graph\ngraph = StateGraph(RouterState)\n\ngraph.add_node(\"classifier\", classifier)\ngraph.add_node(\"coding\", coding_agent)\ngraph.add_node(\"search\", search_agent)\ngraph.add_node(\"chat\", chat_agent)\n\ngraph.add_edge(START, \"classifier\")\n\n# Conditional edges from classifier\ngraph.add_conditional_edges(\n    \"classifier\",\n    route_query,\n    {\n        \"coding\": \"coding\",\n        \"search\": \"search\",\n        \"chat\": \"chat\"\n    }\n)\n\n# All agents lead to END\ngraph.add_edge(\"coding\", END)\ngraph.add_edge(\"search\", END)\ngraph.add_edge(\"chat\", END)\n\napp = graph.compile()\n\n### Persistence with Checkpointer\n\nSave and resume agent state\n\n**When to use**: Multi-turn conversations, long-running agents\n\nfrom langgraph.graph import StateGraph\nfrom langgraph.checkpoint.sqlite import SqliteSaver\nfrom langgraph.checkpoint.postgres import PostgresSaver\n\n# SQLite for development\nmemory = SqliteSaver.from_conn_string(\":memory:\")\n# Or persistent file\nmemory = SqliteSaver.from_conn_string(\"agent_state.db\")\n\n# PostgreSQL for production\n# memory = PostgresSaver.from_conn_string(DATABASE_URL)\n\n# Compile with checkpointer\napp = graph.compile(checkpointer=memory)\n\n# Run with thread_id for conversation continuity\nconfig = {\"configurable\": {\"thread_id\": \"user-123-session-1\"}}\n\n# First message\nresult1 = app.invoke(\n    {\"messages\": [(\"user\", \"My name is Alice\")]},\n    config=config\n)\n\n# Second message - agent remembers context\nresult2 = app.invoke(\n    {\"messages\": [(\"user\", \"What's my name?\")]},\n    config=config\n)\n# Agent knows name is Alice!\n\n# Get conversation history\nstate = app.get_state(config)\nprint(state.values[\"messages\"])\n\n# List all checkpoints\nfor checkpoint in app.get_state_history(config):\n    print(checkpoint.config, checkpoint.values)\n\n### Human-in-the-Loop\n\nPause for human approval before actions\n\n**When to use**: Sensitive operations, review before execution\n\nfrom langgraph.graph import StateGraph, START, END\n\nclass ApprovalState(TypedDict):\n    messages: Annotated[list, add_messages]\n    pending_action: dict | None\n    approved: bool\n\ndef agent(state: ApprovalState) -> dict:\n    # Agent decides on action\n    action = {\"type\": \"send_email\", \"to\": \"user@example.com\"}\n    return {\n        \"pending_action\": action,\n        \"messages\": [(\"assistant\", f\"I want to: {action}\")]\n    }\n\ndef execute_action(state: ApprovalState) -> dict:\n    action = state[\"pending_action\"]\n    # Execute the approved action\n    result = f\"Executed: {action['type']}\"\n    return {\n        \"messages\": [(\"assistant\", result)],\n        \"pending_action\": None\n    }\n\ndef should_execute(state: ApprovalState) -> str:\n    if state.get(\"approved\"):\n        return \"execute\"\n    return END  # Wait for approval\n\n# Build graph\ngraph = StateGraph(ApprovalState)\ngraph.add_node(\"agent\", agent)\ngraph.add_node(\"execute\", execute_action)\n\ngraph.add_edge(START, \"agent\")\ngraph.add_conditional_edges(\"agent\", should_execute, [\"execute\", END])\ngraph.add_edge(\"execute\", END)\n\n# Compile with interrupt_before for human review\napp = graph.compile(\n    checkpointer=memory,\n    interrupt_before=[\"execute\"]  # Pause before execution\n)\n\n# Run until interrupt\nconfig = {\"configurable\": {\"thread_id\": \"approval-flow\"}}\nresult = app.invoke({\"messages\": [(\"user\", \"Send report\")]}, config)\n\n# Agent paused - get pending state\nstate = app.get_state(config)\npending = state.values[\"pending_action\"]\nprint(f\"Pending: {pending}\")  # Human reviews\n\n# Human approves - update state and continue\napp.update_state(config, {\"approved\": True})\nresult = app.invoke(None, config)  # Resume\n\n### Parallel Execution (Map-Reduce)\n\nRun multiple branches in parallel\n\n**When to use**: Parallel research, batch processing\n\nfrom langgraph.graph import StateGraph, START, END, Send\nfrom langgraph.constants import Send\n\nclass ParallelState(TypedDict):\n    topics: list[str]\n    results: Annotated[list[str], add]\n    summary: str\n\ndef research_topic(state: dict) -> dict:\n    \"\"\"Research a single topic.\"\"\"\n    topic = state[\"topic\"]\n    result = f\"Research on {topic}...\"\n    return {\"results\": [result]}\n\ndef summarize(state: ParallelState) -> dict:\n    \"\"\"Combine all research results.\"\"\"\n    all_results = state[\"results\"]\n    summary = f\"Summary of {len(all_results)} topics\"\n    return {\"summary\": summary}\n\ndef fanout_topics(state: ParallelState) -> list[Send]:\n    \"\"\"Create parallel tasks for each topic.\"\"\"\n    return [\n        Send(\"research\", {\"topic\": topic})\n        for topic in state[\"topics\"]\n    ]\n\n# Build graph\ngraph = StateGraph(ParallelState)\ngraph.add_node(\"research\", research_topic)\ngraph.add_node(\"summarize\", summarize)\n\n# Fan out to parallel research\ngraph.add_conditional_edges(START, fanout_topics, [\"research\"])\n# All research nodes lead to summarize\ngraph.add_edge(\"research\", \"summarize\")\ngraph.add_edge(\"summarize\", END)\n\napp = graph.compile()\n\nresult = app.invoke({\n    \"topics\": [\"AI\", \"Climate\", \"Space\"],\n    \"results\": []\n})\n# Research runs in parallel, then summarizes\n\n## Collaboration\n\n### Delegation Triggers\n\n- crewai|role-based|crew -> crewai (Need role-based multi-agent approach)\n- observability|tracing|langsmith -> langfuse (Need LLM observability)\n- structured output|json schema -> structured-output (Need structured LLM responses)\n- evaluate|benchmark|test agent -> agent-evaluation (Need to evaluate agent performance)\n\n### Production Agent Stack\n\nSkills: langgraph, langfuse, structured-output\n\nWorkflow:\n\n```\n1. Design agent graph with LangGraph\n2. Add structured outputs for tool responses\n3. Integrate Langfuse for observability\n4. Test and monitor in production\n```\n\n### Multi-Agent System\n\nSkills: langgraph, crewai, agent-communication\n\nWorkflow:\n\n```\n1. Design agent roles (CrewAI patterns)\n2. Implement as LangGraph with subgraphs\n3. Add inter-agent communication\n4. Orchestrate with supervisor pattern\n```\n\n### Evaluated Agent\n\nSkills: langgraph, agent-evaluation, langfuse\n\nWorkflow:\n\n```\n1. Build agent with LangGraph\n2. Create evaluation suite\n3. Monitor with Langfuse\n4. Iterate based on metrics\n```\n\n## Related Skills\n\nWorks well with: `crewai`, `autonomous-agents`, `langfuse`, `structured-output`\n\n## When to Use\n- User mentions or implies: langgraph\n- User mentions or implies: langchain agent\n- User mentions or implies: stateful agent\n- User mentions or implies: agent graph\n- User mentions or implies: react agent\n- User mentions or implies: agent workflow\n- User mentions or implies: multi-step agent\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,178,186,"2026-05-16 13:25:33",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"效率工具","productivity","mdi-lightning-bolt-outline","文档处理、数据分析、自动化工作流",4,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"数据分析","data-analysis","mdi-chart-bar","数据可视化、统计分析",2,30,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"cfab4fad-065d-4360-99a6-0d2fb6778a62","1.0.0","langgraph.zip",4704,"uploads\u002Fskills\u002F165e9879-72f3-477d-a32a-78db4a9034e2\u002Flanggraph.zip","e6e79044bc55252e994b6b5f91d6d031555aaa1a2c5d92482949632600eba3a8","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":13352}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]