Cheat sheet · Module 13

Cheat sheet: LangChain ecosystem

Generative AI · Cheat sheet · LangChain ecosystem

Open the moduleModule quiz

Map: LangChain is the fast path to an agent (create_agent) and a common model interface. LangGraph is the low-level runtime for stateful, long-running work; LangChain agents are built on it. LangSmith is tracing, evaluation and deployment, and works with other frameworks. Deep Agents is a packaged harness on LangGraph. Start with the SDK, then create_agent, then a graph. Name the job before the part.

Arithmetic: checkpoints per day = conversations × steps × state size (20,000 × 12 × 40 KB = 9.6 GB). Cost per resolved task = cost per attempt ÷ resolution rate. All retries fail = rate to the power of attempts if independent (0.05³ = 0.0125%), and real failures are correlated.

Core

  • Runnable: the shared interface (invoke, batch, stream, async). A pipe composes; a dict runs branches in parallel. No loops or durable state: use a graph for those.
  • 1.0: create_agent replaces create_react_agent; middleware extends the loop; structured output comes from the main loop; content_blocks; legacy chains and retrievers moved to langchain-classic.
  • Typed output: with_structured_output on a model; response_format (provider or tool strategy) in an agent, result under structured_response. A schema reduces malformed output; it does not remove it.
  • Tools: docstring and type hints are the schema. Inject identity through the hidden runtime parameter, never as a model argument.
  • Retrieval: two-step (predictable), agentic (flexible, variable latency), hybrid (adds rewriting and checks).

Agents and middleware

  • Hooks: before_agent, before_model, wrap_model_call, wrap_tool_call, after_model, after_agent. Before hooks run first to last, wraps nest with the first as outermost, after hooks run last to first.
  • Limits and retries in middleware, not prompts. Redaction first. Approval only on tools that write, spend or send.
  • Four places to keep things: state, short-term memory (checkpointer and thread id), runtime context (read-only per call), long-term store. Approval and thread memory need a checkpointer.
  • Multi-agent patterns: subagents, handoffs, skills, router, custom workflow. Start with one agent; split for a measured reason.
  • Migrate: pin versions, write evaluations, port one piece at a time, compare traces, remove the bridge.

LangGraph

  • State, nodes (return partial updates), edges. Compile before use. A reducer is the merge rule for a key (default replace); parallel writes need one; clear an append list with an overwrite.
  • Super-steps: parallel nodes on the same state, merge at the boundary, repeat. Set the recursion limit yourself. Steps can run twice, so make side effects safe to repeat.
  • Conditional edge routes; Command updates and routes; Send fans out with a runtime count. A static edge still runs beside a goto.
  • Graph API when the shape matters; functional API to add durability to procedural code.

Persistence and approval

  • Checkpointer: one thread, keyed by thread id. Store: across threads, keyed by namespace and key. Never the in-memory saver in production; prune checkpoints.
  • interrupt saves state and pauses; resume with a command on the same thread. The node restarts from its top. No bare try-except, stable order, JSON payload, no while-true loop.
  • Outside effects are at least once: idempotency keys, check for existing results. Durability: exit, async, sync.
  • Replay re-runs later nodes (effects fire again). A fork branches from a checkpoint and leaves history intact.

LangSmith

  • Run, trace, thread, project, feedback, tags, metadata. Tracing: LANGSMITH_TRACING, LANGSMITH_API_KEY, optional project. Add version, model, tenant and thread id. Flush in serverless; redact before sending.
  • Method: find, read top down, check exact inputs, classify, reproduce, add to a dataset.
  • Dataset, example, split, experiment, evaluator. Reference outputs are for evaluators only. Code, judge, human, pairwise; score trajectories for agents.
  • Trust: calibrate the judge, look at slices, repeat runs, hold out a set, watch for gaming. Offline before release; online (no reference) after.
  • Gate: beat the baseline on a pinned dataset with no slice worse; release gradually.

Deployment

  • Assistant (graph plus config), thread, run, cron, store, checkpoints, task queue. Core data in PostgreSQL; Redis for signalling.
  • Hosting: cloud, hybrid, self-hosted with control plane, standalone, or build your own (and rebuild streaming, resume, queues, concurrency rules).
  • Double texting: enqueue (default), reject, interrupt, rollback. Chat prefers interrupt or rollback; transactional work prefers enqueue or reject.
  • Auth on every request; thread ownership by metadata filter; self-hosted has no default auth. Budgets, a kill switch, idempotent tools, a deletion path.
  • Deploys with paused runs need compatible state, stable node names and interrupt order.

A design answer in eight parts

Clarify · shape · state and memory · tools · guardrails and budgets · evaluation · deployment · failure modes. When a constraint changes, re-cost aloud and name the risk you accept.

Traps

Old chain, executor and memory classes in new code · a loop built from pipes · the model choosing the user id · typed output treated as a guarantee · no reducer on a parallel key · a side effect before interrupt · the in-memory saver in production · no recursion limit · tracing personal data · one judge score trusted · no thread-ownership check · using the framework for a single call.