From ce6eb004a0c4e5e3b743434c02b5d82603d28c20 Mon Sep 17 00:00:00 2001 From: chiguyong Date: Tue, 30 Jun 2026 05:06:38 +0800 Subject: [PATCH] refactor(advance_phase): simplify previous_phase capture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove over-engineered _previous_value static method that did index math on a hardcoded phase list. Instead, capture the previous phase before the transition — clearer intent, fewer lines, same behavior. ce-simplify-code step of LFG pipeline. --- src/agentkit/tools/advance_phase.py | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/src/agentkit/tools/advance_phase.py b/src/agentkit/tools/advance_phase.py index 87a3912..b750d3f 100644 --- a/src/agentkit/tools/advance_phase.py +++ b/src/agentkit/tools/advance_phase.py @@ -56,6 +56,8 @@ class AdvancePhaseTool(Tool): self._engine = engine async def execute(self, **kwargs) -> dict[str, Any]: + # Capture previous phase before transition (engine is single-threaded per request). + previous = self._engine.current_phase new_phase = self._engine.advance_phase() if new_phase is None: # Either no policy set, or already at DELIVERY. @@ -74,26 +76,7 @@ class AdvancePhaseTool(Tool): } return { "is_error": False, - "previous_phase": self._previous_value(new_phase), + "previous_phase": previous.value if previous else "", "current_phase": new_phase.value, "message": f"Phase advanced to {new_phase.value}.", } - - @staticmethod - def _previous_value(current: Any) -> str: - """Return the previous phase value (for telemetry/UI).""" - from agentkit.core.phase import PhaseState - - order = [ - PhaseState.PLANNING, - PhaseState.BUILDING, - PhaseState.VERIFICATION, - PhaseState.DELIVERY, - ] - try: - idx = order.index(current) - except ValueError: - return "" - if idx == 0: - return "" - return order[idx - 1].value