Udemy
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Building AI Self-Healing Agents with Python - 2026
28 students

Building AI Self-Healing Agents with Python - 2026

Practical, production ready, failure detection, recovery, escalations, LLM auto-corrections and more...
Created byAdnan Waheed
Last updated 5/2026
English

What you'll learn

  • Build a production AI agent in Python from scratch — model, tools, agent loop, all wired together using the Anthropic SDK.
  • Detect and diagnose failures like production teams do — six failure modes, an execution monitor, and a diagnostician that classifies root cause.
  • Implement three real recovery mechanisms — tool self-repair, prompt self-modification with safety guards, and strategy switching when plans fail.
  • Ship with confidence — failure memory, recovery scoring, graceful degradation, human escalation, a 19-test pytest suite, and a local FastAPI server.

Course content

1 section • 41 lectures • 6h 18m total length
  • What Is an Agent, Really?7:23

    Learn that an agent is a model, tools, and a loop, with the model deciding tool calls and the loop enabling multi-step actions; the course builds self-healing agents in Python.

  • Download Code and scripts0:15
  • Setup: Python, uv, and Anthropic6:25

    Set up python environment with uv, create a self healing agent project, install Entropic and pytest, and prepare an Entropic API key for the first API call in .env file.

  • Test our enviroment4:44
  • How to create your own tool18:06

    Define a tool by building a function, a schema, and a registry, then register it and drive a model to count words in text.

  • what are stop_reason?13:10

    Explore the stop reason concept in self-healing AI agents, distinguishing end turn and tool use, and how max token limits affect tool calls.

  • How does tool use blocks?14:35

    Explore how a model returns a list of typed blocks and how tools are invoked to fetch price and market cap data, with final results in the second call.

  • Your First Agent Loop16:10

    Build and test your first ai agent loop using a stock price tool with Apple, Microsoft, and Google, then explore typos, unknown tickers, and ambiguous questions to enable self-healing.

  • What "Failure" Actually Means8:59

    Explore six AI agent failure modes—wrong output, stuck loop, tool error, hallucination, timeout, cost blowout—and understand loud vs silent failures, plus detection via sanity checks, schema validation, and LLM critique.

  • Defining taxonomy for catching errors10:22
  • The Execution Monitor13:42

    Develop the execution monitor to produce a trace of every step—tool calls, model results, and outputs—capturing timing, results, errors, and a confidence score for detection and learning.

  • What is a Silent Failure Detection?4:04

    Detect silent failures by building a detector that reads the trace and output to emit failure objects, using sanity rules, structural checks, and an LLM self-critique in order for efficiency.

  • Code Silent Feature Detection18:49

    Build a silent detector class in Python that applies three safety checks—sanity rules, repetition detection, and an LLM critique—to flag failures and hallucinations.

  • Use silent detection in agent loop15:13
  • The Diagnostician5:44

    Diagnose failures by classifying them into five root causes—bad input, bad tool, bad prompt, bad model, and bad logic—and route targeted recoveries accordingly.

  • writing a diagnostician17:55

    Define a diagnostician with Cause, Diagnostics, and Diagnostician classes to analyze traces and failure codes, using an LLM to output JSON with cause, evidence, fix, and confidence.

  • Testing Diadnotics with cause, suggested fix9:28

    Build and test a Python diagnostician to classify failures, capture traces, evidence, and suggested fixes, and validate prompts and retry logic across three scenarios.

  • The self-repair tool7:21
  • agent with self-repair tool8:48
  • Prompt Self-Modification14:35

    Learn how to use prompt self-modification with delta edits to fix failing system prompts, balancing depth with the one-sentence constraint.

  • Strategy Switching13:26

    Discover how strategy switching lets ai agents generate diverse alternatives, score them, and pick the best approach, including chunked summarization and novel recovery strategies.

  • Creating a Short-Term Memory16:50
  • Creating a Long-Term Failure log15:49
  • Recovery Confidence Scorer12:36

    Introduce the recovery confidence score to determine whether a recovered output actually solves the task, using semantic comparison with the original failure and a strict 0–1 llm evaluation.

  • Graceful Degradation12:16
  • Human Escalation12:34
  • Adversarial Test Suite8:50

    This lecture introduces a 20-test adversarial suite to probe a self-healing agent's honest failure handling before production. It covers typo variants, tool failures, and prompt conflicts.

  • Using pytest6:37

    Learn to use pytest to build and run unit tests for AI agents, exploring test files like test_calculator, fixtures and parameterized tests, and validating self-healing behavior.

  • Test Suites - helper functions3:35
  • Test - Typos12:00

    Showcases pytest parametrized typo tests and adversary testing against an AI self-healing agent, capturing failures, evidence, confidence, and recovery actions to correct misinterpreted tickers like AAPL, APPL, MSTF, XYZ.

  • Test - Tool failures6:01
  • Test - Prompt conflicts5:49
  • Test - Loops5:21
  • Test - Silent failures4:57

    Explore unit tests for silent failures—invented citations, historical fabrication, and partial result disclosures—to build robust, self-healing AI agents with Python.

  • Test - Recovery5:25

    Explore recovery correctness testing for self-healing AI agents, including recovery logs, polite and genuine failures, and recovery score thresholds. Learn how unit tests across categories validate robust recovery behavior.

  • Test - All tests1:57
  • Create an Agent Server8:59

    Expose a self-healing agent via a Python FastAPI server with uvicorn. Create endpoints like run and health, using logging for production observability.

  • Testing the agent server with client8:26
  • Thank You!0:56

    Explore building self-healing AI agents in Python that know when they fail in production. Share your work with the community to learn, contribute, and ship honest systems that reveal failures.

  • My Other courses0:02
  • Your feedback is very valuable!0:28

