Appearance
Phase 6: Stateful Graphs, Persistence & Human-in-the-Loop β
Canonical Source of Trust: Google Doc Tab
Phase 6
Training Program: [Huy Chau] Generative AI Training Plan
Stateful Graphs & Human-in-the-Loop β
1. What to Learn β
- Stateful Orchestration: Transitioning from linear chains to Directed Cyclic Graphs (DCGs) using LangGraph 1.0 to manage iterative loops and complex logic
- The Shared State Object: Defining a strongly typed state (usually via Python TypedDict) that persists across the entire workflow, allowing nodes to read and write to a common "backpack" of data.
- Durable Persistence: Implementing Checkpointers to save snapshots of the graph state at every "superstep" (node execution), enabling failure recovery and "time travel" debugging.
- Human-in-the-Loop (HITL) Patterns:
- Interrupts: Using the interrupt primitive to pause execution for human review or modification.
- Resumption: Using Command(resume=...) to feed human feedback back into the graph.
- The Functional API: Using @entrypoint and @task decorators to add persistence and memory to standard Python functions, allowing for a lower learning curve in building durable apps
- Tracing Hierarchy:
- The Thread as the Unit of Observation for Stateful Workflows
- Session Continuity across Checkpoints and Interrupts via thread_id
- **Online Evaluation: **
- Real-Time Production Sampling
- LLM-as-a-Judge Scoring on Live Traffic
- Automated Quality Thresholds
- **Evaluation Lifecycle: **
- Offline Evaluation (Unit Tests) vs. Online Evaluation (Production Sampling)
- Configuring LangFuse Monitors to Alert on Hallucination Rates Exceeding Defined Thresholds
- Compulsory Security:
- Privileged Action Gates: Designing Privileged Action Gates (RBAC/ABAC, Contextual Validation, Execution Authorization) to block irreversible actions (e.g., data deletion) without human validation and generating an Audit Trail of Reasoning
- Sandbox Enforcement: Hardened tool/filesystem boundaries to prevent "Rogue Agent" behavior
2. How to Learn β
- State Schema Design: Practice defining robust state structures using TypedDict or Pydantic to avoid "silent data loss" during complex transitions.
- Non-Linear Logic Drills: Build workflows that can loop back to a previous step, for instance, an agent that retrieves more data only if its initial answer fails a self-verification check.
- Visual Debugging: Using LangGraph Studio to observe real-time state transitions and identify bottlenecks or "doom loops" in complex multi-agent graphs.
- State Resumption Drills: Simulating a server crash during a multi-day agent task and practicing resuming state perfectly from a specific thread_id.
- Interrupt Implementation: Building a workflow where a "Sensitive Tool" cannot be invoked until a Command(resume=True) is received from the user.
- Serialization Testing: Practicing JSON-serializable inputs and outputs to ensure workflows can be saved and restored without runtime errors
3. Where to Learn β
- **E-book: **AI Agents and Applications (Part 5, Chapters 11β14)
- Technical Documentation: Functional API overview and Context engineering in agents (LangChain Docs).
- Advanced Framework Guides: LangGraph 1.0: The Durable Agent Framework and The Complete Guide to LangChain & LangGraph (2025/2026).
- Practical Tutorials: Multi-Agent Systems with LangGraph (DataCamp).
- Security Standard: OWASP Top 10 for LLM and Agentic Applications (2025/2026)
4. Subjective Outputs Required β
- The Stateful Essayist: A fully functional workflow that writes an essay, executes an interrupt for a human to approve the draft, and then either finishes or loops back to "rewrite" based on the human's input.
- The Privileged Action Gatekeeper: A security-focused agent that requires a native human-in-the-loop checkpoint before executing high-impact tools, such as processing a refund or deleting data.
- The Multi-Agent Research Pipeline: A coordinated system of at least three specialized agents (e.g., Planner, Executor, and Critic) that share a global state to produce a comprehensive technical report.
- Durable Execution Proof: A documented case where an agentic run was interrupted (simulating a crash), resumed from a checkpoint, and successfully completed the task without re-running expensive upstream tasks.
- Audit Trail Proof: A verifiable LangFuse trace showing the agent's internal monologue, the specific human-in-the-loop decision, and the final outcome