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:
parent
da4eef1349
commit
5a0554b27f
|
|
@ -56,6 +56,8 @@ class AdvancePhaseTool(Tool):
|
||||||
self._engine = engine
|
self._engine = engine
|
||||||
|
|
||||||
async def execute(self, **kwargs) -> dict[str, Any]:
|
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()
|
new_phase = self._engine.advance_phase()
|
||||||
if new_phase is None:
|
if new_phase is None:
|
||||||
# Either no policy set, or already at DELIVERY.
|
# Either no policy set, or already at DELIVERY.
|
||||||
|
|
@ -74,26 +76,7 @@ class AdvancePhaseTool(Tool):
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
"is_error": False,
|
"is_error": False,
|
||||||
"previous_phase": self._previous_value(new_phase),
|
"previous_phase": previous.value if previous else "",
|
||||||
"current_phase": new_phase.value,
|
"current_phase": new_phase.value,
|
||||||
"message": f"Phase advanced to {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
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue