Module 02

AI Agents and Workflows

M02·AI Agents and Workflows

Self-Correcting Agent

Build a self-correcting ReAct agent that catches tool errors, feeds them back to the LLM, and retries automatically. Error recovery with LangGraph.

Self-Correcting Agent

Your agent calls a tool with the wrong argument. The tool throws and your app crashes. This happens all the time in production, the LLM hallucinates a parameter and call tools incorrectly. Most ReAct implementations treat these as fatal errors but we can do a lot better.

We'll catch the exception, pack it into a ToolMessage, and feed it back to the model. The LLM reads the error, adjusts its arguments, retries. A well-formatted error message is just another piece of context the model can reason about.

Most LLMs can't self-correct reasoning on their own1, but they can when given external feedback2, and tool errors are exactly that. We'll rebuild the agent from the previous tutorial using LangGraph and add this error-recovery loop as the main feature.

What You'll Build

  • A stock screening agent built with LangGraph
  • Tool validation that raises errors with helpful messages
  • Exceptions formatted as ToolMessages for the LLM
  • Retry limits to prevent infinite loops

Setup

Members onlyJoin 900+ members
Members only from here
This lesson is part of the full AI engineering roadmap. Here's what unlocking gives you.
What you unlock
  • 01All 6 modules · 40+ hands-on tutorials
  • 02Source code, repositories, and architecture diagrams
  • 03Portfolio artifacts: apps, APIs, eval reports, dashboards, capstones
  • 04Live sessions + every recording
  • 05Discord community access
  • 06Certificate of completion with public verification URL
Price·lifetime
$299$197·Pay once

price goes up August 1

30-day money-back guarantee. One email, full refund.

or
“Best educational investment in my ML/AI journey.”
Ana Clara Medeiros·AI Developer
Instant access after paymentSecure checkout · stripe

Footnotes

  1. Large Language Models Cannot Self-Correct Reasoning Yet (Huang et al., ICLR 2024)

  2. When Can LLMs Actually Correct Their Own Mistakes? (Kamoi et al., TACL 2024)

  3. LangGraph Error Handling and Retry Policies