InterviewHubPRO
Section Overview
Q28

Question 28 of 50

Part 3: Agentic Workflows, Function Calling & MCP

56%
AI Engineering & LLMs (50 Qs)•Part 3: Agentic Workflows, Function Calling & MCP

Human-in-the-Loop (HITL) Workflows: Checkpoints, State Serialization & Resumption Tokens

1. Why Full Autonomy is Dangerous in Production

Autonomous agents must not execute destructive actions without human authorization:

  • Dropping production database tables or running schema migrations.
  • Executing financial payments or fund transfers.
  • Sending external customer-facing emails.
  • Merging PRs to main production branches.

A Human-in-the-Loop (HITL) architecture pauses agent execution, serializes state, alerts a human operator, and waits for cryptographic approval before proceeding.

vbnet
   Agent Plan ──► Step 1 (Read Repo) ──► Step 2 (Run Tests) ──► Step 3: [DROP DATABASE]
                                                                        │
                                                         ┌──────────────┴──────────────┐
                                                         ▼                             ▼
                                                [ Pause & Checkpoint ]        [ Send Slack Alert ]
                                                State saved to DB             "Approve / Reject?"
                                                         │                             │
                                                         ▼                             ▼
                                                Wait for Webhook ◄────────── Human Clicks "APPROVE"
                                                         │
                                                         ▼
                                                Resume Execution from exact checkpoint!

2. State Checkpointing & Resumption Architecture

python
from langgraph.checkpoint.sqlite import SqliteSaver
from langgraph.graph import StateGraph

# LangGraph native interrupt pattern
def critical_action_node(state):
    # This node triggers an interrupt before irreversible execution
    return {"status": "Database migration executed."}

memory = SqliteSaver.from_conn_string(":memory:")
workflow = StateGraph(...)
# Interrupt the graph immediately BEFORE executing critical_action
app = workflow.compile(checkpointer=memory, interrupt_before=["critical_action"])

# 1. Run until human approval required
config = {"configurable": {"thread_id": "thread-42"}}
for event in app.stream({"input": "Upgrade database schema"}, config):
    print(event) # Pauses before critical_action

# 2. Human reviews state, approves, and resumes execution
app.stream(None, config) # Resumes seamlessly from saved thread_id!