Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Guides architectural decisions for LangGraph applications. Use when deciding between LangGraph vs alternatives, choosing state management strategies, designing multi-agent systems, or selecting persistence and streaming approaches.
.claude/skills/majiayu000-langgraph-architecture/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 2% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 12% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 8% | 0% |
| case-19 | ✗→✓ | ▲ Improved | 55% | 0% |
| case-05 | ✓→✓ | = Same ✓ | 84% | 0% |
| Scenario | Alternative | Why | |----------|-------------|-----| | Single LLM call | Direct API call | Overhead not justified | | Linear pipeline | LangChain LCEL | Simpler abstraction | | Stateless tool use | Function calling | No persistence needed | | Simple RAG | LangChain retrievers | Built-in patterns | | Batch processing | Async tasks | Different execution model |
| TypedDict | Pydantic | |-----------|----------| | Lightweight, faster | Runtime validation | | Dict-like access | Attribute access | | No validation overhead | Type coercion | | Simpler serialization | Complex nested models |
Recommendation: Use TypedDict for most cases. Use Pydantic when you need validation or complex nested structures.
| Use Case | Reducer | Example | |----------|---------|---------| | Chat messages | add_messages | Handles IDs, RemoveMessage | | Simple append | operator.add | Annotated[list, operator.add] | | Keep latest | None (LastValue) | field: str | | Custom merge | Lambda | Annotated[list, lambda a, b: ...] | | Overwrite list | Overwrite | Bypass reducer |
python# SMALL STATE (< 1MB) - Put in state class State(TypedDict): messages: Annotated[list, add_messages] context: str # LARGE DATA - Use Store class State(TypedDict): messages: Annotated[list, add_messages] document_ref: str # Reference to store def node(state, *, store: BaseStore): doc = store.get(namespace, state["document_ref"]) # Process without bloating checkpoints
Single Graph when:
Subgraphs when:
| Conditional Edges | Command | |------------------|---------| | Routing based on state | Routing + state update | | Separate router function | Decision in node | | Clearer visualization | More flexible | | Standard patterns | Dynamic destinations |
python# Conditional Edge - when routing is the focus def router(state) -> Literal["a", "b"]: return "a" if condition else "b" builder.add_conditional_edges("node", router) # Command - when combining routing with updates def node(state) -> Command: return Command(goto="next", update={"step": state["step"] + 1})
Static Edges (add_edge):
Dynamic Routing (add_conditional_edges, Command, Send):
| Checkpointer | Use Case | Characteristics | |--------------|----------|-----------------| | InMemorySaver | Testing only | Lost on restart | | SqliteSaver | Development | Single file, local | | PostgresSaver | Production | Scalable, concurrent | | Custom | Special needs | Implement BaseCheckpointSaver |
python# Full persistence (default) graph = builder.compile(checkpointer=checkpointer) # Subgraph options subgraph = sub_builder.compile( checkpointer=None, # Inherit from parent checkpointer=True, # Independent checkpointing checkpointer=False, # No checkpointing (runs atomically) )
Best for:
┌─────────────┐
│ Supervisor │
└──────┬──────┘
┌────────┬───┴───┬────────┐
▼ ▼ ▼ ▼
┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐
│Agent1│ │Agent2│ │Agent3│ │Agent4│
└──────┘ └──────┘ └──────┘ └──────┘Best for:
┌──────┐ ┌──────┐
│Agent1│◄───►│Agent2│
└──┬───┘ └───┬──┘
│ │
▼ ▼
┌──────┐ ┌──────┐
│Agent3│◄───►│Agent4│
└──────┘ └──────┘Best for:
┌────────┐ ┌────────┐ ┌────────┐
│Research│───►│Planning│───►│Execute │
└────────┘ └────────┘ └────────┘| Mode | Use Case | Data | |------|----------|------| | updates | UI updates | Node outputs only | | values | State inspection | Full state each step | | messages | Chat UX | LLM tokens | | custom | Progress/logs | Your data via StreamWriter | | debug | Debugging | Tasks + checkpoints |
python# Stream from subgraphs async for chunk in graph.astream( input, stream_mode="updates", subgraphs=True # Include subgraph events ): namespace, data = chunk # namespace indicates depth
| Strategy | Use Case | |----------|----------| | interrupt_before | Approval before action | | interrupt_after | Review after completion | | interrupt() in node | Dynamic, contextual pauses |
python# Simple resume (same thread) graph.invoke(None, config) # Resume with value graph.invoke(Command(resume="approved"), config) # Resume specific interrupt graph.invoke(Command(resume={interrupt_id: value}), config) # Modify state and resume graph.update_state(config, {"field": "new_value"}) graph.invoke(None, config)
python# Per-node retry RetryPolicy( initial_interval=0.5, backoff_factor=2.0, max_interval=60.0, max_attempts=3, retry_on=lambda e: isinstance(e, (APIError, TimeoutError)) ) # Multiple policies (first match wins) builder.add_node("node", fn, retry_policy=[ RetryPolicy(retry_on=RateLimitError, max_attempts=5), RetryPolicy(retry_on=Exception, max_attempts=2), ])
pythondef node_with_fallback(state): try: return primary_operation(state) except PrimaryError: return fallback_operation(state) # Or use conditional edges for complex fallback routing def route_on_error(state) -> Literal["retry", "fallback", "__end__"]: if state.get("error") and state["attempts"] < 3: return "retry" elif state.get("error"): return "fallback" return END
python# Set recursion limit config = {"recursion_limit": 50} graph.invoke(input, config) # Track remaining steps in state class State(TypedDict): remaining_steps: RemainingSteps def check_budget(state): if state["remaining_steps"] < 5: return "wrap_up" return "continue"
Before implementing:
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-05 | pass→pass | 10,675 | 7,759 | -27% | 1 | 1 | 0% | 1,887 | 3,481 | +84% | 0 | 0 | — |
case-06 | pass→pass | 16,619 | 12,501 | -25% | 1 | 1 | 0% | 2,230 | 4,244 | +90% | 0 | 0 | — |
case-01 | fail→pass | 37,026 | 22,539 | -39% | 1 | 1 | 0% | 4,702 | 4,804 | +2% | 0 | 0 | — |
case-02 | fail→pass | 30,492 | 25,921 | -15% | 1 | 1 | 0% | 5,566 | 6,237 | +12% | 0 | 0 | — |
case-03 | fail→pass | 40,522 | 26,265 | -35% | 1 | 1 | 0% | 6,440 | 6,984 | +8% | 0 | 0 | — |
case-04 | pass→pass | 12,209 | 8,214 | -33% | 1 | 1 | 0% | 2,034 | 3,457 | +70% | 0 | 0 | — |
case-07 | pass→pass | 17,086 | 12,388 | -27% | 1 | 1 | 0% | 2,788 | 4,445 | +59% | 0 | 0 | — |
case-08 | pass→pass | 6,633 | 6,513 | -2% | 1 | 1 | 0% | 1,195 | 3,422 | +186% | 0 | 0 | — |
case-09 | pass→pass | 12,678 | 12,572 | -1% | 1 | 1 | 0% | 2,200 | 4,435 | +102% | 0 | 0 | — |
case-10 | pass→pass | 14,446 | 15,899 | +10% | 1 | 1 | 0% | 2,300 | 5,048 | +119% | 0 | 0 | — |
case-11 | pass→pass | 12,701 | 6,474 | -49% | 1 | 1 | 0% | 2,105 | 3,392 | +61% | 0 | 0 | — |
case-12 | pass→pass | 8,427 | 8,413 | -0% | 1 | 1 | 0% | 1,431 | 3,787 | +165% | 0 | 0 | — |
case-13 | pass→pass | 11,541 | 10,545 | -9% | 1 | 1 | 0% | 1,823 | 4,032 | +121% | 0 | 0 | — |
case-14 | pass→pass | 19,052 | 10,969 | -42% | 1 | 1 | 0% | 2,827 | 4,173 | +48% | 0 | 0 | — |
case-15 | pass→pass | 7,011 | 4,292 | -39% | 1 | 1 | 0% | 1,209 | 2,979 | +146% | 0 | 0 | — |
case-16 | pass→pass | 5,869 | 6,203 | +6% | 1 | 1 | 0% | 1,021 | 3,329 | +226% | 0 | 0 | — |
case-17 | pass→pass | 14,823 | 11,232 | -24% | 1 | 1 | 0% | 2,509 | 4,375 | +74% | 0 | 0 | — |
case-18 | pass→pass | 11,055 | 9,133 | -17% | 1 | 1 | 0% | 2,236 | 4,044 | +81% | 0 | 0 | — |
case-19 | fail→pass | 16,340 | 13,160 | -19% | 1 | 1 | 0% | 3,060 | 4,753 | +55% | 0 | 0 | — |
case-20 | pass→pass | 12,497 | 11,750 | -6% | 1 | 1 | 0% | 2,351 | 4,379 | +86% | 0 | 0 | — |
case-21 | pass→pass | 8,394 | 4,557 | -46% | 1 | 1 | 0% | 1,620 | 3,110 | +92% | 0 | 0 | — |
case-22 | pass→pass | 16,514 | 9,146 | -45% | 1 | 1 | 0% | 2,383 | 3,988 | +67% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +18 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.