First of all, if a human makes a mistake it’s a learning opportunity. When a human misses a bug an LLM hallucinated, noone really learn from it.
Agents can "learn" from their mistakes within their harness.
You or the agent can add notes in the memory files or the repo level agents.md files, or standards and conventions files to look for those mistakes.
Most harnesses these days will spin up a new agent to do a review once the implementation is done, that agent will take memory files, agents.md files and other standards and conventions files into its context to know what to look out for so it won't make the same mistake twice
Claude code is even doing "dreaming" where it'll do a cron every night to look through all the conversations from the day for stuff it messed up on and add to its memory files to not do those same mistakes.