Requirements

  • No prior agent framework experience needed
  • We build everything from scratch.

Description

Most agent tutorials teach you to build agents that work on the happy path.

Ticker is valid. API returns 200. Model doesn't hallucinate. Tool schema hasn't changed. Input is well-formed. Everyone's polite.

Then you ship it.

And at 3am on a Tuesday, your agent is stuck in a loop calling the same broken tool 47 times, burning through your API budget, returning confidently wrong answers to your users, and you're the one who has to fix it.


This course is about the other 90% of the job.


I'm going to teach you how to build an agent that detects its own failures, diagnoses why it failed, rewrites its own broken tool calls, modifies its own system prompt, switches strategies when one approach stops working, remembers its mistakes so it doesn't repeat them, and knows exactly when to escalate to a human instead of pretending it has the answer.


Not error handling. Genuine self-correction.


Over 14 modules, you'll build every component from scratch in Python —

  • The execution monitor,

  • The silent failure detector,

  • The diagnostician,

  • The tool repair layer,

  • The prompt self-modifier,

  • The strategy switcher,

  • Session and long-term memory,

  • Recovery scoring,

  • Graceful degradation, and

  • human escalation.


Then at the end, you'll run it against an adversarial test suite — 20 deliberate attacks designed to break your agent in every way agents break in production. Typos. Flaky tools. Prompt injections. Contradictory instructions. Hallucination bait. Poisoned memory.


If your agent recovers from all 20, you ship it.


By the end of this course, you will have built something most production teams haven't figured out yet — an agent that gets harder to break every single time it fails.


Your agent will fail. Teach it to fix itself.

  1. Agents that survive production.

  2. Self-Healing AI Agents in Python.

  3. Build an agent that gets harder to break every time it fails.

    Let's build it.

Who this course is for:

  • Developers who want a deep, hands-on project that goes beyond CRUD apps and toy chatbots.
  • Engineers who have been paged at 3am because an agent confidently returned a wrong answer to a real user.
  • Backend and API developers moving into AI work who want to learn agents the right way — without hiding behind a framework's abstractions.
  • Anyone who is willing to explore real, practical AI agents buildings