Cyclic Self-Correcting LangGraph: Generate, Critique, Revise with Loop Guard
Advanced · 30 minutes · 5 tasks, checked automatically · 100 points
Build a stateful LangGraph pipeline that cycles through three nodes — Generate, Critique, and Revise — until the critique node signals the output is acceptable or a hard loop counter stops runaway execution. You will wire conditional edges that read loop state, observe the graph halt cleanly at the limit, and confirm the final state captures every iteration. This lab is foundational for any agentic workflow that needs self-improvement without infinite recursion.
What you’ll learn
- Install LangGraph, langchain-core, and langchain-ollama into the toolbox container
- Define a TypedDict state schema that tracks draft text, critique feedback, iteration count, and an accepted flag
- Implement Generate, Critique, and Revise nodes that call the local qwen2.5:3b model
- Wire a conditional edge after Critique that routes to Revise when rejected, to END when accepted, and to END when the loop limit is reached
- Run the graph and verify it terminates within the hard limit and writes a JSON log of every iteration to /root/lab/run_log.json
How this lab works
- Start the lab: One click starts a sandbox with a local model and the agent’s toolbox: no API key and no token bill.
- Work through 5 tasks: Each task says what to build or fix. You do it yourself, in a real terminal, with hints when you get stuck.
- Check your work: Check my work inspects the agent, its config and its output, and says what passed and what to fix.
- Finish and keep going: 100 points, your progress saved, and the next lab to try.
What it runs on
- Runs: Locally, against a model on your computer: no API key, no tokens
- Model: qwen2.5:3b
- Open source: github.com/langchain-ai/langgraph
What you need
- A free LearnXops account
- The LearnXops desktop app for macOS, Windows or Linux
- Docker Desktop (or Podman / Rancher Desktop) installed and running
- A model sandbox started in the Agent Playground
Topics: langgraph, cyclic-graph, self-correction, loop-guard, conditional-edges, state-management, ollama, qwen2.5, automation
Create a free account to start this lab.
Keep going
- Autonomous File Triage & Daily Digest with OpenClaw
- Drive a Codebase with Hermes: ripgrep Search, Multi-File Edits, and Running the Test Suite from the Agent Loop
- Build a Research-and-Write Crew with Local Documents
- CrewAI Flows: Deterministic Control with Branching, Retries, and Shared State
- Self-Correcting LangGraph on Claude: Generate, Critique, Revise
- Hermes Self-Skill Engineering: Teach the Agent to Teach Itself