Module 02

AI Agents and Workflows

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.

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

Membership requiredJoin 855+ members
Access Denied
This tutorial is part of the full AI engineering roadmap.
What you unlock
  • 01All 6 modules · 40+ tutorials · source code
  • 02Verifiable certificate with public URL
  • 03LinkedIn-ready completion credential
  • 04Live sessions + every recording
  • 05Discord community
Price·monthly
$39/mo·Cancel anytime
“Best educational investment in my ML/AI journey.”
— Ana Clara Medeiros·AI Developer
30-day money-back guaranteeInstant 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