Files

36 lines
1.4 KiB
Python
Raw Permalink Normal View History

"""Blockers and checkpoints for AGI state machine."""
from typing import Any, Protocol
from fusionagi.schemas.goal import Blocker, Checkpoint
from fusionagi._logger import logger
class BlockersAndCheckpoints:
"""Tracks blockers (why stuck) and checkpoints (resumable points)."""
def __init__(self) -> None:
self._blockers: dict[str, list[Blocker]] = {}
self._checkpoints: dict[str, list[Checkpoint]] = {}
def add_blocker(self, blocker: Blocker) -> None:
self._blockers.setdefault(blocker.task_id, []).append(blocker)
logger.info("Blocker added", extra={"task_id": blocker.task_id, "reason": blocker.reason[:80] if blocker.reason else ""})
def get_blockers(self, task_id: str) -> list[Blocker]:
return list(self._blockers.get(task_id, []))
def clear_blockers(self, task_id: str) -> None:
self._blockers.pop(task_id, None)
def add_checkpoint(self, checkpoint: Checkpoint) -> None:
self._checkpoints.setdefault(checkpoint.task_id, []).append(checkpoint)
logger.debug("Checkpoint added", extra={"task_id": checkpoint.task_id})
def get_latest_checkpoint(self, task_id: str) -> Checkpoint | None:
lst = self._checkpoints.get(task_id, [])
return lst[-1] if lst else None
def list_checkpoints(self, task_id: str) -> list[Checkpoint]:
return list(self._checkpoints.get(task_id, []))