feat: stop experiment
This commit is contained in:
@@ -235,6 +235,39 @@ class AgentSpeakGenerator:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _add_stop_plan(self, phase: Phase):
|
||||||
|
"""
|
||||||
|
Adds a plan to stop the program. This just skips to the end phase,
|
||||||
|
where there is no behavior defined.
|
||||||
|
"""
|
||||||
|
self._asp.plans.append(
|
||||||
|
AstPlan(
|
||||||
|
TriggerType.ADDED_GOAL,
|
||||||
|
AstLiteral("stop"),
|
||||||
|
[AstLiteral("phase", [AstString(phase.id)])],
|
||||||
|
[
|
||||||
|
AstStatement(
|
||||||
|
StatementType.DO_ACTION,
|
||||||
|
AstLiteral(
|
||||||
|
"notify_transition_phase",
|
||||||
|
[
|
||||||
|
AstString(phase.id),
|
||||||
|
AstString("end")
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
AstStatement(
|
||||||
|
StatementType.REMOVE_BELIEF,
|
||||||
|
AstLiteral("phase", [AstVar("Phase")]),
|
||||||
|
),
|
||||||
|
AstStatement(
|
||||||
|
StatementType.ADD_BELIEF,
|
||||||
|
AstLiteral("phase", [AstString("end")])
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def _process_phases(self, phases: list[Phase]) -> None:
|
def _process_phases(self, phases: list[Phase]) -> None:
|
||||||
"""
|
"""
|
||||||
Processes all phases in the program and their transitions.
|
Processes all phases in the program and their transitions.
|
||||||
@@ -277,6 +310,9 @@ class AgentSpeakGenerator:
|
|||||||
for trigger in phase.triggers:
|
for trigger in phase.triggers:
|
||||||
self._process_trigger(trigger, phase)
|
self._process_trigger(trigger, phase)
|
||||||
|
|
||||||
|
# Add force transition to end phase
|
||||||
|
self._add_stop_plan(phase)
|
||||||
|
|
||||||
def _add_phase_transition(self, from_phase: Phase | None, to_phase: Phase | None) -> None:
|
def _add_phase_transition(self, from_phase: Phase | None, to_phase: Phase | None) -> None:
|
||||||
"""
|
"""
|
||||||
Adds plans for transitioning between phases.
|
Adds plans for transitioning between phases.
|
||||||
@@ -567,6 +603,7 @@ class AgentSpeakGenerator:
|
|||||||
- check_triggers: When no triggers are applicable
|
- check_triggers: When no triggers are applicable
|
||||||
- transition_phase: When phase transition conditions aren't met
|
- transition_phase: When phase transition conditions aren't met
|
||||||
- force_transition_phase: When forced transitions aren't possible
|
- force_transition_phase: When forced transitions aren't possible
|
||||||
|
- stop: When we are already in the end phase
|
||||||
"""
|
"""
|
||||||
# Trigger fallback
|
# Trigger fallback
|
||||||
self._asp.plans.append(
|
self._asp.plans.append(
|
||||||
@@ -598,6 +635,16 @@ class AgentSpeakGenerator:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Stop fallback
|
||||||
|
self._asp.plans.append(
|
||||||
|
AstPlan(
|
||||||
|
TriggerType.ADDED_GOAL,
|
||||||
|
AstLiteral("stop"),
|
||||||
|
[],
|
||||||
|
[AstStatement(StatementType.EMPTY, AstLiteral("true"))],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@singledispatchmethod
|
@singledispatchmethod
|
||||||
def _astify(self, element: ProgramElement) -> AstExpression:
|
def _astify(self, element: ProgramElement) -> AstExpression:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -176,6 +176,8 @@ class BDICoreAgent(BaseAgent):
|
|||||||
self._force_norm(msg.body)
|
self._force_norm(msg.body)
|
||||||
case "force_next_phase":
|
case "force_next_phase":
|
||||||
self._force_next_phase()
|
self._force_next_phase()
|
||||||
|
case "stop":
|
||||||
|
self._stop()
|
||||||
case _:
|
case _:
|
||||||
self.logger.warning("Received unknown user interruption: %s", msg)
|
self.logger.warning("Received unknown user interruption: %s", msg)
|
||||||
|
|
||||||
@@ -335,6 +337,11 @@ class BDICoreAgent(BaseAgent):
|
|||||||
|
|
||||||
self.logger.info("Manually forced phase transition.")
|
self.logger.info("Manually forced phase transition.")
|
||||||
|
|
||||||
|
def _stop(self):
|
||||||
|
self._set_goal("stop")
|
||||||
|
|
||||||
|
self.logger.info("Stopped the program (skipped to end phase).")
|
||||||
|
|
||||||
def _add_custom_actions(self) -> None:
|
def _add_custom_actions(self) -> None:
|
||||||
"""
|
"""
|
||||||
Add any custom actions here. Inside `@self.actions.add()`, the first argument is
|
Add any custom actions here. Inside `@self.actions.add()`, the first argument is
|
||||||
|
|||||||
@@ -164,6 +164,12 @@ class UserInterruptAgent(BaseAgent):
|
|||||||
else:
|
else:
|
||||||
self.logger.info("Sent resume command.")
|
self.logger.info("Sent resume command.")
|
||||||
|
|
||||||
|
case "stop":
|
||||||
|
self.logger.debug(
|
||||||
|
"Received stop command."
|
||||||
|
)
|
||||||
|
await self._send_stop_command()
|
||||||
|
|
||||||
case "next_phase" | "reset_phase":
|
case "next_phase" | "reset_phase":
|
||||||
await self._send_experiment_control_to_bdi_core(event_type)
|
await self._send_experiment_control_to_bdi_core(event_type)
|
||||||
case _:
|
case _:
|
||||||
@@ -423,3 +429,15 @@ class UserInterruptAgent(BaseAgent):
|
|||||||
await self.send(vad_message)
|
await self.send(vad_message)
|
||||||
# Voice Activity Detection and Visual Emotion Recognition agents
|
# Voice Activity Detection and Visual Emotion Recognition agents
|
||||||
self.logger.info("Sent resume command to VAD and VED agents.")
|
self.logger.info("Sent resume command to VAD and VED agents.")
|
||||||
|
|
||||||
|
async def _send_stop_command(self):
|
||||||
|
"""
|
||||||
|
Send a command to the BDI to stop the program (i.e., skip to end phase).
|
||||||
|
"""
|
||||||
|
msg = InternalMessage(
|
||||||
|
to=settings.agent_settings.bdi_core_name,
|
||||||
|
body="",
|
||||||
|
thread="stop"
|
||||||
|
)
|
||||||
|
|
||||||
|
await self.send(msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user