research
Self-Correct Agent
An LLM agent that iteratively self-corrects its outputs
PythonLLMAgentsAI
View project
Overview
Self-Correct Agent is an open-source Python framework that implements iterative self-correction for large language model (LLM) agents. The core idea is to prompt the model to evaluate its own output and refine it in multiple passes, reducing hallucinations and improving factual accuracy.
Motivation
LLMs frequently produce confident but incorrect outputs. Self-correction allows agents to catch and fix their own errors without external validation, making them more reliable for deployment in automated pipelines.
Key contributions
- Iterative correction loop with configurable rounds and stopping criteria.
- Structured output validation (JSON schema-style constraints) so the agent can self-check format and missing fields.
- Backend-agnostic interface for swapping LLM providers without rewriting the agent logic.
Results (what improves)
- Reliability: fewer formatting failures when you need structured outputs (e.g., JSON for downstream automation).
- Robustness: better handling of “first attempt” mistakes via a deliberate review + revision phase.
How it works (high level)
- Draft answer
- Self-critique (identify issues, missing evidence, inconsistencies)
- Revise answer
- Optional: validate structure (when structured output is required)
Usage
from self_correct_agent import Agent
agent = Agent(model="claude-3-5-sonnet", max_rounds=3)
result = agent.run("Summarize the key findings of the 2023 IPCC report.")
print(result.final_answer)
Reproducibility
- Source: {externalUrl}
- Suggested eval: create a small prompt suite with known answers (or ground-truth links) and compare 1-pass vs multi-pass outputs across the same model.