chore: cond_norms unachieve and via belief msg
This commit is contained in:
@@ -26,7 +26,7 @@ class UserInterruptAgent(BaseAgent):
|
|||||||
|
|
||||||
- Send a prioritized message to the `RobotSpeechAgent`
|
- Send a prioritized message to the `RobotSpeechAgent`
|
||||||
- Send a prioritized gesture to the `RobotGestureAgent`
|
- Send a prioritized gesture to the `RobotGestureAgent`
|
||||||
- Send a belief override to the `BDIProgramManager`in order to activate a
|
- Send a belief override to the `BDI Core` in order to activate a
|
||||||
trigger/conditional norm or complete a goal.
|
trigger/conditional norm or complete a goal.
|
||||||
|
|
||||||
Prioritized actions clear the current RI queue before inserting the new item,
|
Prioritized actions clear the current RI queue before inserting the new item,
|
||||||
@@ -75,7 +75,9 @@ class UserInterruptAgent(BaseAgent):
|
|||||||
These are the different types and contexts:
|
These are the different types and contexts:
|
||||||
- type: "speech", context: string that the robot has to say.
|
- type: "speech", context: string that the robot has to say.
|
||||||
- type: "gesture", context: single gesture name that the robot has to perform.
|
- type: "gesture", context: single gesture name that the robot has to perform.
|
||||||
- type: "override", context: belief_id that overrides the goal/trigger/conditional norm.
|
- type: "override", context: id that belongs to the goal/trigger/conditional norm.
|
||||||
|
- type: "override_unachieve", context: id that belongs to the conditional norm to unachieve.
|
||||||
|
- type: "next_phase", context: None, indicates to the BDI Core to
|
||||||
- type: "pause", context: boolean indicating whether to pause
|
- type: "pause", context: boolean indicating whether to pause
|
||||||
- type: "reset_phase", context: None, indicates to the BDI Core to
|
- type: "reset_phase", context: None, indicates to the BDI Core to
|
||||||
- type: "reset_experiment", context: None, indicates to the BDI Core to
|
- type: "reset_experiment", context: None, indicates to the BDI Core to
|
||||||
@@ -93,19 +95,20 @@ class UserInterruptAgent(BaseAgent):
|
|||||||
|
|
||||||
self.logger.debug("Received event type %s", event_type)
|
self.logger.debug("Received event type %s", event_type)
|
||||||
|
|
||||||
if event_type == "speech":
|
match event_type:
|
||||||
|
case "speech":
|
||||||
await self._send_to_speech_agent(event_context)
|
await self._send_to_speech_agent(event_context)
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
"Forwarded button press (speech) with context '%s' to RobotSpeechAgent.",
|
"Forwarded button press (speech) with context '%s' to RobotSpeechAgent.",
|
||||||
event_context,
|
event_context,
|
||||||
)
|
)
|
||||||
elif event_type == "gesture":
|
case "gesture":
|
||||||
await self._send_to_gesture_agent(event_context)
|
await self._send_to_gesture_agent(event_context)
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
"Forwarded button press (gesture) with context '%s' to RobotGestureAgent.",
|
"Forwarded button press (gesture) with context '%s' to RobotGestureAgent.",
|
||||||
event_context,
|
event_context,
|
||||||
)
|
)
|
||||||
elif event_type == "override":
|
case "override":
|
||||||
ui_id = str(event_context)
|
ui_id = str(event_context)
|
||||||
if asl_trigger := self._trigger_map.get(ui_id):
|
if asl_trigger := self._trigger_map.get(ui_id):
|
||||||
await self._send_to_bdi("force_trigger", asl_trigger)
|
await self._send_to_bdi("force_trigger", asl_trigger)
|
||||||
@@ -114,9 +117,9 @@ class UserInterruptAgent(BaseAgent):
|
|||||||
event_context,
|
event_context,
|
||||||
)
|
)
|
||||||
elif asl_cond_norm := self._cond_norm_map.get(ui_id):
|
elif asl_cond_norm := self._cond_norm_map.get(ui_id):
|
||||||
await self._send_to_bdi("force_norm", asl_cond_norm)
|
await self._send_to_bdi_belief(asl_cond_norm)
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
"Forwarded button press (override) with context '%s' to BDIProgramManager.",
|
"Forwarded button press (override) with context '%s' to BDI Core.",
|
||||||
event_context,
|
event_context,
|
||||||
)
|
)
|
||||||
elif asl_goal := self._goal_map.get(ui_id):
|
elif asl_goal := self._goal_map.get(ui_id):
|
||||||
@@ -125,7 +128,7 @@ class UserInterruptAgent(BaseAgent):
|
|||||||
"Forwarded button press (override) with context '%s' to BDI Core.",
|
"Forwarded button press (override) with context '%s' to BDI Core.",
|
||||||
event_context,
|
event_context,
|
||||||
)
|
)
|
||||||
|
# Send achieve_goal to program manager to update semantic belief extractor
|
||||||
goal_achieve_msg = InternalMessage(
|
goal_achieve_msg = InternalMessage(
|
||||||
to=settings.agent_settings.bdi_program_manager_name,
|
to=settings.agent_settings.bdi_program_manager_name,
|
||||||
thread="achieve_goal",
|
thread="achieve_goal",
|
||||||
@@ -135,8 +138,21 @@ class UserInterruptAgent(BaseAgent):
|
|||||||
await self.send(goal_achieve_msg)
|
await self.send(goal_achieve_msg)
|
||||||
else:
|
else:
|
||||||
self.logger.warning("Could not determine which element to override.")
|
self.logger.warning("Could not determine which element to override.")
|
||||||
|
case "override_unachieve":
|
||||||
|
ui_id = str(event_context)
|
||||||
|
if asl_cond_norm := self._cond_norm_map.get(ui_id):
|
||||||
|
await self._send_to_bdi_belief(asl_cond_norm, True)
|
||||||
|
self.logger.info(
|
||||||
|
"Forwarded button press (override_unachieve)"
|
||||||
|
"with context '%s' to BDI Core.",
|
||||||
|
event_context,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.logger.warning(
|
||||||
|
"Could not determine which conditional norm to unachieve."
|
||||||
|
)
|
||||||
|
|
||||||
elif event_type == "pause":
|
case "pause":
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
"Received pause/resume button press with context '%s'.", event_context
|
"Received pause/resume button press with context '%s'.", event_context
|
||||||
)
|
)
|
||||||
@@ -146,9 +162,9 @@ class UserInterruptAgent(BaseAgent):
|
|||||||
else:
|
else:
|
||||||
self.logger.info("Sent resume command.")
|
self.logger.info("Sent resume command.")
|
||||||
|
|
||||||
elif event_type in ["next_phase", "reset_phase", "reset_experiment"]:
|
case "next_phase" | "reset_phase" | "reset_experiment":
|
||||||
await self._send_experiment_control_to_bdi_core(event_type)
|
await self._send_experiment_control_to_bdi_core(event_type)
|
||||||
else:
|
case _:
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
"Received button press with unknown type '%s' (context: '%s').",
|
"Received button press with unknown type '%s' (context: '%s').",
|
||||||
event_type,
|
event_type,
|
||||||
@@ -195,9 +211,10 @@ class UserInterruptAgent(BaseAgent):
|
|||||||
await self._send_experiment_update(payload)
|
await self._send_experiment_update(payload)
|
||||||
self.logger.info(f"UI Update: Goal {goal_name} started (ID: {ui_id})")
|
self.logger.info(f"UI Update: Goal {goal_name} started (ID: {ui_id})")
|
||||||
case "active_norms_update":
|
case "active_norms_update":
|
||||||
norm_list = [s.strip("() '\",") for s in msg.body.split(",") if s.strip("() '\",")]
|
active_norms_asl = [
|
||||||
|
s.strip("() '\",") for s in msg.body.split(",") if s.strip("() '\",")
|
||||||
await self._broadcast_cond_norms(norm_list)
|
]
|
||||||
|
await self._broadcast_cond_norms(active_norms_asl)
|
||||||
case _:
|
case _:
|
||||||
self.logger.debug(f"Received internal message on unhandled thread: {msg.thread}")
|
self.logger.debug(f"Received internal message on unhandled thread: {msg.thread}")
|
||||||
|
|
||||||
@@ -308,12 +325,15 @@ class UserInterruptAgent(BaseAgent):
|
|||||||
await self.send(msg)
|
await self.send(msg)
|
||||||
self.logger.info(f"Directly forced {thread} in BDI: {body}")
|
self.logger.info(f"Directly forced {thread} in BDI: {body}")
|
||||||
|
|
||||||
async def _send_to_bdi_belief(self, asl_goal: str):
|
async def _send_to_bdi_belief(self, asl_goal: str, unachieve: bool = False):
|
||||||
"""Send belief to BDI Core"""
|
"""Send belief to BDI Core"""
|
||||||
belief_name = f"achieved_{asl_goal}"
|
belief_name = f"achieved_{asl_goal}"
|
||||||
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}")
|
||||||
belief_message = BeliefMessage(create=[belief])
|
# Conditional norms are unachieved by removing the belief
|
||||||
|
belief_message = (
|
||||||
|
BeliefMessage(delete=[belief]) if unachieve else BeliefMessage(create=[belief])
|
||||||
|
)
|
||||||
msg = InternalMessage(
|
msg = InternalMessage(
|
||||||
to=settings.agent_settings.bdi_core_name,
|
to=settings.agent_settings.bdi_core_name,
|
||||||
thread="beliefs",
|
thread="beliefs",
|
||||||
|
|||||||
Reference in New Issue
Block a user