Agent Foundry
All Problems

#79. Critic-Generator Loop

MediumMulti-AgentEvaluation

The Problem

You have a content-generation agent that produces product descriptions in a single pass. The output quality is inconsistent — sometimes great, sometimes mediocre. You need to add a critic agent that reviews each draft and provides actionable feedback, and a loop so the generator can revise until the critic is satisfied (or a maximum number of iterations is reached). The starter code only does one-shot generation with no review.

Examples

Example 1

User input: Product: wireless noise-cancelling headphones

Current (bad) output: A single draft that may be bland, too short, or miss key selling points — with no review or revision.

Expected (good) output: The generator produces a first draft. The critic reviews it (e.g., "Missing mention of battery life; tone is too technical"). The generator revises incorporating that feedback. The critic approves the second draft, and the final polished description is returned.

Example 2

User input: Product: ergonomic standing desk

Current (bad) output: A one-shot description that undersells the product.

Expected (good) output: After 1–2 rounds of critic feedback and generator revision, a polished description that highlights key features, benefits, and a compelling call to action.

Your Task

Extend the starter code so that:

  • A critic agent reviews each generated draft and provides specific improvement suggestions.
  • The generator receives the critic's feedback and produces a revised draft.
  • This loop continues until the critic approves the draft or a maximum iteration count (e.g., 3) is reached.
  • Both agents remain separate with distinct roles.

Evaluation

Submissions are checked for the following:

  • Review loop implemented: The generator and critic run in a loop where feedback leads to revision.
  • Critic provides actionable feedback: The critic agent reviews the draft and returns specific improvement suggestions.
  • Generator incorporates feedback: The generator uses the critic's feedback to produce an improved draft.
  • Loop terminates correctly: The loop stops when quality is met or a maximum iteration count is reached.

Constraints

  • The generator and critic must be separate agents
  • The loop must terminate when quality criteria are met or a max iteration count is reached
  • The critic must provide actionable feedback, not just a pass/fail
  • The generator must incorporate critic feedback in subsequent attempts
Starter Code
from crewai import Agent, Task, Crew, Process
from crewai import LLM

llm = LLM(model="gpt-4o-mini")

generator = Agent(
    role="Content Generator",
    goal="Write a compelling product description",
    backstory="You are a creative copywriter.",
    llm=llm,
)

critic = Agent(
    role="Quality Critic",
    goal="Review content and provide improvement suggestions",
    backstory="You are a senior editor with high standards.",
    llm=llm,
)

# BUG: One-shot generation — the critic never reviews the output
# TODO: Add a review loop so the critic checks and the generator revises
generate_task = Task(
    description="Write a product description for {product}",
    expected_output="A compelling 100-word product description",
    agent=generator,
)

crew = Crew(
    agents=[generator],
    tasks=[generate_task],
    process=Process.sequential,
)

result = crew.kickoff(inputs={"product": "wireless noise-cancelling headphones"})
print(result)
Open in Google Colab
Evaluation Criteria0/4