The Big One #43

Merged
k.marinus merged 93 commits from feat/reset-experiment-and-phase into dev 2026-01-26 19:20:45 +00:00
2 changed files with 20 additions and 1 deletions
Showing only changes of commit 4f927bc025 - Show all commits

View File

@@ -31,6 +31,7 @@ class BDIProgramManager(BaseAgent):
:ivar sub_socket: The ZMQ SUB socket used to receive program updates. :ivar sub_socket: The ZMQ SUB socket used to receive program updates.
:ivar _program: The current Program. :ivar _program: The current Program.
:ivar _phase: The current Phase. :ivar _phase: The current Phase.
:ivar _goal_mapping: A mapping of goal IDs to goals.
""" """
_program: Program _program: Program
@@ -39,6 +40,7 @@ class BDIProgramManager(BaseAgent):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self.sub_socket = None self.sub_socket = None
self._goal_mapping: dict[str, Goal] = {}
def _initialize_internal_state(self, program: Program): def _initialize_internal_state(self, program: Program):
""" """
@@ -49,7 +51,7 @@ class BDIProgramManager(BaseAgent):
""" """
self._program = program self._program = program
self._phase = program.phases[0] # start in first phase self._phase = program.phases[0] # start in first phase
self._goal_mapping: dict[str, Goal] = {} self._goal_mapping = {}
for phase in program.phases: for phase in program.phases:
for goal in phase.goals: for goal in phase.goals:
self._populate_goal_mapping_with_goal(goal) self._populate_goal_mapping_with_goal(goal)
@@ -107,6 +109,9 @@ class BDIProgramManager(BaseAgent):
:param old: The ID of the old phase. :param old: The ID of the old phase.
:param new: The ID of the new phase. :param new: The ID of the new phase.
""" """
if self._phase is None:
return
if old != str(self._phase.id): if old != str(self._phase.id):
self.logger.warning( self.logger.warning(
f"Phase transition desync detected! ASL requested move from '{old}', " f"Phase transition desync detected! ASL requested move from '{old}', "
@@ -146,6 +151,12 @@ class BDIProgramManager(BaseAgent):
def _extract_current_beliefs(self) -> list[Belief]: def _extract_current_beliefs(self) -> list[Belief]:
"""Extract beliefs from the current phase.""" """Extract beliefs from the current phase."""
assert self._phase is not None, (
"Invalid state, no phase set. Call this method only when "
"a program has been received and the end-phase has not "
"been reached."
)
beliefs: list[Belief] = [] beliefs: list[Belief] = []
for norm in self._phase.norms: for norm in self._phase.norms:
@@ -198,6 +209,12 @@ class BDIProgramManager(BaseAgent):
:return: A list of Goal objects. :return: A list of Goal objects.
""" """
assert self._phase is not None, (
"Invalid state, no phase set. Call this method only when "
"a program has been received and the end-phase has not "
"been reached."
)
goals: list[Goal] = [] goals: list[Goal] = []
for goal in self._phase.goals: for goal in self._phase.goals:

View File

@@ -335,6 +335,8 @@ class UserInterruptAgent(BaseAgent):
belief_name = f"force_{asl}" belief_name = f"force_{asl}"
else: else:
self.logger.warning("Tried to send belief with unknown type") self.logger.warning("Tried to send belief with unknown type")
return
belief = Belief(name=belief_name, arguments=None) belief = Belief(name=belief_name, arguments=None)
self.logger.debug(f"Sending belief to BDI Core: {belief_name}") self.logger.debug(f"Sending belief to BDI Core: {belief_name}")
# Conditional norms are unachieved by removing the belief # Conditional norms are unachieved by removing the belief