refactor(advance_phase): simplify previous_phase capture

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.
This commit is contained in:
chiguyong 2026-06-30 05:06:38 +08:00
parent 7869caddc7
commit ce6eb004a0
1 changed files with 3 additions and 20 deletions

View File

@ -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