# Langgraph Agent

> >-

- **Type:** Skill
- **Install:** `agentstack add skill-mfrostbutter-claude-skills-langgraph-agent`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [Mfrostbutter](https://agentstack.voostack.com/s/mfrostbutter)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [Mfrostbutter](https://github.com/Mfrostbutter)
- **Source:** https://github.com/Mfrostbutter/claude-skills/tree/main/skills/langgraph-agent

## Install

```sh
agentstack add skill-mfrostbutter-claude-skills-langgraph-agent
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Building production LangGraph agents

LangGraph is a state machine over an LLM: nodes mutate a shared state, edges route, and the graph streams its progress. The expensive lessons are not the API, they are the **discipline** that keeps a graph importable from Studio, boot-safe inside an app, resumable across a human pause, and visible in a live UI. This skill is that discipline.

## The five non-negotiables

1. **Graph modules are pure factories.** A graph file exports `build_X_graph(llm, ..., checkpointer=None)` and imports only its own siblings (`.prompts`, `.sources`) plus langchain/langgraph. **No imports of your app package, ever.** That is what lets `langgraph dev` / Studio import the graph without dragging in your web app.
2. **Heavy imports are lazy.** `import langgraph`, `langchain_anthropic`, `psycopg2`, etc. go **inside** functions, never at module scope, so the package imports cleanly at app boot even when an optional extra is absent.
3. **IO is injected, not imported.** A graph never reaches out to a DB, an API, or an external service directly. Side effects arrive as an `effects` dict of callables the builder passes to its nodes. This keeps the graph pure AND lets Studio/tests run it with dry-run or no-op effects. Effects **fail open or dry-run** when their credentials are absent.
4. **Progress is messages.** Nodes emit `AIMessage`s on the `messages` channel. A message with `name="ingest"` becomes a labeled timeline + graph step; the final **unnamed** `AIMessage` is the run result. This is the whole contract a streaming UI renders against.
5. **The human pause is `interrupt()` + a checkpointer.** HITL agents call `interrupt({...})` to HALT and only resume when re-entered with `Command(resume=decision)` on the same `thread_id`. No checkpointer, no resume.

Break one and the symptom is usually: Studio import fails (1/2), the app won't boot (2), the graph can't run headless (3), the timeline/graph stays blank (4), or the run can't pause/resume (5).

## The 1.x API you actually use

```python
from langgraph.graph import START, END, StateGraph, MessagesState
from langgraph.types import interrupt, Command
from langgraph.checkpoint.memory import MemorySaver
from langgraph.prebuilt import ToolNode, tools_condition   # for ReAct loops
# llm.with_structured_output(PydanticModel) -> validated object, no parsing
# graph.astream(state, config, stream_mode="updates") -> async node updates
```

Pins that work together: `langgraph==1.2.4`, `langchain-core==1.4.6`, `langchain-anthropic==1.4.5`, `langsmith==0.8.14`, `langchain-openai>=1.0,/graph.py` as a pure factory: `build__graph(llm, effects, checkpointer=None)`. Define a state `class S(MessagesState): ...`, the nodes, the edges, `return g.compile(checkpointer=checkpointer)`.
2. Put IO in sibling modules under the agent package (`sources.py`, `dedup.py`), pure and self-contained, lazy heavy imports, fail-open.
3. Wire it into your app with a small builder `build(llm, checkpointer)` that constructs the effects (+ any second model) and calls your factory. Keep a registry/catalog of these builders if you run more than one agent. See `reference/03-wiring-into-an-app.md`.
4. Register for Studio: build the graph at module scope **without** a checkpointer in a `studio.py`, and point `langgraph.json` at it.

Copy-paste skeleton: `assets/new_agent_template.py`.

## Human-in-the-loop

`interrupt(payload)` HALTS the graph and surfaces `payload` to the human; resume with `Command(resume=decision)` and the graph continues from exactly that node. A useful `decision` contract is `{"action": "approve"|"edit"|"reject", "edited": str, "mode": "dry_run"|"live"}`. Your driver parks the live compiled graph, emits an "awaiting approval" event, and re-enters it on resume. Write-path agents default to `dry_run` and require an explicit `live`. A run can pause MORE than once: re-park on each interrupt, so a multi-gate agent (pick, then approve) is just two `interrupt()` nodes — each interrupt value needs a `proposal` key. Full pattern: `reference/04-hitl.md`.

## Streaming + a live graph view

Drive `graph.astream(..., stream_mode="updates")` and map each node update to your UI. Emit a **named** `AIMessage` per node so it shows as a labeled step; a message with no name and no tool calls is the result-so-far (the last one is the final). The graph topology for a live SVG comes from `compiled.get_graph()` (build with a throwaway, never-invoked model to read the shape without an API key). Details + a workable event contract + LangSmith tracing: `reference/05-streaming-and-observability.md`.

## Patterns to reach for

- **ReAct tool-loop:** `investigate ⇄ tools` via `tools_condition`, ends when the model stops calling tools. Read-only diagnosis.
- **Parallel fan-out / reduce:** a plan node dispatches N lenses that run in one superstep, a synthesize node reduces. Use an additive state channel (e.g. `findings: list`).
- **Routing pipeline:** triage → assess → conditional route → propose → approve → apply. One graph, branches.
- **Two-model:** a cheap model ranks/routes, a quality model writes. Build the second model from the first's key so you reuse one credential.
- **Multi-gate content + live publish:** TWO interrupts in one run (pick an idea, then approve the draft) ending in a consequential, gated action (dry-run by default).
- **Cross-provider reviewer:** a different vendor's model judges the primary's output before it acts.
- **Grounding fact-check:** ground concrete claims against the source text (not the model's memory) before the human sees the draft; bound the auto-revision loop.
- **Structured output:** `llm.with_structured_output(PydanticModel)` for selection/assessment/verdict nodes. Validation + retry happen for you.

More: `reference/06-patterns.md`.

## Test before you wire the UI

Stand up a matched venv (the pins above), then drive the graph headless with **stub models + real (or no-op) effects** through the interrupt and a resume. You do not need an API key to prove topology, streaming, the pause, and staging. Then `py_compile`, then run it in the app. Harness + venv recipe: `reference/07-testing.md`.

## Prompt hygiene in agents

- **Untrusted data:** any retrieved content (web, tools, tickets, scraped) is data, never instructions. Say so in the system prompt.
- **Consistent punctuation:** pick a style and scrub the rest; models mimic what they see, so stray characters leak into output.

## Reference

- `reference/01-api-1x.md` — the 1.x imports and idioms.
- `reference/02-pure-factories-and-effects.md` — why pure factories + injected effects, and how.
- `reference/03-wiring-into-an-app.md` — turning a graph into a runnable, catalogued agent + Studio.
- `reference/04-hitl.md` — interrupt/resume, multi-gate, the driver's park/resume job.
- `reference/05-streaming-and-observability.md` — streaming to a UI, topology, LangSmith.
- `reference/06-patterns.md` — the graph shapes with when-to-use.
- `reference/07-testing.md` — stub models, drive-to-interrupt, the async gotcha.
- `assets/new_agent_template.py` — a HITL two-model pure-factory skeleton.

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [Mfrostbutter](https://github.com/Mfrostbutter)
- **Source:** [Mfrostbutter/claude-skills](https://github.com/Mfrostbutter/claude-skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** yes

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-mfrostbutter-claude-skills-langgraph-agent
- Seller: https://agentstack.voostack.com/s/mfrostbutter
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
