Module deck
LangChain ecosystem flashcards
Reviewing needs JavaScript. You can read every card in the list below.
Loading your cards...
Back to the module97 cards in this deck
Read all 97 cards as a list
The LangChain map and Runnables
- Front
- How do LangChain, LangGraph and LangSmith fit together?
- Back
- LangChain: quick path to an agent and a common model interface. LangGraph: the stateful runtime LangChain agents are built on (persistence, interrupts, loops). LangSmith: tracing, evaluation and deployment, usable with any framework.
- Front
- What is Deep Agents?
- Back
- A packaged agent harness on top of LangGraph: planning, subagents, filesystem tools and context management. Use it for long, open-ended tasks.
- Front
- Does LangSmith need LangChain?
- Back
- No. It traces and evaluates agents built with any framework or a plain SDK. Tracing is switched on through environment variables.
- Front
- What changed in LangChain 1.0 that dates an old tutorial?
- Back
- create_agent replaces create_react_agent; middleware extends the loop; structured output comes from the main loop; content_blocks give a provider-neutral view; legacy chains and memory moved to langchain-classic.
- Front
- What is a Runnable?
- Back
- The shared interface of every component: the same calls for one input, a batch, async or a stream. Because the shape is shared, components compose.
- Front
- How do a pipe and a dict compose Runnables?
- Back
- A pipe runs left to right, passing each output on. A dict runs its branches on the same input in parallel and gathers a dict of results.
- Front
- When does the pipe style stop being enough?
- Back
- When you need loops (retry until valid), branching on state, waiting for a person, or resuming after a crash. The pipe flow has no cycles and no durable state; use a graph.
- Front
- Two ways to get typed output in LangChain?
- Back
- On a bare model: with_structured_output(schema), optionally returning the raw reply and parse error. In an agent: response_format, using provider-native output or a tool strategy; the result is under structured_response.
- Front
- Why is typed output not a guarantee?
- Back
- Output can be cut off at the token limit, a loose schema lets the model fill filler, and a valid value can be wrong. Validate, retry a bounded number of times, define the failure path.
- Front
- Where does a tool's schema come from?
- Back
- The function: its docstring is the description and its type hints are the input schema. The docstring is part of your prompt.
- Front
- Why inject user_id into a tool instead of making it an argument?
- Back
- A model-chosen id can be changed by prompt injection or a persuasive user. A hidden runtime parameter is filled from the caller's session, so the model never chooses whose data is read.
- Front
- Two-step, agentic and hybrid RAG: when each?
- Back
- Two-step (always retrieve, then answer): predictable latency, FAQ bots. Agentic (retrieval as a tool): flexible, variable latency. Hybrid (adds rewriting and checks, may loop): ambiguous or quality-sensitive flows.
- Front
- When would you skip LangChain entirely?
- Back
- A single model call or simple feature with no state, tools or vendor swap: call the provider SDK. Add the framework when you can name the concrete benefit.
Agents, middleware and memory
- Front
- What does create_agent build?
- Back
- A loop on the LangGraph runtime: call the model, run the tools it asks for, add results, stop when no tool is requested. Persistence and approvals come from the runtime.
- Front
- The middleware hooks and when each runs?
- Back
- Node-style: before_agent and after_agent (once per invocation), before_model and after_model (every model turn). Wrap-style: wrap_model_call and wrap_tool_call (around each call; the handler can run zero, one or many times).
- Front
- Which hook fits history trimming? A tool retry? A reply guard?
- Back
- Trimming: before_model. Tool retry or error shaping: wrap_tool_call. Reply guard: after_model.
- Front
- How do you stop a runaway agent loop?
- Back
- A model call limit (and a tool call limit) in middleware, with a chosen exit behaviour. Do not rely on a prompt sentence.
- Front
- Middleware execution order for [m1, m2, m3]?
- Back
- before hooks: m1, m2, m3. wrap hooks nest, m1 outermost. after hooks: m3, m2, m1.
- Front
- Where should redaction and approval go?
- Back
- Redaction first, before anything that logs or forwards. Approval only on tools that write, spend or send, not on every tool.
- Front
- What needs a checkpointer in a create_agent agent?
- Back
- Conversation continuity by thread id, human-in-the-loop approval that resumes, and per-thread limits. Runtime context and the system prompt do not.
- Front
- State, short-term memory, runtime context, long-term memory?
- Back
- State: messages plus custom fields, per thread. Short-term: checkpointer plus thread id. Context: read-only data per invocation (user, tenant). Long-term: a namespaced store across threads.
- Front
- Why does cost sometimes rise after enabling summarisation?
- Back
- Each summary is an extra model call, a trigger that fires too often repeats it, and lost facts can cause extra tool calls. Check traces before and after.
- Front
- Name the five multi-agent patterns in the docs.
- Back
- Subagents, handoffs, skills, router, custom workflow (a LangGraph graph).
- Front
- Cost of each pattern?
- Back
- Subagents: extra model call per request. Handoffs: sequential. Skills: loaded text stays in context. Router: stateless, a routing call every time. Custom: more code.
- Front
- When should you add a second agent?
- Back
- Only for a measured need: context isolation, parallel work or independent evaluation. A single agent with good tools often does the job.
- Front
- Old to new: create_react_agent, prompt=, pre_model_hook, post_model_hook?
- Back
- create_agent, system_prompt=, before_model middleware, after_model middleware. Legacy chains and retrievers moved to langchain-classic.
- Front
- A safe migration method?
- Back
- Pin versions, write evaluations of current behaviour, port one piece at a time, compare traces and scores after each, then remove the bridge package.
LangGraph: state, nodes, edges and control flow
- Front
- What are the three primitives of a LangGraph graph?
- Back
- State (shared data, with merge rules), nodes (functions that return partial updates) and edges (fixed, conditional or dynamic routing). Compile the graph before use.
- Front
- What should a node return?
- Back
- A partial update with only the keys it changed. Returning the whole state risks overwriting other nodes' work.
- Front
- How do you bound a retry loop in a graph?
- Back
- Keep a counter in state and have the routing function end the run when it reaches the cap. Also set the recursion limit.
- Front
- What is a reducer?
- Back
- The merge rule for one state key. Default: replace. An append reducer combines lists; the message reducer appends and updates by message id.
- Front
- Why do parallel writes to one key need a reducer?
- Back
- Two nodes in a round both write it; the runtime needs a rule to combine them. Without one the update is invalid or one write is lost.
- Front
- How do you clear a list that has an append reducer?
- Back
- Returning an empty list merges nothing in. Use the overwrite wrapper to bypass the reducer, from one node per round.
- Front
- What is a super-step?
- Back
- One round: all active nodes run in parallel on the same state, updates merge at the boundary through the reducers, and the next nodes activate.
- Front
- Why set the recursion limit yourself?
- Back
- The default can change between versions and is large (1000 from 1.0.6 per the docs). An unbounded cycle is an unbounded bill. Set it at the top level of the run config.
- Front
- Why must a node's side effects be safe to repeat?
- Back
- A retry or resume can re-run a step. The runtime saves state, not your outside effects, so use idempotency keys.
- Front
- Conditional edge, Command or Send?
- Back
- Conditional edge: a function picks the next node. Command: a node returns an update and the next node together. Send: fan out workers with their own input when the count is known only at run time.
- Front
- What happens if a node returns Command(goto=...) and also has a static edge?
- Back
- Both run. The static edge still fires alongside the goto, so remove it if you meant only the goto.
- Front
- Map-reduce in LangGraph?
- Back
- A routing function returns one Send per item; a worker node handles each; an append reducer on the results key gathers them; a join runs after.
- Front
- Graph API or functional API?
- Back
- Graph API when you want the shape visible: shared state, several decisions, parallel merges. Functional API to add durability to procedural code with simple branching. Same core capabilities.
- Front
- When is a graph the wrong tool?
- Back
- A linear pipeline with no loops, state or pauses: plain functions or a pipe chain. A standard tool agent: create_agent.
LangGraph: persistence, human approval and failure
- Front
- Checkpointer or store?
- Back
- Checkpointer: one thread's state at each step, keyed by thread id (continuity, approvals, time travel, recovery). Store: memories across threads, keyed by namespace and key (long-term memory).
- Front
- What does a thread id select?
- Back
- Which saved state to load. Reuse it to continue; a new id starts fresh. Treat it as part of access control.
- Front
- Why not the in-memory saver in production?
- Back
- Checkpoints are in RAM and lost on restart, so paused runs and conversations vanish. Use a database-backed saver, and prune old checkpoints.
- Front
- How does interrupt pause and resume a run?
- Back
- interrupt saves state through the checkpointer and returns its payload to the caller. Invoking again with a resume command on the same thread continues; interrupt then returns the resume value.
- Front
- Where does execution restart after an interrupt?
- Back
- At the top of the same node, not the line after the call. Everything before interrupt runs again.
- Front
- Rules for using interrupt?
- Back
- Needs a checkpointer and thread id; JSON-serialisable payload; no bare try-except around it; stable interrupt order; no while-true loop (use a conditional edge); resume parallel interrupts with a map of ids.
- Front
- Static breakpoints or interrupt for approvals?
- Back
- interrupt. Static breakpoints (before or after a node) are a debugging aid; the docs do not recommend them for human-approval flows.
- Front
- What guarantee do outside side effects get after a failure or resume?
- Back
- At least once. A node that failed part-way re-runs from its start. Use idempotency keys or check for an existing result.
- Front
- How do you stop a duplicate approval from refunding twice?
- Back
- Send the refund with a stable key derived from the request, so a second resume is recognised and ignored. A fresh random key per attempt would not help.
- Front
- The three durability modes?
- Back
- exit (save only when the run ends: fastest, no mid-run recovery), async (save while the next step runs: small loss window), sync (save before the next step: safest, slowest).
- Front
- What does replay from a checkpoint do?
- Back
- Nodes before it are not re-run; nodes after it run again, so model calls and side effects happen again and may differ. Replaying from the final checkpoint does nothing.
- Front
- What does a fork do?
- Back
- Updates state at an earlier checkpoint and branches a new checkpoint from it. The original history stays intact. Later steps then run live.
- Front
- Wrong assumption at step 4 of 9: how to fix it?
- Back
- Fork from the checkpoint before step 4 with corrected state. Steps 1 to 3 are not redone; steps 4 to 9 run again, with their side effects.
LangSmith: tracing, datasets and evaluation
- Front
- Run, trace, thread, project?
- Back
- Run: one unit of work (a model call, a retrieval, a tool), like an OpenTelemetry span. Trace: the runs for one operation. Thread: traces of one conversation, grouped by a thread_id metadata key. Project: the container for one application's traces.
- Front
- How is tracing enabled for LangChain and LangGraph code?
- Back
- Environment variables: LANGSMITH_TRACING=true and LANGSMITH_API_KEY, with an optional LANGSMITH_PROJECT (default project name is default). Plain code uses a decorator or context manager.
- Front
- What do you add to every trace from day one?
- Back
- Tags and metadata: app version, model, prompt version, tenant, environment, and a thread id for conversations. Without them you cannot filter by version when a release goes wrong.
- Front
- Why do traces go missing in a serverless function?
- Back
- Tracing sends from a background thread and the process can exit first. Wait for tracers in a finally block, or make callbacks synchronous.
- Front
- How do you keep personal data out of traces?
- Back
- Redact before sending: flags that hide inputs or outputs, an anonymizer with regex rules or a function, or per-function processing. Decide region and retention too.
- Front
- The five-step method for debugging from a trace?
- Back
- Find the trace; read top down for the slow, costly or wrong run; check that run's exact inputs; classify the cause; reproduce, fix, and add the case to a dataset.
- Front
- How does a one-off failure become a permanent test?
- Back
- Add the failing trace to a dataset with the correct answer as a reference, so every later experiment runs it.
- Front
- Dataset, example, split, experiment?
- Back
- Dataset: a collection of examples. Example: inputs plus an optional reference output and metadata. Split: a named subset (an example can be in several). Experiment: one application version evaluated on a dataset.
- Front
- Who sees a reference output?
- Back
- Only evaluators. It is never passed to the application under test.
- Front
- Which evaluator type for what?
- Back
- Code: format, schema, exact match, thresholds. LLM judge: helpfulness, groundedness, tone (calibrate it). Human: ground truth and judge calibration. Pairwise: compare two versions when absolute scores are noisy.
- Front
- What extra should you score for an agent?
- Back
- The trajectory: right tools, right order, no redundant calls, within the step budget. A correct answer reached wastefully still has a problem.
- Front
- Offline versus online evaluation?
- Back
- Offline: curated datasets before release, with reference outputs. Online: sampled live runs and threads, with no reference outputs, so only reference-free checks such as format or groundedness.
- Front
- How do you make an evaluation score trustworthy?
- Back
- Calibrate the judge on human labels; compare versions on the same examples and look at slices; repeat runs for non-determinism; keep a hold-out set; watch for metric gaming; track cost and latency too.
- Front
- The judge says v2 is +6 points but users complain. What do you check?
- Back
- Judge bias (longer answers), the dataset not matching real questions, a slice that got worse, judge calibration, format versus usefulness. Compare length-controlled, sample recent production questions, read failures.
- Front
- What is an automation rule?
- Back
- An item type (runs or threads), a filter, a sampling rate and an action: annotation queue, dataset, webhook, online evaluator, code evaluator or extended retention. It can be backfilled to older runs.
- Front
- What does a good release gate require?
- Back
- An experiment on a pinned dataset version that beats the baseline with no slice worse, then a gradual release watched by online evaluators.
LangSmith Deployment: running agents in production
- Front
- Why do agents need more than a request handler?
- Back
- Runs are long, bursty, stateful, streaming, interruptible and sometimes scheduled. A plain handler hits timeouts, loses runs on deploy and cannot resume. A runtime supplies durable state, streaming and queues.
- Front
- Assistant, thread, run, store, checkpoint?
- Back
- Assistant: a graph plus configuration. Thread: one conversation's state container. Run: one execution. Store: memory across threads. Checkpoint: a snapshot so an interrupted run can resume.
- Front
- Where does the Agent Server keep what?
- Back
- Assistants, threads, runs and cron jobs always in PostgreSQL. Redis handles signalling, cancellation and streaming and holds only ephemeral data.
- Front
- How does a background run work?
- Back
- Create a run on a thread; the call returns before the work finishes. Check status later, join to wait, then read the final thread state.
- Front
- The hosting options?
- Back
- Cloud (vendor runs everything); hybrid (vendor control plane, your servers and data); self-hosted with control plane (your Kubernetes, enterprise); standalone server (you run it with Postgres, Redis and a licence); or build your own.
- Front
- What do you rebuild if you build your own runtime?
- Back
- Streaming with reconnect, resume after interrupt, queues, cron, and concurrency rules for new messages on a busy thread.
- Front
- Where is the lock-in?
- Back
- Graph code is open source and portable. The server runtime is the part you rent. Weigh it against the cost of rebuilding the runtime.
- Front
- The four double-texting strategies?
- Back
- Enqueue (default: finish, then run the new input), reject (refuse new runs while one is active), interrupt (halt, keep progress, add the input), rollback (halt, revert everything, restart with the new input).
- Front
- Which strategy for a chat product? For a transactional agent?
- Back
- Chat: usually interrupt or rollback, since the old run is stale. Transactional: enqueue or reject, because abandoning a half-done real action is risky; rollback does not undo a payment.
- Front
- What does the custom auth handler do?
- Back
- Runs on every request, validates credentials and returns the user's identity and extra fields. Self-hosted servers have no default authentication.
- Front
- How do you enforce thread ownership?
- Back
- Set an owner in thread metadata on create; return a filter on the caller's identity for reads and searches. Runs inherit their thread's access control; the store uses namespace rewriting.
- Front
- Budgets and safety for a deployed agent?
- Back
- Per-run caps (model calls, tool calls, time, money) and a set recursion limit; a kill switch and a degraded mode; identity from the auth context; idempotent tools; redacted traces; a deletion path across threads, checkpoints, store and traces.
- Front
- What must be true to deploy while runs are paused for approval?
- Back
- State is durable; the new graph reads the old state; node names and interrupt order stay stable; side effects are idempotent; the rollout is understood and tested.
- Front
- A safe release path for a prompt, model or graph change?
- Back
- Offline experiment beats the baseline with no slice worse, then a gradual release with online evaluators, pinned versions, and a rollback path for graph and prompt together.
LangChain ecosystem: interview drills
- Front
- The 90-second opener on LangChain, LangGraph and LangSmith?
- Back
- LangChain: common model interface and create_agent for the standard loop. LangGraph: the stateful runtime beneath, for state, checkpoints, interrupts, streaming. LangSmith: tracing, evaluation, deployment, for any framework. Start with the SDK, then create_agent, then a graph; name a case for using none.
- Front
- What closing line shows judgement?
- Back
- "For a single prompt with a typed answer I would call the provider SDK directly." Name the least machinery that does the job.
- Front
- Checkpoint storage per day?
- Back
- Conversations × saved steps × state size. 20,000 × 12 × 40 KB = 9.6 GB. Keep references in state, not documents, and set retention.
- Front
- Cost per resolved conversation?
- Back
- Cost per attempt ÷ resolution rate. 6 cents ÷ 0.7 ≈ 8.6 cents. Track it, not cost per call.
- Front
- Trace budget with 10% sampling plus all errors?
- Back
- Sampled traces plus the errors not already sampled: 2,000 + 0.9 × 600 = 2,540 a day for 20,000 conversations and 3% errors.
- Front
- Odds that all retries fail?
- Back
- Failure rate to the power of attempts, if independent: 0.05³ = 0.0125%. Real failures are correlated (an outage), so also add a fallback.
- Front
- The eight parts of a design answer for an approval agent?
- Back
- Clarify; shape (router, graph); state and memory; tools (idempotency, caps, ownership); guardrails and budgets; evaluation; deployment; failure modes.
- Front
- Where does the refund call go, and why?
- Back
- After the interrupt, with an idempotency key from the request. The node restarts on resume, so anything before the pause runs again; the key absorbs a duplicate resume.
- Front
- Markers of a strong design answer?
- Back
- Idempotency, authorisation, budgets and evaluation gates raised unprompted; retrieval separated from generation quality; what not to automate; cost per resolved ticket; a rollback story.
- Front
- A refund went out twice. First checks?
- Back
- A side effect before the interrupt; a duplicate resume; no idempotency key. Look at where the refund call sits relative to the interrupt.
- Front
- Chat forgets turns in production but not locally?
- Back
- No checkpointer, a new thread id per request, or an in-memory saver behind several replicas. Compare thread ids on consecutive traces.
- Front
- Bill tripled after a release?
- Back
- Defeated prompt cache, summarising off, more tool calls, bigger retrieved chunks, retries. Read tokens per run by run type in the traces.
- Front
- Evaluation score up, users unhappy?
- Back
- Judge bias, a dataset that no longer matches real questions, a slice that got worse, latency. Check scores by slice and read ten failures.