44 / 108 · 03 Agentic Testing Architectures · The Critic-Actor Pattern← prev⊞ allnext →☰ Read as one page
6.3Implementation
class CriticActorPipeline:
def __init__(self, actor: Agent, critic: Agent, max_rounds=3):
self.actor = actor
self.critic = critic
self.max_rounds = max_rounds
def generate_reviewed_tests(self, spec: str) -> TestSuite:
# Actor generates initial test suite
tests = self.actor.generate(spec)
print(f"Actor generated {len(tests)} tests")
for round_num in range(self.max_rounds):
# Critic reviews all tests
review = self.critic.review(tests, spec)
print(f"Round {round_num + 1}: "
f"{review.approved_count} approved, "
f"{review.revise_count} need revision, "
f"{review.rejected_count} rejected")
if review.approval_rate >= 0.9: # 90%+ tests approved
print(f"Critic satisfied after {round_num + 1} rounds")
break
# Actor revises based on critic feedback
tests = self.actor.revise(tests, review.feedback)
# Final suite: only approved tests
return TestSuite(tests=[t for t in tests if t.status == "approved"])