{"id":"c5ccc38d-206c-4866-9649-ef9d6ec778d4","shortId":"VEgmU6","kind":"skill","title":"LangGraph State Machine Designer","tagline":"Converts a workflow description into a LangGraph node/edge graph with typed state, conditional routing, and human-in-the-loop checkpoints.","description":"# LangGraph State Machine Designer\n\n## What this skill does\n\nThis skill takes a plain-language description of an agentic workflow and designs the corresponding LangGraph state machine: typed state schema, node functions, conditional edges, and checkpoint configuration. It handles the hard parts — state typing, routing logic, error recovery, and human-in-the-loop interrupts.\n\n## How to use\n\n### Claude Code / Cline\n\nCopy this file to `.agents/skills/langgraph-state-machine-designer/SKILL.md` in your project root.\n\nThen ask:\n- *\"Use the LangGraph State Machine Designer to build a research-then-write workflow.\"*\n- *\"Design a LangGraph agent that routes between a SQL tool and a web search tool.\"*\n\nProvide:\n- What the agent should do (in plain English)\n- What tools or actions it has available\n- Whether humans need to approve any steps\n- Your LangGraph version (v0.2+ assumed)\n\n### Cursor / Codex\n\nDescribe the workflow and paste these instructions. Ask for the full graph code.\n\n## The Prompt / Instructions for the Agent\n\nWhen asked to design a LangGraph state machine, produce the following:\n\n### Step 1 — Define the TypedDict state\n\nEvery LangGraph graph has a single shared state object. Define it as a TypedDict with `Annotated` fields for lists (so they append rather than overwrite):\n\n```python\nfrom typing import TypedDict, Annotated, Sequence\nfrom langchain_core.messages import BaseMessage\nimport operator\n\nclass AgentState(TypedDict):\n    messages: Annotated[Sequence[BaseMessage], operator.add]\n    # Add task-specific fields:\n    query: str\n    search_results: list[str]\n    draft: str\n    approved: bool\n    error: str | None\n```\n\nRules for state design:\n- Use `Annotated[list, operator.add]` for any field that accumulates over time (messages, results)\n- Use plain types for fields that get overwritten each step (current_step, status)\n- Add an `error` field to every state — nodes should write errors here instead of raising\n\n### Step 2 — Design the nodes\n\nEach node is a function that takes state and returns a partial state update:\n\n```python\ndef call_model(state: AgentState) -> dict:\n    \"\"\"Main LLM reasoning node.\"\"\"\n    response = llm.invoke(state[\"messages\"])\n    return {\"messages\": [response]}\n\ndef run_tool(state: AgentState) -> dict:\n    \"\"\"Execute the tool the model requested.\"\"\"\n    last_message = state[\"messages\"][-1]\n    tool_result = execute_tool(last_message.tool_calls[0])\n    return {\"messages\": [ToolMessage(content=tool_result)]}\n\ndef handle_error(state: AgentState) -> dict:\n    \"\"\"Graceful error recovery node.\"\"\"\n    return {\"messages\": [AIMessage(content=\"I encountered an error. Let me try a different approach.\")], \"error\": None}\n```\n\nNode design rules:\n- Nodes should do ONE thing (single responsibility)\n- Always return a dict — never mutate state directly\n- Catch exceptions inside nodes and write to `state[\"error\"]`\n- Keep nodes stateless — all context comes from state\n\n### Step 3 — Design the edges and routing\n\n```python\nfrom langgraph.graph import StateGraph, END\nfrom langgraph.prebuilt import ToolNode\n\nbuilder = StateGraph(AgentState)\n\n# Add nodes\nbuilder.add_node(\"agent\", call_model)\nbuilder.add_node(\"tools\", ToolNode(tools))\nbuilder.add_node(\"error_handler\", handle_error)\n\n# Set entry point\nbuilder.set_entry_point(\"agent\")\n\n# Conditional routing\ndef should_continue(state: AgentState) -> str:\n    last = state[\"messages\"][-1]\n    if state.get(\"error\"):\n        return \"error_handler\"\n    if hasattr(last, \"tool_calls\") and last.tool_calls:\n        return \"tools\"\n    return END\n\nbuilder.add_conditional_edges(\"agent\", should_continue, {\n    \"tools\": \"tools\",\n    \"error_handler\": \"error_handler\",\n    END: END\n})\nbuilder.add_edge(\"tools\", \"agent\")\nbuilder.add_edge(\"error_handler\", \"agent\")\n```\n\n### Step 4 — Add human-in-the-loop (if needed)\n\nFor workflows requiring human approval before destructive actions:\n\n```python\nfrom langgraph.checkpoint.memory import MemorySaver\n\n# Compile with checkpointer\nmemory = MemorySaver()\ngraph = builder.compile(\n    checkpointer=memory,\n    interrupt_before=[\"execute_action\"]  # pause before this node\n)\n\n# Run until interrupt\nconfig = {\"configurable\": {\"thread_id\": \"thread_001\"}}\nresult = graph.invoke({\"messages\": [HumanMessage(content=user_query)]}, config)\n\n# Resume after human approval\ngraph.invoke(None, config)  # continues from checkpoint\n```\n\n### Step 5 — Standard graph patterns\n\n**Pattern: ReAct agent (reason → act → observe loop)**\n```\nentry → agent → [tools | END]\n              ↑_______|\n```\n\n**Pattern: Multi-step pipeline (sequential)**\n```\nentry → step_1 → step_2 → step_3 → END\n```\n\n**Pattern: Supervisor with sub-agents**\n```\nentry → supervisor → [researcher | writer | reviewer | END]\n                   ↑___________________________|\n```\n\n**Pattern: Retry with fallback**\n```\nentry → primary_agent → [success: END | failure: fallback_agent → END]\n```\n\n### Step 6 — Output the complete graph\n\nAlways produce:\n1. Full `AgentState` TypedDict\n2. All node functions with docstrings\n3. Complete graph builder with edges\n4. Compiled graph with appropriate checkpointer\n5. Example invocation with config\n\n## Example\n\n**Input:**\n> \"Design a LangGraph agent that takes a user question, searches the web, then writes a summarized answer. No human approval needed.\"\n\n**Output:**\n```python\nfrom typing import TypedDict, Annotated, Sequence\nimport operator\nfrom langchain_core.messages import BaseMessage, HumanMessage\nfrom langgraph.graph import StateGraph, END\nfrom langgraph.prebuilt import ToolNode\n\nclass ResearchState(TypedDict):\n    messages: Annotated[Sequence[BaseMessage], operator.add]\n    query: str\n\ndef research_agent(state: ResearchState) -> dict:\n    response = llm_with_tools.invoke(state[\"messages\"])\n    return {\"messages\": [response]}\n\ndef should_continue(state: ResearchState) -> str:\n    last = state[\"messages\"][-1]\n    if hasattr(last, \"tool_calls\") and last.tool_calls:\n        return \"search\"\n    return END\n\nbuilder = StateGraph(ResearchState)\nbuilder.add_node(\"agent\", research_agent)\nbuilder.add_node(\"search\", ToolNode([web_search_tool]))\nbuilder.set_entry_point(\"agent\")\nbuilder.add_conditional_edges(\"agent\", should_continue, {\"search\": \"search\", END: END})\nbuilder.add_edge(\"search\", \"agent\")\n\ngraph = builder.compile()\n```","tags":["langgraph","state","machine","designer","openagentskills","notysoty","agent-skills","claude","claude-code","claude-skills","cline","cursor"],"capabilities":["skill","source-notysoty","skill-langgraph-state-machine-designer","topic-agent-skills","topic-claude","topic-claude-code","topic-claude-skills","topic-cline","topic-cursor","topic-llm","topic-llm-skills","topic-skills"],"categories":["openagentskills"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/Notysoty/openagentskills/langgraph-state-machine-designer","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add Notysoty/openagentskills","source_repo":"https://github.com/Notysoty/openagentskills","install_from":"skills.sh"}},"qualityScore":"0.454","qualityRationale":"deterministic score 0.45 from registry signals: · indexed on github topic:agent-skills · 8 github stars · SKILL.md body (6,275 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-05-18T19:13:22.455Z","embedding":null,"createdAt":"2026-05-18T13:20:43.689Z","updatedAt":"2026-05-18T19:13:22.455Z","lastSeenAt":"2026-05-18T19:13:22.455Z","tsv":"'-1':355,486,764 '0':362 '001':576 '1':188,619,658 '2':303,621,662 '3':431,623,668 '4':529,674 '5':596,680 '6':651 'accumul':269 'act':604 'action':139,545,563 'add':239,287,450,530 'agent':44,115,130,175,454,474,508,522,527,602,608,630,643,648,690,744,782,784,795,799,809 'agents/skills/langgraph-state-machine-designer/skill.md':91 'agentst':232,326,343,373,449,481,660 'aimessag':381 'alway':405,656 'annot':208,223,235,262,714,736 'answer':703 'append':214 'approach':392 'appropri':678 'approv':147,252,542,588,706 'ask':97,164,177 'assum':154 'avail':142 'basemessag':228,237,721,738 'bool':253 'build':105 'builder':447,671,777 'builder.add':452,457,462,505,519,523,780,785,796,806 'builder.compile':557,811 'builder.set':471,792 'call':323,361,455,497,500,769,772 'catch':413 'checkpoint':25,61,553,558,594,679 'class':231,732 'claud':84 'cline':86 'code':85,169 'codex':156 'come':427 'compil':551,675 'complet':654,669 'condit':17,58,475,506,797 'config':571,584,591,684 'configur':62,572 'content':366,382,581 'context':426 'continu':479,510,592,757,801 'convert':5 'copi':87 'correspond':49 'current':284 'cursor':155 'def':322,339,369,477,742,755 'defin':189,202 'describ':157 'descript':8,41 'design':4,29,47,103,112,179,260,304,396,432,687 'destruct':544 'dict':327,344,374,408,747 'differ':391 'direct':412 'docstr':667 'draft':250 'edg':59,434,507,520,524,673,798,807 'encount':384 'end':442,504,517,518,610,624,636,645,649,727,776,804,805 'english':135 'entri':469,472,607,617,631,641,793 'error':72,254,289,297,371,376,386,393,421,464,467,489,491,513,515,525 'everi':193,292 'exampl':681,685 'except':414 'execut':345,358,562 'failur':646 'fallback':640,647 'field':209,243,267,278,290 'file':89 'follow':186 'full':167,659 'function':57,311,665 'get':280 'grace':375 'graph':13,168,195,556,598,655,670,676,810 'graph.invoke':578,589 'handl':64,370,466 'handler':465,492,514,516,526 'hard':66 'hasattr':494,766 'human':21,76,144,532,541,587,705 'human-in-the-loop':20,75,531 'humanmessag':580,722 'id':574 'import':221,227,229,440,445,549,712,716,720,725,730 'input':686 'insid':415 'instead':299 'instruct':163,172 'interrupt':80,560,570 'invoc':682 'keep':422 'langchain_core.messages':226,719 'langgraph':1,11,26,50,100,114,151,181,194,689 'langgraph.checkpoint.memory':548 'langgraph.graph':439,724 'langgraph.prebuilt':444,729 'languag':40 'last':351,483,495,761,767 'last.tool':499,771 'last_message.tool':360 'let':387 'list':211,248,263 'llm':329 'llm.invoke':333 'llm_with_tools.invoke':749 'logic':71 'loop':24,79,535,606 'machin':3,28,52,102,183 'main':328 'memori':554,559 'memorysav':550,555 'messag':234,272,335,337,352,354,364,380,485,579,735,751,753,763 'model':324,349,456 'multi':613 'multi-step':612 'mutat':410 'need':145,537,707 'never':409 'node':56,294,306,308,331,378,395,398,416,423,451,453,458,463,567,664,781,786 'node/edge':12 'none':256,394,590 'object':201 'observ':605 'one':401 'oper':230,717 'operator.add':238,264,739 'output':652,708 'overwrit':217 'overwritten':281 'part':67 'partial':318 'past':161 'pattern':599,600,611,625,637 'paus':564 'pipelin':615 'plain':39,134,275 'plain-languag':38 'point':470,473,794 'primari':642 'produc':184,657 'project':94 'prompt':171 'provid':127 'python':218,321,437,546,709 'queri':244,583,740 'question':695 'rais':301 'rather':215 'react':601 'reason':330,603 'recoveri':73,377 'request':350 'requir':540 'research':108,633,743,783 'research-then-writ':107 'researchst':733,746,759,779 'respons':332,338,404,748,754 'result':247,273,357,368,577 'resum':585 'retri':638 'return':316,336,363,379,406,490,501,503,752,773,775 'review':635 'root':95 'rout':18,70,117,436,476 'rule':257,397 'run':340,568 'schema':55 'search':125,246,696,774,787,790,802,803,808 'sequenc':224,236,715,737 'sequenti':616 'set':468 'share':199 'singl':198,403 'skill':32,35 'skill-langgraph-state-machine-designer' 'source-notysoty' 'specif':242 'sql':120 'standard':597 'state':2,16,27,51,54,68,101,182,192,200,259,293,314,319,325,334,342,353,372,411,420,429,480,484,745,750,758,762 'state.get':488 'stategraph':441,448,726,778 'stateless':424 'status':286 'step':149,187,283,285,302,430,528,595,614,618,620,622,650 'str':245,249,251,255,482,741,760 'sub':629 'sub-ag':628 'success':644 'summar':702 'supervisor':626,632 'take':36,313,692 'task':241 'task-specif':240 'thing':402 'thread':573,575 'time':271 'tool':121,126,137,341,347,356,359,367,459,461,496,502,511,512,521,609,768,791 'toolmessag':365 'toolnod':446,460,731,788 'topic-agent-skills' 'topic-claude' 'topic-claude-code' 'topic-claude-skills' 'topic-cline' 'topic-cursor' 'topic-llm' 'topic-llm-skills' 'topic-skills' 'tri':389 'type':15,53,69,220,276,711 'typeddict':191,206,222,233,661,713,734 'updat':320 'use':83,98,261,274 'user':582,694 'v0.2':153 'version':152 'web':124,698,789 'whether':143 'workflow':7,45,111,159,539 'write':110,296,418,700 'writer':634","prices":[{"id":"37c5fcb7-eeb2-452f-a344-0cca16049d2a","listingId":"c5ccc38d-206c-4866-9649-ef9d6ec778d4","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"Notysoty","category":"openagentskills","install_from":"skills.sh"},"createdAt":"2026-05-18T13:20:43.689Z"}],"sources":[{"listingId":"c5ccc38d-206c-4866-9649-ef9d6ec778d4","source":"github","sourceId":"Notysoty/openagentskills/langgraph-state-machine-designer","sourceUrl":"https://github.com/Notysoty/openagentskills/tree/main/skills/langgraph-state-machine-designer","isPrimary":false,"firstSeenAt":"2026-05-18T13:20:43.689Z","lastSeenAt":"2026-05-18T19:13:22.455Z"}],"details":{"listingId":"c5ccc38d-206c-4866-9649-ef9d6ec778d4","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"Notysoty","slug":"langgraph-state-machine-designer","github":{"repo":"Notysoty/openagentskills","stars":8,"topics":["agent-skills","claude","claude-code","claude-skills","cline","cursor","llm","llm-skills","skills"],"license":"mit","html_url":"https://github.com/Notysoty/openagentskills","pushed_at":"2026-03-28T06:50:19Z","description":"A  community-driven library of reusable AI agent skills for Claude Code, Cursor, Codex, Cline, and more.","skill_md_sha":"5d5bf3f0d5ae9d744a53d040a8181ea29b8cb22b","skill_md_path":"skills/langgraph-state-machine-designer/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/Notysoty/openagentskills/tree/main/skills/langgraph-state-machine-designer"},"layout":"multi","source":"github","category":"openagentskills","frontmatter":{"name":"LangGraph State Machine Designer","description":"Converts a workflow description into a LangGraph node/edge graph with typed state, conditional routing, and human-in-the-loop checkpoints."},"skills_sh_url":"https://skills.sh/Notysoty/openagentskills/langgraph-state-machine-designer"},"updatedAt":"2026-05-18T19:13:22.455Z"}}