feat: added endpoint userinterrupt to userinterrupt
ref: N25B-400
This commit is contained in:
45
src/control_backend/agents/bdi/agentspeak.asl
Normal file
45
src/control_backend/agents/bdi/agentspeak.asl
Normal file
@@ -0,0 +1,45 @@
|
||||
phase("9922935f-ec70-4792-9a61-37a129e1ec14").
|
||||
keyword_said(Keyword) :- (user_said(Message) & .substring(Keyword, Message, Pos)) & (Pos >= 0).
|
||||
|
||||
|
||||
+!reply_with_goal(Goal)
|
||||
: user_said(Message)
|
||||
<- +responded_this_turn;
|
||||
.findall(Norm, norm(Norm), Norms);
|
||||
.reply_with_goal(Message, Norms, Goal).
|
||||
|
||||
+!say(Text)
|
||||
<- +responded_this_turn;
|
||||
.say(Text).
|
||||
|
||||
+!reply
|
||||
: user_said(Message)
|
||||
<- +responded_this_turn;
|
||||
.findall(Norm, norm(Norm), Norms);
|
||||
.reply(Message, Norms).
|
||||
|
||||
+user_said(Message)
|
||||
: phase("9922935f-ec70-4792-9a61-37a129e1ec14")
|
||||
<- .notify_user_said(Message);
|
||||
-responded_this_turn;
|
||||
!check_triggers;
|
||||
!transition_phase.
|
||||
|
||||
+!transition_phase
|
||||
: phase("9922935f-ec70-4792-9a61-37a129e1ec14") &
|
||||
not responded_this_turn
|
||||
<- -phase("9922935f-ec70-4792-9a61-37a129e1ec14");
|
||||
+phase("end");
|
||||
?user_said(Message);
|
||||
-+user_said(Message);
|
||||
.notify_transition_phase("9922935f-ec70-4792-9a61-37a129e1ec14", "end").
|
||||
|
||||
+user_said(Message)
|
||||
: phase("end")
|
||||
<- !reply.
|
||||
|
||||
+!check_triggers
|
||||
<- true.
|
||||
|
||||
+!transition_phase
|
||||
<- true.
|
||||
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
import json
|
||||
|
||||
import zmq
|
||||
@@ -30,6 +31,26 @@ class UserInterruptAgent(BaseAgent):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.sub_socket = None
|
||||
self.pub_socket = None
|
||||
|
||||
async def setup(self):
|
||||
"""
|
||||
Initialize the agent.
|
||||
|
||||
Connects the internal ZMQ SUB socket and subscribes to the 'button_pressed' topic.
|
||||
Starts the background behavior to receive the user interrupts.
|
||||
"""
|
||||
context = Context.instance()
|
||||
|
||||
self.sub_socket = context.socket(zmq.SUB)
|
||||
self.sub_socket.connect(settings.zmq_settings.internal_sub_address)
|
||||
self.sub_socket.subscribe("button_pressed")
|
||||
|
||||
self.pub_socket = context.socket(zmq.PUB)
|
||||
self.pub_socket.connect(settings.zmq_settings.internal_pub_address)
|
||||
|
||||
self.add_behavior(self._receive_button_event())
|
||||
self.add_behavior(self.test_sending_behaviour())
|
||||
|
||||
async def _receive_button_event(self):
|
||||
"""
|
||||
@@ -78,6 +99,33 @@ class UserInterruptAgent(BaseAgent):
|
||||
event_context,
|
||||
)
|
||||
|
||||
async def test_sending_behaviour(self):
|
||||
self.logger.info("Starting simple test sending behaviour...")
|
||||
|
||||
while True:
|
||||
try:
|
||||
test_data = {"type": "heartbeat", "status": "ok"}
|
||||
|
||||
await self._send_experiment_update(test_data)
|
||||
|
||||
except zmq.ZMQError as ze:
|
||||
self.logger.error(f"ZMQ error: {ze}")
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error: {e}")
|
||||
|
||||
await asyncio.sleep(2)
|
||||
|
||||
async def _send_experiment_update(self, data):
|
||||
"""
|
||||
Sends an update to the 'experiment' topic.
|
||||
The SSE endpoint will pick this up and push it to the UI.
|
||||
"""
|
||||
if self.pub_socket:
|
||||
topic = b"experiment"
|
||||
body = json.dumps(data).encode("utf-8")
|
||||
await self.pub_socket.send_multipart([topic, body])
|
||||
self.logger.debug(f"Sent experiment update: {data}")
|
||||
|
||||
async def _send_to_speech_agent(self, text_to_say: str):
|
||||
"""
|
||||
method to send prioritized speech command to RobotSpeechAgent.
|
||||
@@ -129,18 +177,3 @@ class UserInterruptAgent(BaseAgent):
|
||||
"Sent button_override belief with id '%s' to Program manager.",
|
||||
belief_id,
|
||||
)
|
||||
|
||||
async def setup(self):
|
||||
"""
|
||||
Initialize the agent.
|
||||
|
||||
Connects the internal ZMQ SUB socket and subscribes to the 'button_pressed' topic.
|
||||
Starts the background behavior to receive the user interrupts.
|
||||
"""
|
||||
context = Context.instance()
|
||||
|
||||
self.sub_socket = context.socket(zmq.SUB)
|
||||
self.sub_socket.connect(settings.zmq_settings.internal_sub_address)
|
||||
self.sub_socket.subscribe("button_pressed")
|
||||
|
||||
self.add_behavior(self._receive_button_event())
|
||||
|
||||
Reference in New Issue
Block a user