Skip to content

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

fix(pipeline): honor verifier context reset (#2544)

buduoqiuc709ef19160e
diff --git a/src/agentscope/pipeline/_goal_pipeline.py b/src/agentscope/pipeline/_goal_pipeline.py
index 63c7278f4..822494b75 100644
--- a/src/agentscope/pipeline/_goal_pipeline.py
+++ b/src/agentscope/pipeline/_goal_pipeline.py
@@ -303,6 +303,10 @@ class GoalPipeline:
break_loop = True
else:
self._iters += 1
+ if self.verifier_reset_context:
+ # Only the conversation, tool/task state stays
+ self.verifier.state.context.clear()
+ self.verifier.state.summary = ""
if self._iters >= self.max_iters:
# Out of attempts; the work never passed
break_loop = True
diff --git a/tests/pipeline_goal_test.py b/tests/pipeline_goal_test.py
index 552260596..e65625948 100644
--- a/tests/pipeline_goal_test.py
+++ b/tests/pipeline_goal_test.py
@@ -67,8 +67,13 @@ class StubAgent:
"""Initialize the stub with one script entry per call."""
self.name = name
self.script = script
- self.state = SimpleNamespace(reply_id=f"{name}-reply")
+ self.state = SimpleNamespace(
+ reply_id=f"{name}-reply",
+ context=[],
+ summary="",
+ )
self.received: list[Any] = []
+ self.conversation_before_calls: list[tuple[list[Any], Any]] = []
# pylint: disable=unused-argument
async def reply_stream(
@@ -80,6 +85,9 @@ class StubAgent:
"""Yield the next batch, holding the final message back unless it
was asked for, the way ``Agent.reply_stream`` does."""
self.received.append(inputs)
+ self.conversation_before_calls.append(
+ (list(self.state.context), self.state.summary),
+ )
batch = self.script[min(len(self.received) - 1, len(self.script) - 1)]
for chunk in batch:
if isinstance(chunk, Msg) and not yield_final_msg:
@@ -132,6 +140,48 @@ class GoalPipelineTest(IsolatedAsyncioTestCase):
executor.received[1].get_text_content(),
)
+ async def test_resets_verifier_conversation_between_refused_rounds(
+ self,
+ ) -> None:
+ """The default keeps a refused verdict out of the next check."""
+ executor = StubAgent("executor", [[_report()], [_report()]])
+ verifier = StubAgent(
+ "verifier",
+ [[_verdict("fail", "try again")], [_verdict("pass")]],
+ )
+ prior = UserMsg("user", "prior verdict")
+ verifier.state.context.append(prior)
+ verifier.state.summary = "prior summary"
+ pipe = GoalPipeline(executor, verifier)
+
+ await self._run(pipe, self.query)
+
+ self.assertListEqual(
+ verifier.conversation_before_calls,
+ [([prior], "prior summary"), ([], "")],
+ )
+
+ async def test_can_keep_verifier_conversation_between_refused_rounds(
+ self,
+ ) -> None:
+ """Opting out preserves the verifier's existing conversation."""
+ executor = StubAgent("executor", [[_report()], [_report()]])
+ verifier = StubAgent(
+ "verifier",
+ [[_verdict("fail", "try again")], [_verdict("pass")]],
+ )
+ prior = UserMsg("user", "prior verdict")
+ verifier.state.context.append(prior)
+ verifier.state.summary = "prior summary"
+ pipe = GoalPipeline(executor, verifier, verifier_reset_context=False)
+
+ await self._run(pipe, self.query)
+
+ self.assertListEqual(
+ verifier.conversation_before_calls,
+ [([prior], "prior summary"), ([prior], "prior summary")],
+ )
+
async def test_stops_at_max_iters(self) -> None:
"""A verdict that never passes stops once the budget is spent."""
executor = StubAgent("executor", [[_report()]])