Project Reference: LangGraph Multi-Step Agent with Memory + Tool Calling
Core Focus: Stateful Systems, Multi-Step Planning, Self-Healing Recovery, Runaway Loop Guards, and Human-in-the-Loop.
This guide provides verbatim framing, architectural trade-offs, and design justifications to ace technical screens, system design interviews, and take-home debriefs.
Q1. "Why build this agent using LangGraph StateGraph instead of standard LangChain chains or simple ReAct loops?"
Senior/Staff Response:
"Linear chains and simple ReAct loops break down in production enterprise environments because they treat agent execution as a black box without explicit state management. In a customer support scenario, we cannot afford an agent hallucinating that it already queried a database or getting stuck in a tool loop without our ability to inspect intermediate state.
By using LangGraph StateGraph, we achieve four critical production properties:
- Typed, Explicit State (
AgentState): The state is a first-class citizen holding messages, explicit working memory plans, error retry counters, and transition audit logs.
- Cyclical Directed Graph with Conditional Routing: The router node evaluates deterministic rules (runaway iteration caps, sensitive action flags) before deciding whether to dispatch tools or seek human intervention.
- Resumable State Checkpoints (
MemorySaver/ SQLite Checkpointer): The graph can pause execution at a node (e.g.human_approval), persist the execution snapshot to a thread ID, and resume hours later when an operator approves the action.
- Debuggability & Auditing: Every single transition (
from_node β to_node) is recorded in the state audit trail and traced to LangSmith."*
Senior/Staff Response:
"Runaway loops happen when an LLM encounters ambiguous outputs, tool errors, or cyclic reasoning traps, blowing through API budgets and degrading latency. We protect the system with a multi-layered guardrail:
- Stateful Iteration Counter (
iteration_count): Incremented on every pass throughplanner_node.
- Hard Safety Threshold (
MAX_ITERATIONS = 8): Evaluated inrouter_conditionon every routing decision.
- Graceful Abort Node (
abort_node): Ifiteration_count >= MAX_ITERATIONS, the router redirects toabort_nodeinstead of throwing an unhandled exception or hanging.
- Context Preservation: The abort node summarizes what the agent did accomplish from
working_memory["completed_steps"], flagsloop_detected = True, and generates a graceful customer-facing escalation ticket."*
Senior/Staff Response:
"In customer service and enterprise automation, tools fall into two categories: read-only/idempotent (querying orders, searching policy, calculating refunds, drafting text) and irreversible/side-effecting (dispatching outbound emails, charging credit cards, updating records).
In our architecture:
- We maintain a registry
SENSITIVE_TOOLS = {"send_email"}.- When the planner generates a tool call for
send_email,router_conditionintercepts it and routes tohuman_approval_node.- If unapproved, the node sets
human_approval_status = "pending"and the graph yields execution (pause_for_human β END). LangGraph's checkpointer saves the exact thread snapshot.- The operator reviews the draft in our dashboard and hits
/api/approvewithdecision: 'approved' | 'rejected' | 'edited'.- We update state via
graph.update_state()and callgraph.invoke(None, config). The node executes the approved action or notifies the agent of the operator's feedback."
Senior/Staff Response:
"Tool execution failures (bad SQL syntax, non-existent columns, timeouts, mathematical formatting errors) must never crash the backend worker process. We use a Defensive Execution + Self-Healing Router Pattern:
- Safe Tool Dispatch (
tool_execution_node): Each tool call runs inside a guardedtry...exceptblock. Exceptions are caught and converted into aToolMessage(status='error'), populatinglast_tool_errorin state.
- Conditional Error Edge (
tools_condition): Iflast_tool_erroris non-empty, execution routes torecovery_nodeinstead of back to the planner.
- Error Diagnosis & Strategy Recommendation:
- If a SQL error mentions
no such columnorno such table, recovery injects advice to invokedatabase_schemato introspect valid tables.- If tool retries exceed
MAX_TOOL_RETRIES, it falls back to an alternative tool likeweb_searchor asks the user for clarification.- This prevents cascading failures and demonstrates self-healing agentic behavior."
Q5. "Explain the difference between Short-Term Memory, Working Memory, and Episodic Memory in this project."
Senior/Staff Response:
"We implement a 3-tier memory hierarchy modeled after cognitive architectures:
Memory Tier Implementation Purpose & Scope Short-Term Memory add_messagesreducer +MemorySaverPreserves conversation context across multi-turn messages within the current thread_id.Working Memory Typed WorkingMemoryinAgentStateExplicit, dynamic multi-step plan ( plan), active step pointer (current_step_index), and completed step checklist (completed_steps).Episodic Memory ChromaDB Vector Store Long-term memory across distinct sessions. Recalls past interactions for the customer (e.g. Alice's past courtesy credit for a damaged box) using semantic embeddings. Before the planner node runs,
memory_recall_nodequeries ChromaDB and injects precedent context into the prompt. When the thread completes,memory_consolidation_nodeembeds and stores a summary into ChromaDB for future sessions."
Senior/Staff Response:
"We enable LangSmith via standard environment variables:
LANGCHAIN_TRACING_V2=true,LANGCHAIN_API_KEY, andLANGCHAIN_PROJECT. Every graph execution automatically publishes full run traces to the LangSmith dashboard, capturing:
- Exact inputs, latency, and token consumption of each node.
- Every tool dispatch and payload arguments.
- The conditional routing decisions and edge traversals.
- In parallel, we log internal state transitions in
state['state_transitions']for client-side auditing and observability."
- Step 1: Open Dashboard: Show the split-screen UI (
http://localhost:8000). Point out the StateGraph Flow on the right and Customer Context on the left. - Step 2: Run Scenario 1 (Happy Path & HITL):
- Click π― 1. Order Refund & HITL.
- Watch the nodes fire:
memory_recall(retrieves Alice's VIP status) βplannerβtools(database_querychecks ORD-901) βplannerβtools(calculatorcomputes 10% restocking fee) βplannerβtools(email_draft) βhuman_approval. - Show how the graph halts! The Human-In-The-Loop Checkpoint Banner appears with the drafted email.
- Click Approve & Send. The graph resumes, dispatches the email, consolidates memory into ChromaDB, and concludes.
- Step 3: Run Scenario 2 (Self-Healing Recovery):
- Click π‘οΈ 2. Self-Healing Recovery.
- Show how the bad SQL query does not crash the server; the
recovery_nodecatches it, suggests schema inspection, and self-corrects.
- Step 4: Run Scenario 3 (Runaway Loop Guard):
- Click π 3. Runaway Loop Guard.
- Demonstrate how
iteration_counthits the cap and halts with ticketLOOP-GUARD-8-8.
- Step 5: Inspect ChromaDB & Transitions:
- Click the Transitions Log tab to show every transition timestamped.
- Click the ChromaDB tab to show semantic session episodes.