Skip to content

Build and run agents you can see, understand and trust.

fix(pipeline): scope the goal pipeline retry budget to one output generation (#3463)

Wilson_Jiang9162517cf435
diff --git a/src/agentscope/pipeline/_goal_pipeline.py b/src/agentscope/pipeline/_goal_pipeline.py
index 142e44cb1..7322ddf65 100644
--- a/src/agentscope/pipeline/_goal_pipeline.py
+++ b/src/agentscope/pipeline/_goal_pipeline.py
@@ -246,6 +246,9 @@ class GoalPipeline:
# The executor parked, so there is nothing to verify yet.
break
+ # Each report gets its own retry budget.
+ self._executor_retries = 0
+
# Verifier
final_msg = None
instruction = verifier_inputs or UserMsg(
@@ -335,6 +338,7 @@ class GoalPipeline:
"pass",
"impossible",
):
+ self._verifier_retries = 0
if final_msg.structured_output["result"] == "impossible":
logger.info(
"The verifier judged the goal impossible: %s",
@@ -343,6 +347,7 @@ class GoalPipeline:
# Settled either way, so the loop ends here.
break_loop = True
else:
+ self._verifier_retries = 0
self._iters += 1
if self.verifier_reset_context:
# Only the conversation, tool/task state stays
diff --git a/tests/pipeline_goal_test.py b/tests/pipeline_goal_test.py
index b22c1321e..3bde56ef6 100644
--- a/tests/pipeline_goal_test.py
+++ b/tests/pipeline_goal_test.py
@@ -377,6 +377,46 @@ class GoalPipelineTest(IsolatedAsyncioTestCase):
(1, 3),
)
+ async def test_executor_can_retry_in_each_round(self) -> None:
+ """Each report can use the full retry budget."""
+ missing = _no_output("executor")
+ first, second = _report("v1"), _report("v2")
+ executor = StubAgent(
+ "executor",
+ [[missing], [first], [missing], [second]],
+ )
+ verifier = StubAgent(
+ "verifier",
+ [[_verdict("fail", "fix it")], [_verdict("pass")]],
+ )
+ pipe = GoalPipeline(executor, verifier, max_retries=1)
+
+ yielded = await self._run(pipe, self.query)
+
+ self.assertEqual(yielded, [missing, first, missing, second])
+ self.assertEqual(
+ (len(executor.received), len(verifier.received)),
+ (4, 2),
+ )
+
+ async def test_verifier_can_retry_in_each_round(self) -> None:
+ """Each verdict can use the full retry budget."""
+ first, second = _report("v1"), _report("v2")
+ executor = StubAgent("executor", [[first], [second]])
+ verifier = StubAgent(
+ "verifier",
+ [[], [_verdict("fail", "fix it")], [], [_verdict("pass")]],
+ )
+ pipe = GoalPipeline(executor, verifier, max_retries=1)
+
+ yielded = await self._run(pipe, self.query)
+
+ self.assertEqual(yielded, [first, second])
+ self.assertEqual(
+ (len(executor.received), len(verifier.received)),
+ (2, 4),
+ )
+
async def test_a_fresh_run_restarts_the_retry_budget(self) -> None:
"""Each participant can retry again after a previous run failed."""
for participant in ("executor", "verifier"):