feat: end to end connected for demo

Includes the Transcription agent. Involved updating the RI agent to receive messages from other agents, sending speech commands to the RI agent, and some performance optimizations.

ref: N25B-216
This commit is contained in:
Twirre Meulenbelt
2025-10-30 10:42:25 +01:00
parent 657c300bc7
commit 86938f79c0
7 changed files with 132 additions and 49 deletions

View File

@@ -1,5 +1,7 @@
import json
import logging
import spade.agent
from spade.agent import Agent
from spade.behaviour import CyclicBehaviour
import zmq
@@ -31,6 +33,7 @@ class RICommandAgent(Agent):
self.bind = bind
class SendCommandsBehaviour(CyclicBehaviour):
"""Behaviour for sending commands received from the UI."""
async def run(self):
"""
Run the command publishing loop indefinetely.
@@ -49,6 +52,17 @@ class RICommandAgent(Agent):
except Exception as e:
logger.error("Error processing message: %s", e)
class SendPythonCommandsBehaviour(CyclicBehaviour):
"""Behaviour for sending commands received from other Python agents."""
async def run(self):
message: spade.agent.Message = await self.receive(timeout=0.1)
if message and message.to == self.agent.jid:
try:
speech_command = SpeechCommand.model_validate_json(message.body)
await self.agent.pubsocket.send_json(speech_command.model_dump())
except Exception as e:
logger.error("Error processing message: %s", e)
async def setup(self):
"""
Setup the command agent
@@ -70,5 +84,6 @@ class RICommandAgent(Agent):
# Add behaviour to our agent
commands_behaviour = self.SendCommandsBehaviour()
self.add_behaviour(commands_behaviour)
self.add_behaviour(self.SendPythonCommandsBehaviour())
logger.info("Finished setting up %s", self.jid)