Skip to main content
The ready-to-run example is available here!

Overview

Iterative refinement is a powerful pattern where multiple agents work together in a feedback loop:
  1. A refactoring agent performs the main task (e.g., code conversion)
  2. A critique agent evaluates the quality and provides detailed feedback
  3. If quality is below threshold, the refactoring agent tries again with the feedback
This pattern is useful for:
  • Code refactoring and modernization (e.g., COBOL to Java)
  • Document translation and localization
  • Content generation with quality requirements
  • Any task requiring iterative improvement

How It Works

The Iteration Loop

The core workflow runs in a loop until quality threshold is met:

Critique Scoring

The critique agent evaluates each file on four dimensions (0-25 pts each):
  • Correctness: Does the Java code preserve the original business logic?
  • Code Quality: Is the code clean and following Java conventions?
  • Completeness: Are all COBOL features properly converted?
  • Best Practices: Does it use proper OOP, error handling, and documentation?

Feedback Loop

When the score is below threshold, the refactoring agent receives the critique file location:

Customization

Adjusting Thresholds

Using Real COBOL Files

The example uses sample files, but you can use real files from the AWS CardDemo project.

Ready-to-run Example

This example is available on GitHub: examples/01_standalone_sdk/31_iterative_refinement.py
examples/01_standalone_sdk/31_iterative_refinement.py
You can run the example code as-is.
The model name should follow the LiteLLM convention: provider/model_name (e.g., anthropic/claude-sonnet-4-5-20250929, openai/gpt-4o). The LLM_API_KEY should be the API key for your chosen provider.
ChatGPT Plus/Pro subscribers: You can use LLM.subscription_login() to authenticate with your ChatGPT account and access Codex models without consuming API credits. See the LLM Subscriptions guide for details.

Next Steps