Refactoring agent and behaviour naming and structure. #25
@@ -1 +0,0 @@
|
|||||||
from .act_speech_agent import ActSpeechAgent as ActSpeechAgent
|
|
||||||
1
src/control_backend/agents/actuation/__init__.py
Normal file
1
src/control_backend/agents/actuation/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from .robot_speech_agent import RobotSpeechAgent as RobotSpeechAgent
|
||||||
@@ -10,7 +10,7 @@ from control_backend.core.config import settings
|
|||||||
from control_backend.schemas.ri_message import SpeechCommand
|
from control_backend.schemas.ri_message import SpeechCommand
|
||||||
|
|
||||||
|
|
||||||
class ActSpeechAgent(BaseAgent):
|
class RobotSpeechAgent(BaseAgent):
|
||||||
subsocket: zmq.Socket
|
subsocket: zmq.Socket
|
||||||
pubsocket: zmq.Socket
|
pubsocket: zmq.Socket
|
||||||
address = ""
|
address = ""
|
||||||
@@ -64,7 +64,7 @@ class ActSpeechAgent(BaseAgent):
|
|||||||
|
|
||||||
async def setup(self):
|
async def setup(self):
|
||||||
"""
|
"""
|
||||||
Setup the command agent
|
Setup the robot speech command agent
|
||||||
"""
|
"""
|
||||||
self.logger.info("Setting up %s", self.jid)
|
self.logger.info("Setting up %s", self.jid)
|
||||||
|
|
||||||
7
src/control_backend/agents/bdi/__init__.py
Normal file
7
src/control_backend/agents/bdi/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from .bdi_core_agent.bdi_core_agent import BDICoreAgent as BDICoreAgent
|
||||||
|
from .belief_collector_agent.belief_collector_agent import (
|
||||||
|
BDIBeliefCollectorAgent as BDIBeliefCollectorAgent,
|
||||||
|
)
|
||||||
|
from .text_belief_extractor_agent.text_belief_extractor_agent import (
|
||||||
|
TextBeliefExtractorAgent as TextBeliefExtractorAgent,
|
||||||
|
)
|
||||||
@@ -57,7 +57,7 @@ class BDICoreAgent(BDIAgent):
|
|||||||
class SendBehaviour(OneShotBehaviour):
|
class SendBehaviour(OneShotBehaviour):
|
||||||
async def run(self) -> None:
|
async def run(self) -> None:
|
||||||
msg = Message(
|
msg = Message(
|
||||||
to=settings.agent_settings.llm_agent_name + "@" + settings.agent_settings.host,
|
to=settings.agent_settings.llm_name + "@" + settings.agent_settings.host,
|
||||||
body=text,
|
body=text,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ class BeliefSetterBehaviour(CyclicBehaviour):
|
|||||||
self.agent.logger.debug("Processing message from sender: %s", sender)
|
self.agent.logger.debug("Processing message from sender: %s", sender)
|
||||||
|
|
||||||
match sender:
|
match sender:
|
||||||
case settings.agent_settings.bdi_belief_collector_agent_name:
|
case settings.agent_settings.bdi_belief_collector_name:
|
||||||
self.agent.logger.debug(
|
self.agent.logger.debug(
|
||||||
"Message is from the belief collector agent. Processing as belief message."
|
"Message is from the belief collector agent. Processing as belief message."
|
||||||
)
|
)
|
||||||
@@ -15,14 +15,14 @@ class ReceiveLLMResponseBehaviour(CyclicBehaviour):
|
|||||||
|
|
||||||
sender = msg.sender.node
|
sender = msg.sender.node
|
||||||
match sender:
|
match sender:
|
||||||
case settings.agent_settings.llm_agent_name:
|
case settings.agent_settings.llm_name:
|
||||||
content = msg.body
|
content = msg.body
|
||||||
self.agent.logger.info("Received LLM response: %s", content)
|
self.agent.logger.info("Received LLM response: %s", content)
|
||||||
|
|
||||||
speech_command = SpeechCommand(data=content)
|
speech_command = SpeechCommand(data=content)
|
||||||
|
|
||||||
message = Message(
|
message = Message(
|
||||||
to=settings.agent_settings.act_speech_agent_name
|
to=settings.agent_settings.robot_speech_name
|
||||||
+ "@"
|
+ "@"
|
||||||
+ settings.agent_settings.host,
|
+ settings.agent_settings.host,
|
||||||
sender=self.agent.jid,
|
sender=self.agent.jid,
|
||||||
@@ -7,7 +7,7 @@ from spade.behaviour import CyclicBehaviour
|
|||||||
from control_backend.core.config import settings
|
from control_backend.core.config import settings
|
||||||
|
|
||||||
|
|
||||||
class BelCollectorBehaviour(CyclicBehaviour):
|
class BeliefCollectorBehaviour(CyclicBehaviour):
|
||||||
"""
|
"""
|
||||||
Continuously collects beliefs/emotions from extractor agents:
|
Continuously collects beliefs/emotions from extractor agents:
|
||||||
Then we send a unified belief packet to the BDI agent.
|
Then we send a unified belief packet to the BDI agent.
|
||||||
@@ -83,9 +83,7 @@ class BelCollectorBehaviour(CyclicBehaviour):
|
|||||||
if not beliefs:
|
if not beliefs:
|
||||||
return
|
return
|
||||||
|
|
||||||
to_jid = (
|
to_jid = f"{settings.agent_settings.bdi_core_name}@{settings.agent_settings.host}"
|
||||||
f"{settings.agent_settings.bdi_core_agent_agent_name}@{settings.agent_settings.host}"
|
|
||||||
)
|
|
||||||
|
|
||||||
msg = Message(to=to_jid, sender=self.agent.jid, thread="beliefs")
|
msg = Message(to=to_jid, sender=self.agent.jid, thread="beliefs")
|
||||||
msg.body = json.dumps(beliefs)
|
msg.body = json.dumps(beliefs)
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
from control_backend.agents.base import BaseAgent
|
from control_backend.agents.base import BaseAgent
|
||||||
|
|
||||||
from .behaviours.bel_collector_behaviour import BelCollectorBehaviour
|
from .behaviours.belief_collector_behaviour import BeliefCollectorBehaviour
|
||||||
|
|
||||||
|
|
||||||
class BDIBeliefCollectorAgent(BaseAgent):
|
class BDIBeliefCollectorAgent(BaseAgent):
|
||||||
async def setup(self):
|
async def setup(self):
|
||||||
self.logger.info("BDIBeliefCollectorAgent starting (%s)", self.jid)
|
self.logger.info("BDIBeliefCollectorAgent starting (%s)", self.jid)
|
||||||
# Attach the continuous collector behaviour (listens and forwards to BDI)
|
# Attach the continuous collector behaviour (listens and forwards to BDI)
|
||||||
self.add_behaviour(BelCollectorBehaviour())
|
self.add_behaviour(BeliefCollectorBehaviour())
|
||||||
self.logger.info("BDIBeliefCollectorAgent ready.")
|
self.logger.info("BDIBeliefCollectorAgent ready.")
|
||||||
@@ -7,7 +7,7 @@ from spade.message import Message
|
|||||||
from control_backend.core.config import settings
|
from control_backend.core.config import settings
|
||||||
|
|
||||||
|
|
||||||
class BDITextBeliefBehaviour(CyclicBehaviour):
|
class TextBeliefExtractorBehaviour(CyclicBehaviour):
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# TODO: LLM prompt nog hardcoded
|
# TODO: LLM prompt nog hardcoded
|
||||||
@@ -44,7 +44,7 @@ class BDITextBeliefBehaviour(CyclicBehaviour):
|
|||||||
|
|
||||||
sender = msg.sender.node
|
sender = msg.sender.node
|
||||||
match sender:
|
match sender:
|
||||||
case settings.agent_settings.per_transcription_agent_name:
|
case settings.agent_settings.transcription_name:
|
||||||
self.logger.debug("Received text from transcriber: %s", msg.body)
|
self.logger.debug("Received text from transcriber: %s", msg.body)
|
||||||
await self._process_transcription_demo(msg.body)
|
await self._process_transcription_demo(msg.body)
|
||||||
case _:
|
case _:
|
||||||
@@ -71,7 +71,7 @@ class BDITextBeliefBehaviour(CyclicBehaviour):
|
|||||||
belief_message = Message()
|
belief_message = Message()
|
||||||
|
|
||||||
belief_message.to = (
|
belief_message.to = (
|
||||||
settings.agent_settings.bdi_belief_collector_agent_name
|
settings.agent_settings.bdi_belief_collector_name
|
||||||
+ "@"
|
+ "@"
|
||||||
+ settings.agent_settings.host
|
+ settings.agent_settings.host
|
||||||
)
|
)
|
||||||
@@ -95,9 +95,7 @@ class BDITextBeliefBehaviour(CyclicBehaviour):
|
|||||||
belief_msg = Message()
|
belief_msg = Message()
|
||||||
|
|
||||||
belief_msg.to = (
|
belief_msg.to = (
|
||||||
settings.agent_settings.bdi_belief_collector_agent_name
|
settings.agent_settings.bdi_belief_collector_name + "@" + settings.agent_settings.host
|
||||||
+ "@"
|
|
||||||
+ settings.agent_settings.host
|
|
||||||
)
|
)
|
||||||
belief_msg.body = payload
|
belief_msg.body = payload
|
||||||
belief_msg.thread = "beliefs"
|
belief_msg.thread = "beliefs"
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
from control_backend.agents.base import BaseAgent
|
||||||
|
|
||||||
|
from .behaviours.text_belief_extractor_behaviour import TextBeliefExtractorBehaviour
|
||||||
|
|
||||||
|
|
||||||
|
class TextBeliefExtractorAgent(BaseAgent):
|
||||||
|
async def setup(self):
|
||||||
|
self.add_behaviour(TextBeliefExtractorBehaviour())
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
from .bdi_belief_collector_agent.bel_collector_agent import (
|
|
||||||
BDIBeliefCollectorAgent as BDIBeliefCollectorAgent,
|
|
||||||
)
|
|
||||||
from .bdi_core_agent.bdi_core_agent import BDICoreAgent as BDICoreAgent
|
|
||||||
from .bdi_text_belief_agent.bdi_text_belief_agent import BDITextBeliefAgent as BDITextBeliefAgent
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
from control_backend.agents.base import BaseAgent
|
|
||||||
|
|
||||||
from .behaviours.bdi_text_belief_behaviour import BDITextBeliefBehaviour
|
|
||||||
|
|
||||||
|
|
||||||
class BDITextBeliefAgent(BaseAgent):
|
|
||||||
async def setup(self):
|
|
||||||
self.add_behaviour(BDITextBeliefBehaviour())
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
from .com_ri_agent import ComRIAgent as ComRIAgent
|
|
||||||
1
src/control_backend/agents/communication/__init__.py
Normal file
1
src/control_backend/agents/communication/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from .ri_communication_agent import RICommunicationAgent as RICommunicationAgent
|
||||||
@@ -8,10 +8,10 @@ from zmq.asyncio import Context
|
|||||||
from control_backend.agents import BaseAgent
|
from control_backend.agents import BaseAgent
|
||||||
from control_backend.core.config import settings
|
from control_backend.core.config import settings
|
||||||
|
|
||||||
from ..act_agents.act_speech_agent import ActSpeechAgent
|
from ..actuation.robot_speech_agent import RobotSpeechAgent
|
||||||
|
|
||||||
|
|
||||||
class ComRIAgent(BaseAgent):
|
class RICommunicationAgent(BaseAgent):
|
||||||
req_socket: zmq.Socket
|
req_socket: zmq.Socket
|
||||||
_address = ""
|
_address = ""
|
||||||
_bind = True
|
_bind = True
|
||||||
@@ -204,11 +204,11 @@ class ComRIAgent(BaseAgent):
|
|||||||
else:
|
else:
|
||||||
self._req_socket.bind(addr)
|
self._req_socket.bind(addr)
|
||||||
case "actuation":
|
case "actuation":
|
||||||
ri_commands_agent = ActSpeechAgent(
|
ri_commands_agent = RobotSpeechAgent(
|
||||||
settings.agent_settings.act_speech_agent_name
|
settings.agent_settings.robot_speech_name
|
||||||
+ "@"
|
+ "@"
|
||||||
+ settings.agent_settings.host,
|
+ settings.agent_settings.host,
|
||||||
settings.agent_settings.act_speech_agent_name,
|
settings.agent_settings.robot_speech_name,
|
||||||
address=addr,
|
address=addr,
|
||||||
bind=bind,
|
bind=bind,
|
||||||
)
|
)
|
||||||
@@ -39,7 +39,7 @@ class LLMAgent(BaseAgent):
|
|||||||
sender,
|
sender,
|
||||||
)
|
)
|
||||||
|
|
||||||
if sender == settings.agent_settings.bdi_core_agent_agent_name:
|
if sender == settings.agent_settings.bdi_core_name:
|
||||||
self.agent.logger.debug("Processing message from BDI Core Agent")
|
self.agent.logger.debug("Processing message from BDI Core Agent")
|
||||||
await self._process_bdi_message(msg)
|
await self._process_bdi_message(msg)
|
||||||
else:
|
else:
|
||||||
@@ -63,9 +63,7 @@ class LLMAgent(BaseAgent):
|
|||||||
Sends a response message back to the BDI Core Agent.
|
Sends a response message back to the BDI Core Agent.
|
||||||
"""
|
"""
|
||||||
reply = Message(
|
reply = Message(
|
||||||
to=settings.agent_settings.bdi_core_agent_agent_name
|
to=settings.agent_settings.bdi_core_name + "@" + settings.agent_settings.host,
|
||||||
+ "@"
|
|
||||||
+ settings.agent_settings.host,
|
|
||||||
body=msg,
|
body=msg,
|
||||||
)
|
)
|
||||||
await self.send(reply)
|
await self.send(reply)
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
import json
|
|
||||||
|
|
||||||
from spade.agent import Agent
|
|
||||||
from spade.behaviour import OneShotBehaviour
|
|
||||||
from spade.message import Message
|
|
||||||
|
|
||||||
from control_backend.core.config import settings
|
|
||||||
|
|
||||||
|
|
||||||
class BelTextAgent(Agent):
|
|
||||||
class SendOnceBehaviourBlfText(OneShotBehaviour):
|
|
||||||
async def run(self):
|
|
||||||
to_jid = (
|
|
||||||
settings.agent_settings.bdi_belief_collector_agent_name
|
|
||||||
+ "@"
|
|
||||||
+ settings.agent_settings.host
|
|
||||||
)
|
|
||||||
|
|
||||||
# Send multiple beliefs in one JSON payload
|
|
||||||
payload = {
|
|
||||||
"type": "belief_extraction_text",
|
|
||||||
"beliefs": {
|
|
||||||
"user_said": [
|
|
||||||
"hello test",
|
|
||||||
"Can you help me?",
|
|
||||||
"stop talking to me",
|
|
||||||
"No",
|
|
||||||
"Pepper do a dance",
|
|
||||||
]
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
msg = Message(to=to_jid)
|
|
||||||
msg.body = json.dumps(payload)
|
|
||||||
await self.send(msg)
|
|
||||||
print(f"Beliefs sent to {to_jid}!")
|
|
||||||
|
|
||||||
self.exit_code = "Job Finished!"
|
|
||||||
await self.agent.stop()
|
|
||||||
|
|
||||||
async def setup(self):
|
|
||||||
print("BelTextAgent started")
|
|
||||||
self.b = self.SendOnceBehaviourBlfText()
|
|
||||||
self.add_behaviour(self.b)
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
from .per_transcription_agent.per_transcription_agent import (
|
|
||||||
PerTranscriptionAgent as PerTranscriptionAgent,
|
|
||||||
)
|
|
||||||
from .per_vad_agent import PerVADAgent as PerVADAgent
|
|
||||||
4
src/control_backend/agents/perception/__init__.py
Normal file
4
src/control_backend/agents/perception/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
from .transcription_agent.transcription_agent import (
|
||||||
|
TranscriptionAgent as TranscriptionAgent,
|
||||||
|
)
|
||||||
|
from .vad_agent import VADAgent as VADAgent
|
||||||
@@ -12,24 +12,20 @@ from control_backend.core.config import settings
|
|||||||
from .speech_recognizer import SpeechRecognizer
|
from .speech_recognizer import SpeechRecognizer
|
||||||
|
|
||||||
|
|
||||||
class PerTranscriptionAgent(BaseAgent):
|
class TranscriptionAgent(BaseAgent):
|
||||||
"""
|
"""
|
||||||
An agent which listens to audio fragments with voice, transcribes them, and sends the
|
An agent which listens to audio fragments with voice, transcribes them, and sends the
|
||||||
transcription to other agents.
|
transcription to other agents.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, audio_in_address: str):
|
def __init__(self, audio_in_address: str):
|
||||||
jid = (
|
jid = settings.agent_settings.transcription_name + "@" + settings.agent_settings.host
|
||||||
settings.agent_settings.per_transcription_agent_name
|
super().__init__(jid, settings.agent_settings.transcription_name)
|
||||||
+ "@"
|
|
||||||
+ settings.agent_settings.host
|
|
||||||
)
|
|
||||||
super().__init__(jid, settings.agent_settings.per_transcription_agent_name)
|
|
||||||
|
|
||||||
self.audio_in_address = audio_in_address
|
self.audio_in_address = audio_in_address
|
||||||
self.audio_in_socket: azmq.Socket | None = None
|
self.audio_in_socket: azmq.Socket | None = None
|
||||||
|
|
||||||
class Transcribing(CyclicBehaviour):
|
class TranscribingBehaviour(CyclicBehaviour):
|
||||||
def __init__(self, audio_in_socket: azmq.Socket):
|
def __init__(self, audio_in_socket: azmq.Socket):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.audio_in_socket = audio_in_socket
|
self.audio_in_socket = audio_in_socket
|
||||||
@@ -83,7 +79,7 @@ class PerTranscriptionAgent(BaseAgent):
|
|||||||
|
|
||||||
self._connect_audio_in_socket()
|
self._connect_audio_in_socket()
|
||||||
|
|
||||||
transcribing = self.Transcribing(self.audio_in_socket)
|
transcribing = self.TranscribingBehaviour(self.audio_in_socket)
|
||||||
transcribing.warmup()
|
transcribing.warmup()
|
||||||
self.add_behaviour(transcribing)
|
self.add_behaviour(transcribing)
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ from spade.behaviour import CyclicBehaviour
|
|||||||
from control_backend.agents import BaseAgent
|
from control_backend.agents import BaseAgent
|
||||||
from control_backend.core.config import settings
|
from control_backend.core.config import settings
|
||||||
|
|
||||||
from .per_transcription_agent.per_transcription_agent import PerTranscriptionAgent
|
from .transcription_agent.transcription_agent import TranscriptionAgent
|
||||||
|
|
||||||
|
|
||||||
class SocketPoller[T]:
|
class SocketPoller[T]:
|
||||||
@@ -40,7 +40,7 @@ class SocketPoller[T]:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class Streaming(CyclicBehaviour):
|
class StreamingBehaviour(CyclicBehaviour):
|
||||||
def __init__(self, audio_in_socket: azmq.Socket, audio_out_socket: azmq.Socket):
|
def __init__(self, audio_in_socket: azmq.Socket, audio_out_socket: azmq.Socket):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.audio_in_poller = SocketPoller[bytes](audio_in_socket)
|
self.audio_in_poller = SocketPoller[bytes](audio_in_socket)
|
||||||
@@ -102,15 +102,15 @@ class Streaming(CyclicBehaviour):
|
|||||||
self.audio_buffer = chunk
|
self.audio_buffer = chunk
|
||||||
|
|
||||||
|
|
||||||
class PerVADAgent(BaseAgent):
|
class VADAgent(BaseAgent):
|
||||||
"""
|
"""
|
||||||
An agent which listens to an audio stream, does Voice Activity Detection (VAD), and sends
|
An agent which listens to an audio stream, does Voice Activity Detection (VAD), and sends
|
||||||
fragments with detected speech to other agents over ZeroMQ.
|
fragments with detected speech to other agents over ZeroMQ.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, audio_in_address: str, audio_in_bind: bool):
|
def __init__(self, audio_in_address: str, audio_in_bind: bool):
|
||||||
jid = settings.agent_settings.per_vad_agent_name + "@" + settings.agent_settings.host
|
jid = settings.agent_settings.vad_name + "@" + settings.agent_settings.host
|
||||||
super().__init__(jid, settings.agent_settings.per_vad_agent_name)
|
super().__init__(jid, settings.agent_settings.vad_name)
|
||||||
|
|
||||||
self.audio_in_address = audio_in_address
|
self.audio_in_address = audio_in_address
|
||||||
self.audio_in_bind = audio_in_bind
|
self.audio_in_bind = audio_in_bind
|
||||||
@@ -118,7 +118,7 @@ class PerVADAgent(BaseAgent):
|
|||||||
self.audio_in_socket: azmq.Socket | None = None
|
self.audio_in_socket: azmq.Socket | None = None
|
||||||
self.audio_out_socket: azmq.Socket | None = None
|
self.audio_out_socket: azmq.Socket | None = None
|
||||||
|
|
||||||
self.streaming_behaviour: Streaming | None = None
|
self.streaming_behaviour: StreamingBehaviour | None = None
|
||||||
|
|
||||||
async def stop(self):
|
async def stop(self):
|
||||||
"""
|
"""
|
||||||
@@ -162,11 +162,11 @@ class PerVADAgent(BaseAgent):
|
|||||||
return
|
return
|
||||||
audio_out_address = f"tcp://localhost:{audio_out_port}"
|
audio_out_address = f"tcp://localhost:{audio_out_port}"
|
||||||
|
|
||||||
self.streaming_behaviour = Streaming(self.audio_in_socket, self.audio_out_socket)
|
self.streaming_behaviour = StreamingBehaviour(self.audio_in_socket, self.audio_out_socket)
|
||||||
self.add_behaviour(self.streaming_behaviour)
|
self.add_behaviour(self.streaming_behaviour)
|
||||||
|
|
||||||
# Start agents dependent on the output audio fragments here
|
# Start agents dependent on the output audio fragments here
|
||||||
transcriber = PerTranscriptionAgent(audio_out_address)
|
transcriber = TranscriptionAgent(audio_out_address)
|
||||||
await transcriber.start()
|
await transcriber.start()
|
||||||
|
|
||||||
self.logger.info("Finished setting up %s", self.jid)
|
self.logger.info("Finished setting up %s", self.jid)
|
||||||
@@ -9,16 +9,16 @@ class ZMQSettings(BaseModel):
|
|||||||
|
|
||||||
class AgentSettings(BaseModel):
|
class AgentSettings(BaseModel):
|
||||||
host: str = "localhost"
|
host: str = "localhost"
|
||||||
bdi_core_agent_agent_name: str = "bdi_core_agent"
|
bdi_core_name: str = "bdi_core_agent"
|
||||||
bdi_belief_collector_agent_name: str = "bdi_belief_collector_agent"
|
bdi_belief_collector_name: str = "belief_collector_agent"
|
||||||
bdi_text_belief_agent_name: str = "bdi_text_belief_agent"
|
text_belief_extractor_name: str = "text_belief_extractor_agent"
|
||||||
per_vad_agent_name: str = "per_vad_agent"
|
vad_name: str = "vad_agent"
|
||||||
llm_agent_name: str = "llm_agent"
|
llm_name: str = "llm_agent"
|
||||||
test_agent_name: str = "test_agent"
|
test_name: str = "test_agent"
|
||||||
per_transcription_agent_name: str = "per_transcription_agent"
|
transcription_name: str = "transcription_agent"
|
||||||
|
|
||||||
com_ri_agent_name: str = "com_ri_agent"
|
ri_communication_name: str = "ri_communication_agent"
|
||||||
act_speech_agent_name: str = "act_speech_agent"
|
robot_speech_name: str = "robot_speech_agent"
|
||||||
|
|
||||||
|
|
||||||
class LLMSettings(BaseModel):
|
class LLMSettings(BaseModel):
|
||||||
|
|||||||
@@ -9,21 +9,21 @@ from zmq.asyncio import Context
|
|||||||
|
|
||||||
# Act agents
|
# Act agents
|
||||||
# BDI agents
|
# BDI agents
|
||||||
from control_backend.agents.bdi_agents import (
|
from control_backend.agents.bdi import (
|
||||||
BDIBeliefCollectorAgent,
|
BDIBeliefCollectorAgent,
|
||||||
BDICoreAgent,
|
BDICoreAgent,
|
||||||
BDITextBeliefAgent,
|
TextBeliefExtractorAgent,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Communication agents
|
# Communication agents
|
||||||
from control_backend.agents.com_agents import ComRIAgent
|
from control_backend.agents.communication import RICommunicationAgent
|
||||||
|
|
||||||
# Emotional Agents
|
# Emotional Agents
|
||||||
# LLM Agents
|
# LLM Agents
|
||||||
from control_backend.agents.llm_agents import LLMAgent
|
from control_backend.agents.llm import LLMAgent
|
||||||
|
|
||||||
# Perceive agents
|
# Perceive agents
|
||||||
from control_backend.agents.per_agents import PerVADAgent
|
from control_backend.agents.perception import VADAgent
|
||||||
|
|
||||||
# Other backend imports
|
# Other backend imports
|
||||||
from control_backend.api.v1.router import api_router
|
from control_backend.api.v1.router import api_router
|
||||||
@@ -77,12 +77,12 @@ async def lifespan(app: FastAPI):
|
|||||||
logger.info("Initializing and starting agents.")
|
logger.info("Initializing and starting agents.")
|
||||||
agents_to_start = {
|
agents_to_start = {
|
||||||
"ComRIAgent": (
|
"ComRIAgent": (
|
||||||
ComRIAgent,
|
RICommunicationAgent,
|
||||||
{
|
{
|
||||||
"name": settings.agent_settings.com_ri_agent_name,
|
"name": settings.agent_settings.ri_communication_name,
|
||||||
"jid": f"{settings.agent_settings.com_ri_agent_name}"
|
"jid": f"{settings.agent_settings.ri_communication_name}"
|
||||||
f"@{settings.agent_settings.host}",
|
f"@{settings.agent_settings.host}",
|
||||||
"password": settings.agent_settings.com_ri_agent_name,
|
"password": settings.agent_settings.ri_communication_name,
|
||||||
"address": "tcp://*:5555",
|
"address": "tcp://*:5555",
|
||||||
"bind": True,
|
"bind": True,
|
||||||
},
|
},
|
||||||
@@ -90,56 +90,61 @@ async def lifespan(app: FastAPI):
|
|||||||
"LLMAgent": (
|
"LLMAgent": (
|
||||||
LLMAgent,
|
LLMAgent,
|
||||||
{
|
{
|
||||||
"name": settings.agent_settings.llm_agent_name,
|
"name": settings.agent_settings.llm_name,
|
||||||
"jid": f"{settings.agent_settings.llm_agent_name}@{settings.agent_settings.host}",
|
"jid": f"{settings.agent_settings.llm_name}@{settings.agent_settings.host}",
|
||||||
"password": settings.agent_settings.llm_agent_name,
|
"password": settings.agent_settings.llm_name,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
"BDICoreAgent": (
|
"BDICoreAgent": (
|
||||||
BDICoreAgent,
|
BDICoreAgent,
|
||||||
{
|
{
|
||||||
"name": settings.agent_settings.bdi_core_agent_agent_name,
|
"name": settings.agent_settings.bdi_core_name,
|
||||||
"jid": f"{settings.agent_settings.bdi_core_agent_agent_name}@"
|
"jid": f"{settings.agent_settings.bdi_core_name}@{settings.agent_settings.host}",
|
||||||
f"{settings.agent_settings.host}",
|
"password": settings.agent_settings.bdi_core_name,
|
||||||
"password": settings.agent_settings.bdi_core_agent_agent_name,
|
"asl": "src/control_backend/agents/bdi/bdi_core_agent/rules.asl",
|
||||||
"asl": "src/control_backend/agents/bdi_agents/bdi_core_agent/rules.asl",
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
"BDIBeliefCollectorAgent": (
|
"BDIBeliefCollectorAgent": (
|
||||||
BDIBeliefCollectorAgent,
|
BDIBeliefCollectorAgent,
|
||||||
{
|
{
|
||||||
"name": settings.agent_settings.bdi_belief_collector_agent_name,
|
"name": settings.agent_settings.bdi_belief_collector_name,
|
||||||
"jid": f"{settings.agent_settings.bdi_belief_collector_agent_name}@"
|
"jid": f"{settings.agent_settings.bdi_belief_collector_name}@"
|
||||||
f"{settings.agent_settings.host}",
|
f"{settings.agent_settings.host}",
|
||||||
"password": settings.agent_settings.bdi_belief_collector_agent_name,
|
"password": settings.agent_settings.bdi_belief_collector_name,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
"BDITextBeliefAgent": (
|
"BDITextBeliefAgent": (
|
||||||
BDITextBeliefAgent,
|
TextBeliefExtractorAgent,
|
||||||
{
|
{
|
||||||
"name": settings.agent_settings.bdi_text_belief_agent_name,
|
"name": settings.agent_settings.text_belief_extractor_name,
|
||||||
"jid": f"{settings.agent_settings.bdi_text_belief_agent_name}@"
|
"jid": f"{settings.agent_settings.text_belief_extractor_name}@"
|
||||||
f"{settings.agent_settings.host}",
|
f"{settings.agent_settings.host}",
|
||||||
"password": settings.agent_settings.bdi_text_belief_agent_name,
|
"password": settings.agent_settings.text_belief_extractor_name,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
"PerVADAgent": (
|
"PerVADAgent": (
|
||||||
PerVADAgent,
|
VADAgent,
|
||||||
{"audio_in_address": "tcp://localhost:5558", "audio_in_bind": False},
|
{"audio_in_address": "tcp://localhost:5558", "audio_in_bind": False},
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vad_agent = None
|
||||||
|
|
||||||
for name, (agent_class, kwargs) in agents_to_start.items():
|
for name, (agent_class, kwargs) in agents_to_start.items():
|
||||||
try:
|
try:
|
||||||
logger.debug("Starting agent: %s", name)
|
logger.debug("Starting agent: %s", name)
|
||||||
agent_instance = agent_class(**{k: v for k, v in kwargs.items() if k != "name"})
|
agent_instance = agent_class(**{k: v for k, v in kwargs.items() if k != "name"})
|
||||||
await agent_instance.start()
|
await agent_instance.start()
|
||||||
|
if isinstance(agent_instance, VADAgent):
|
||||||
|
vad_agent = agent_instance
|
||||||
logger.info("Agent '%s' started successfully.", name)
|
logger.info("Agent '%s' started successfully.", name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Failed to start agent '%s': %s", name, e, exc_info=True)
|
logger.error("Failed to start agent '%s': %s", name, e, exc_info=True)
|
||||||
# Consider if the application should continue if an agent fails to start.
|
# Consider if the application should continue if an agent fails to start.
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
await vad_agent.streaming_behaviour.reset()
|
||||||
|
|
||||||
logger.info("Application startup complete.")
|
logger.info("Application startup complete.")
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
|||||||
import pytest
|
import pytest
|
||||||
import zmq
|
import zmq
|
||||||
|
|
||||||
from control_backend.agents.act_agents.act_speech_agent import ActSpeechAgent
|
from control_backend.agents.actuation.robot_speech_agent import RobotSpeechAgent
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def zmq_context(mocker):
|
def zmq_context(mocker):
|
||||||
mock_context = mocker.patch(
|
mock_context = mocker.patch(
|
||||||
"control_backend.agents.act_agents.act_speech_agent.zmq.Context.instance"
|
"control_backend.agents.actuation.robot_speech_agent.zmq.Context.instance"
|
||||||
)
|
)
|
||||||
mock_context.return_value = MagicMock()
|
mock_context.return_value = MagicMock()
|
||||||
return mock_context
|
return mock_context
|
||||||
@@ -21,8 +21,8 @@ async def test_setup_bind(zmq_context, mocker):
|
|||||||
"""Test setup with bind=True"""
|
"""Test setup with bind=True"""
|
||||||
fake_socket = zmq_context.return_value.socket.return_value
|
fake_socket = zmq_context.return_value.socket.return_value
|
||||||
|
|
||||||
agent = ActSpeechAgent("test@server", "password", address="tcp://localhost:5555", bind=True)
|
agent = RobotSpeechAgent("test@server", "password", address="tcp://localhost:5555", bind=True)
|
||||||
settings = mocker.patch("control_backend.agents.act_agents.act_speech_agent.settings")
|
settings = mocker.patch("control_backend.agents.actuation.robot_speech_agent.settings")
|
||||||
settings.zmq_settings.internal_sub_address = "tcp://internal:1234"
|
settings.zmq_settings.internal_sub_address = "tcp://internal:1234"
|
||||||
|
|
||||||
await agent.setup()
|
await agent.setup()
|
||||||
@@ -40,8 +40,8 @@ async def test_setup_connect(zmq_context, mocker):
|
|||||||
"""Test setup with bind=False"""
|
"""Test setup with bind=False"""
|
||||||
fake_socket = zmq_context.return_value.socket.return_value
|
fake_socket = zmq_context.return_value.socket.return_value
|
||||||
|
|
||||||
agent = ActSpeechAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
agent = RobotSpeechAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
||||||
settings = mocker.patch("control_backend.agents.act_agents.act_speech_agent.settings")
|
settings = mocker.patch("control_backend.agents.actuation.robot_speech_agent.settings")
|
||||||
settings.zmq_settings.internal_sub_address = "tcp://internal:1234"
|
settings.zmq_settings.internal_sub_address = "tcp://internal:1234"
|
||||||
|
|
||||||
await agent.setup()
|
await agent.setup()
|
||||||
@@ -59,7 +59,7 @@ async def test_send_commands_behaviour_valid_message():
|
|||||||
)
|
)
|
||||||
fake_socket.send_json = AsyncMock()
|
fake_socket.send_json = AsyncMock()
|
||||||
|
|
||||||
agent = ActSpeechAgent("test@server", "password")
|
agent = RobotSpeechAgent("test@server", "password")
|
||||||
agent.subsocket = fake_socket
|
agent.subsocket = fake_socket
|
||||||
agent.pubsocket = fake_socket
|
agent.pubsocket = fake_socket
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ async def test_send_commands_behaviour_valid_message():
|
|||||||
behaviour.agent = agent
|
behaviour.agent = agent
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"control_backend.agents.act_agents.act_speech_agent.SpeechCommand"
|
"control_backend.agents.actuation.robot_speech_agent.SpeechCommand"
|
||||||
) as MockSpeechCommand:
|
) as MockSpeechCommand:
|
||||||
mock_message = MagicMock()
|
mock_message = MagicMock()
|
||||||
MockSpeechCommand.model_validate.return_value = mock_message
|
MockSpeechCommand.model_validate.return_value = mock_message
|
||||||
@@ -85,7 +85,7 @@ async def test_send_commands_behaviour_invalid_message():
|
|||||||
fake_socket.recv_multipart = AsyncMock(return_value=(b"command", b"{invalid_json}"))
|
fake_socket.recv_multipart = AsyncMock(return_value=(b"command", b"{invalid_json}"))
|
||||||
fake_socket.send_json = AsyncMock()
|
fake_socket.send_json = AsyncMock()
|
||||||
|
|
||||||
agent = ActSpeechAgent("test@server", "password")
|
agent = RobotSpeechAgent("test@server", "password")
|
||||||
agent.subsocket = fake_socket
|
agent.subsocket = fake_socket
|
||||||
agent.pubsocket = fake_socket
|
agent.pubsocket = fake_socket
|
||||||
|
|
||||||
@@ -3,11 +3,11 @@ from unittest.mock import ANY, AsyncMock, MagicMock, patch
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from control_backend.agents.com_agents.com_ri_agent import ComRIAgent
|
from control_backend.agents.communication.ri_communication_agent import RICommunicationAgent
|
||||||
|
|
||||||
|
|
||||||
def act_agent_path():
|
def speech_agent_path():
|
||||||
return "control_backend.agents.com_agents.com_ri_agent.ActSpeechAgent"
|
return "control_backend.agents.communication.ri_communication_agent.RobotSpeechAgent"
|
||||||
|
|
||||||
|
|
||||||
def fake_json_correct_negototiate_1():
|
def fake_json_correct_negototiate_1():
|
||||||
@@ -91,7 +91,7 @@ def fake_json_invalid_id_negototiate():
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def zmq_context(mocker):
|
def zmq_context(mocker):
|
||||||
mock_context = mocker.patch(
|
mock_context = mocker.patch(
|
||||||
"control_backend.agents.com_agents.com_ri_agent.zmq.Context.instance"
|
"control_backend.agents.communication.ri_communication_agent.zmq.Context.instance"
|
||||||
)
|
)
|
||||||
mock_context.return_value = MagicMock()
|
mock_context.return_value = MagicMock()
|
||||||
return mock_context
|
return mock_context
|
||||||
@@ -109,12 +109,17 @@ async def test_setup_creates_socket_and_negotiate_1(zmq_context):
|
|||||||
fake_socket.send_multipart = AsyncMock()
|
fake_socket.send_multipart = AsyncMock()
|
||||||
|
|
||||||
# Mock ActSpeechAgent agent startup
|
# Mock ActSpeechAgent agent startup
|
||||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
|
||||||
fake_agent_instance = MockCommandAgent.return_value
|
fake_agent_instance = MockCommandAgent.return_value
|
||||||
fake_agent_instance.start = AsyncMock()
|
fake_agent_instance.start = AsyncMock()
|
||||||
|
|
||||||
# --- Act ---
|
# --- Act ---
|
||||||
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
agent = RICommunicationAgent(
|
||||||
|
"test@server",
|
||||||
|
"password",
|
||||||
|
address="tcp://localhost:5555",
|
||||||
|
bind=False,
|
||||||
|
)
|
||||||
await agent.setup()
|
await agent.setup()
|
||||||
|
|
||||||
# --- Assert ---
|
# --- Assert ---
|
||||||
@@ -144,12 +149,17 @@ async def test_setup_creates_socket_and_negotiate_2(zmq_context):
|
|||||||
fake_socket.send_multipart = AsyncMock()
|
fake_socket.send_multipart = AsyncMock()
|
||||||
|
|
||||||
# Mock ActSpeechAgent agent startup
|
# Mock ActSpeechAgent agent startup
|
||||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
|
||||||
fake_agent_instance = MockCommandAgent.return_value
|
fake_agent_instance = MockCommandAgent.return_value
|
||||||
fake_agent_instance.start = AsyncMock()
|
fake_agent_instance.start = AsyncMock()
|
||||||
|
|
||||||
# --- Act ---
|
# --- Act ---
|
||||||
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
agent = RICommunicationAgent(
|
||||||
|
"test@server",
|
||||||
|
"password",
|
||||||
|
address="tcp://localhost:5555",
|
||||||
|
bind=False,
|
||||||
|
)
|
||||||
await agent.setup()
|
await agent.setup()
|
||||||
|
|
||||||
# --- Assert ---
|
# --- Assert ---
|
||||||
@@ -182,12 +192,17 @@ async def test_setup_creates_socket_and_negotiate_3(zmq_context):
|
|||||||
|
|
||||||
# We are sending wrong negotiation info to the communication agent,
|
# We are sending wrong negotiation info to the communication agent,
|
||||||
# so we should retry and expect a better response, within a limited time.
|
# so we should retry and expect a better response, within a limited time.
|
||||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
|
||||||
fake_agent_instance = MockCommandAgent.return_value
|
fake_agent_instance = MockCommandAgent.return_value
|
||||||
fake_agent_instance.start = AsyncMock()
|
fake_agent_instance.start = AsyncMock()
|
||||||
# --- Act ---
|
# --- Act ---
|
||||||
|
|
||||||
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
agent = RICommunicationAgent(
|
||||||
|
"test@server",
|
||||||
|
"password",
|
||||||
|
address="tcp://localhost:5555",
|
||||||
|
bind=False,
|
||||||
|
)
|
||||||
await agent.setup(max_retries=1)
|
await agent.setup(max_retries=1)
|
||||||
|
|
||||||
# --- Assert ---
|
# --- Assert ---
|
||||||
@@ -213,11 +228,16 @@ async def test_setup_creates_socket_and_negotiate_4(zmq_context):
|
|||||||
fake_socket.send_multipart = AsyncMock()
|
fake_socket.send_multipart = AsyncMock()
|
||||||
|
|
||||||
# Mock ActSpeechAgent agent startup
|
# Mock ActSpeechAgent agent startup
|
||||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
|
||||||
fake_agent_instance = MockCommandAgent.return_value
|
fake_agent_instance = MockCommandAgent.return_value
|
||||||
fake_agent_instance.start = AsyncMock()
|
fake_agent_instance.start = AsyncMock()
|
||||||
# --- Act ---
|
# --- Act ---
|
||||||
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=True)
|
agent = RICommunicationAgent(
|
||||||
|
"test@server",
|
||||||
|
"password",
|
||||||
|
address="tcp://localhost:5555",
|
||||||
|
bind=True,
|
||||||
|
)
|
||||||
await agent.setup()
|
await agent.setup()
|
||||||
|
|
||||||
# --- Assert ---
|
# --- Assert ---
|
||||||
@@ -247,11 +267,16 @@ async def test_setup_creates_socket_and_negotiate_5(zmq_context):
|
|||||||
fake_socket.send_multipart = AsyncMock()
|
fake_socket.send_multipart = AsyncMock()
|
||||||
|
|
||||||
# Mock ActSpeechAgent agent startup
|
# Mock ActSpeechAgent agent startup
|
||||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
|
||||||
fake_agent_instance = MockCommandAgent.return_value
|
fake_agent_instance = MockCommandAgent.return_value
|
||||||
fake_agent_instance.start = AsyncMock()
|
fake_agent_instance.start = AsyncMock()
|
||||||
# --- Act ---
|
# --- Act ---
|
||||||
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
agent = RICommunicationAgent(
|
||||||
|
"test@server",
|
||||||
|
"password",
|
||||||
|
address="tcp://localhost:5555",
|
||||||
|
bind=False,
|
||||||
|
)
|
||||||
await agent.setup()
|
await agent.setup()
|
||||||
|
|
||||||
# --- Assert ---
|
# --- Assert ---
|
||||||
@@ -281,11 +306,16 @@ async def test_setup_creates_socket_and_negotiate_6(zmq_context):
|
|||||||
fake_socket.send_multipart = AsyncMock()
|
fake_socket.send_multipart = AsyncMock()
|
||||||
|
|
||||||
# Mock ActSpeechAgent agent startup
|
# Mock ActSpeechAgent agent startup
|
||||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
|
||||||
fake_agent_instance = MockCommandAgent.return_value
|
fake_agent_instance = MockCommandAgent.return_value
|
||||||
fake_agent_instance.start = AsyncMock()
|
fake_agent_instance.start = AsyncMock()
|
||||||
# --- Act ---
|
# --- Act ---
|
||||||
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
agent = RICommunicationAgent(
|
||||||
|
"test@server",
|
||||||
|
"password",
|
||||||
|
address="tcp://localhost:5555",
|
||||||
|
bind=False,
|
||||||
|
)
|
||||||
await agent.setup()
|
await agent.setup()
|
||||||
|
|
||||||
# --- Assert ---
|
# --- Assert ---
|
||||||
@@ -318,13 +348,18 @@ async def test_setup_creates_socket_and_negotiate_7(zmq_context):
|
|||||||
|
|
||||||
# We are sending wrong negotiation info to the communication agent,
|
# We are sending wrong negotiation info to the communication agent,
|
||||||
# so we should retry and expect a better response, within a limited time.
|
# so we should retry and expect a better response, within a limited time.
|
||||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
|
||||||
fake_agent_instance = MockCommandAgent.return_value
|
fake_agent_instance = MockCommandAgent.return_value
|
||||||
fake_agent_instance.start = AsyncMock()
|
fake_agent_instance.start = AsyncMock()
|
||||||
|
|
||||||
# --- Act ---
|
# --- Act ---
|
||||||
|
|
||||||
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
agent = RICommunicationAgent(
|
||||||
|
"test@server",
|
||||||
|
"password",
|
||||||
|
address="tcp://localhost:5555",
|
||||||
|
bind=False,
|
||||||
|
)
|
||||||
await agent.setup(max_retries=1)
|
await agent.setup(max_retries=1)
|
||||||
|
|
||||||
# --- Assert ---
|
# --- Assert ---
|
||||||
@@ -346,13 +381,18 @@ async def test_setup_creates_socket_and_negotiate_timeout(zmq_context):
|
|||||||
fake_socket.recv_json = AsyncMock(side_effect=asyncio.TimeoutError)
|
fake_socket.recv_json = AsyncMock(side_effect=asyncio.TimeoutError)
|
||||||
fake_socket.send_multipart = AsyncMock()
|
fake_socket.send_multipart = AsyncMock()
|
||||||
|
|
||||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
|
||||||
fake_agent_instance = MockCommandAgent.return_value
|
fake_agent_instance = MockCommandAgent.return_value
|
||||||
fake_agent_instance.start = AsyncMock()
|
fake_agent_instance.start = AsyncMock()
|
||||||
|
|
||||||
# --- Act ---
|
# --- Act ---
|
||||||
|
|
||||||
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
agent = RICommunicationAgent(
|
||||||
|
"test@server",
|
||||||
|
"password",
|
||||||
|
address="tcp://localhost:5555",
|
||||||
|
bind=False,
|
||||||
|
)
|
||||||
await agent.setup(max_retries=1)
|
await agent.setup(max_retries=1)
|
||||||
|
|
||||||
# --- Assert ---
|
# --- Assert ---
|
||||||
@@ -372,7 +412,7 @@ async def test_listen_behaviour_ping_correct():
|
|||||||
fake_socket.recv_json = AsyncMock(return_value={"endpoint": "ping", "data": {}})
|
fake_socket.recv_json = AsyncMock(return_value={"endpoint": "ping", "data": {}})
|
||||||
fake_socket.send_multipart = AsyncMock()
|
fake_socket.send_multipart = AsyncMock()
|
||||||
|
|
||||||
agent = ComRIAgent("test@server", "password")
|
agent = RICommunicationAgent("test@server", "password")
|
||||||
agent._req_socket = fake_socket
|
agent._req_socket = fake_socket
|
||||||
agent.connected = True
|
agent.connected = True
|
||||||
|
|
||||||
@@ -405,7 +445,7 @@ async def test_listen_behaviour_ping_wrong_endpoint():
|
|||||||
)
|
)
|
||||||
fake_pub_socket = AsyncMock()
|
fake_pub_socket = AsyncMock()
|
||||||
|
|
||||||
agent = ComRIAgent("test@server", "password", fake_pub_socket)
|
agent = RICommunicationAgent("test@server", "password", fake_pub_socket)
|
||||||
agent._req_socket = fake_socket
|
agent._req_socket = fake_socket
|
||||||
agent.connected = True
|
agent.connected = True
|
||||||
|
|
||||||
@@ -428,7 +468,7 @@ async def test_listen_behaviour_timeout(zmq_context):
|
|||||||
fake_socket.recv_json = AsyncMock(side_effect=asyncio.TimeoutError)
|
fake_socket.recv_json = AsyncMock(side_effect=asyncio.TimeoutError)
|
||||||
fake_socket.send_multipart = AsyncMock()
|
fake_socket.send_multipart = AsyncMock()
|
||||||
|
|
||||||
agent = ComRIAgent("test@server", "password")
|
agent = RICommunicationAgent("test@server", "password")
|
||||||
agent._req_socket = fake_socket
|
agent._req_socket = fake_socket
|
||||||
agent.connected = True
|
agent.connected = True
|
||||||
|
|
||||||
@@ -456,7 +496,7 @@ async def test_listen_behaviour_ping_no_endpoint():
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
agent = ComRIAgent("test@server", "password")
|
agent = RICommunicationAgent("test@server", "password")
|
||||||
agent._req_socket = fake_socket
|
agent._req_socket = fake_socket
|
||||||
agent.connected = True
|
agent.connected = True
|
||||||
|
|
||||||
@@ -477,7 +517,12 @@ async def test_setup_unexpected_exception(zmq_context):
|
|||||||
fake_socket.recv_json = AsyncMock(side_effect=Exception("boom!"))
|
fake_socket.recv_json = AsyncMock(side_effect=Exception("boom!"))
|
||||||
fake_socket.send_multipart = AsyncMock()
|
fake_socket.send_multipart = AsyncMock()
|
||||||
|
|
||||||
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
agent = RICommunicationAgent(
|
||||||
|
"test@server",
|
||||||
|
"password",
|
||||||
|
address="tcp://localhost:5555",
|
||||||
|
bind=False,
|
||||||
|
)
|
||||||
|
|
||||||
await agent.setup(max_retries=1)
|
await agent.setup(max_retries=1)
|
||||||
|
|
||||||
@@ -500,11 +545,16 @@ async def test_setup_unpacking_exception(zmq_context):
|
|||||||
fake_socket.recv_json = AsyncMock(return_value=malformed_data)
|
fake_socket.recv_json = AsyncMock(return_value=malformed_data)
|
||||||
|
|
||||||
# Patch ActSpeechAgent so it won't actually start
|
# Patch ActSpeechAgent so it won't actually start
|
||||||
with patch(act_agent_path(), autospec=True) as MockCommandAgent:
|
with patch(speech_agent_path(), autospec=True) as MockCommandAgent:
|
||||||
fake_agent_instance = MockCommandAgent.return_value
|
fake_agent_instance = MockCommandAgent.return_value
|
||||||
fake_agent_instance.start = AsyncMock()
|
fake_agent_instance.start = AsyncMock()
|
||||||
|
|
||||||
agent = ComRIAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
|
agent = RICommunicationAgent(
|
||||||
|
"test@server",
|
||||||
|
"password",
|
||||||
|
address="tcp://localhost:5555",
|
||||||
|
bind=False,
|
||||||
|
)
|
||||||
|
|
||||||
# --- Act & Assert ---
|
# --- Act & Assert ---
|
||||||
|
|
||||||
@@ -5,27 +5,25 @@ import pytest
|
|||||||
import zmq
|
import zmq
|
||||||
from spade.agent import Agent
|
from spade.agent import Agent
|
||||||
|
|
||||||
from control_backend.agents.per_agents.per_vad_agent import PerVADAgent
|
from control_backend.agents.perception.vad_agent import VADAgent
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def zmq_context(mocker):
|
def zmq_context(mocker):
|
||||||
mock_context = mocker.patch(
|
mock_context = mocker.patch("control_backend.agents.perception.vad_agent.azmq.Context.instance")
|
||||||
"control_backend.agents.per_agents.per_vad_agent.azmq.Context.instance"
|
|
||||||
)
|
|
||||||
mock_context.return_value = MagicMock()
|
mock_context.return_value = MagicMock()
|
||||||
return mock_context
|
return mock_context
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def streaming(mocker):
|
def streaming(mocker):
|
||||||
return mocker.patch("control_backend.agents.per_agents.per_vad_agent.Streaming")
|
return mocker.patch("control_backend.agents.perception.vad_agent.StreamingBehaviour")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def per_transcription_agent(mocker):
|
def per_transcription_agent(mocker):
|
||||||
return mocker.patch(
|
return mocker.patch(
|
||||||
"control_backend.agents.per_agents.per_vad_agent.PerTranscriptionAgent", autospec=True
|
"control_backend.agents.perception.vad_agent.TranscriptionAgent", autospec=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -33,9 +31,9 @@ def per_transcription_agent(mocker):
|
|||||||
async def test_normal_setup(streaming, per_transcription_agent):
|
async def test_normal_setup(streaming, per_transcription_agent):
|
||||||
"""
|
"""
|
||||||
Test that during normal setup, the VAD agent creates a Streaming behavior and creates audio
|
Test that during normal setup, the VAD agent creates a Streaming behavior and creates audio
|
||||||
sockets, and starts the PerTranscriptionAgent without loading real models.
|
sockets, and starts the TranscriptionAgent without loading real models.
|
||||||
"""
|
"""
|
||||||
per_vad_agent = PerVADAgent("tcp://localhost:12345", False)
|
per_vad_agent = VADAgent("tcp://localhost:12345", False)
|
||||||
per_vad_agent.add_behaviour = MagicMock()
|
per_vad_agent.add_behaviour = MagicMock()
|
||||||
|
|
||||||
await per_vad_agent.setup()
|
await per_vad_agent.setup()
|
||||||
@@ -54,7 +52,7 @@ def test_in_socket_creation(zmq_context, do_bind: bool):
|
|||||||
Test that the VAD agent creates an audio input socket, differentiating between binding and
|
Test that the VAD agent creates an audio input socket, differentiating between binding and
|
||||||
connecting.
|
connecting.
|
||||||
"""
|
"""
|
||||||
per_vad_agent = PerVADAgent(f"tcp://{'*' if do_bind else 'localhost'}:12345", do_bind)
|
per_vad_agent = VADAgent(f"tcp://{'*' if do_bind else 'localhost'}:12345", do_bind)
|
||||||
|
|
||||||
per_vad_agent._connect_audio_in_socket()
|
per_vad_agent._connect_audio_in_socket()
|
||||||
|
|
||||||
@@ -78,7 +76,7 @@ def test_out_socket_creation(zmq_context):
|
|||||||
"""
|
"""
|
||||||
Test that the VAD agent creates an audio output socket correctly.
|
Test that the VAD agent creates an audio output socket correctly.
|
||||||
"""
|
"""
|
||||||
per_vad_agent = PerVADAgent("tcp://localhost:12345", False)
|
per_vad_agent = VADAgent("tcp://localhost:12345", False)
|
||||||
|
|
||||||
per_vad_agent._connect_audio_out_socket()
|
per_vad_agent._connect_audio_out_socket()
|
||||||
|
|
||||||
@@ -97,7 +95,7 @@ async def test_out_socket_creation_failure(zmq_context):
|
|||||||
zmq_context.return_value.socket.return_value.bind_to_random_port.side_effect = (
|
zmq_context.return_value.socket.return_value.bind_to_random_port.side_effect = (
|
||||||
zmq.ZMQBindError
|
zmq.ZMQBindError
|
||||||
)
|
)
|
||||||
per_vad_agent = PerVADAgent("tcp://localhost:12345", False)
|
per_vad_agent = VADAgent("tcp://localhost:12345", False)
|
||||||
|
|
||||||
await per_vad_agent.setup()
|
await per_vad_agent.setup()
|
||||||
|
|
||||||
@@ -110,7 +108,7 @@ async def test_stop(zmq_context, per_transcription_agent):
|
|||||||
"""
|
"""
|
||||||
Test that when the VAD agent is stopped, the sockets are closed correctly.
|
Test that when the VAD agent is stopped, the sockets are closed correctly.
|
||||||
"""
|
"""
|
||||||
per_vad_agent = PerVADAgent("tcp://localhost:12345", False)
|
per_vad_agent = VADAgent("tcp://localhost:12345", False)
|
||||||
zmq_context.return_value.socket.return_value.bind_to_random_port.return_value = random.randint(
|
zmq_context.return_value.socket.return_value.bind_to_random_port.return_value = random.randint(
|
||||||
1000,
|
1000,
|
||||||
10000,
|
10000,
|
||||||
@@ -5,7 +5,7 @@ import pytest
|
|||||||
import soundfile as sf
|
import soundfile as sf
|
||||||
import zmq
|
import zmq
|
||||||
|
|
||||||
from control_backend.agents.per_agents.per_vad_agent import Streaming
|
from control_backend.agents.perception.vad_agent import StreamingBehaviour
|
||||||
|
|
||||||
|
|
||||||
def get_audio_chunks() -> list[bytes]:
|
def get_audio_chunks() -> list[bytes]:
|
||||||
@@ -42,14 +42,12 @@ async def test_real_audio(mocker):
|
|||||||
audio_in_socket = AsyncMock()
|
audio_in_socket = AsyncMock()
|
||||||
audio_in_socket.recv.side_effect = audio_chunks
|
audio_in_socket.recv.side_effect = audio_chunks
|
||||||
|
|
||||||
mock_poller: MagicMock = mocker.patch(
|
mock_poller: MagicMock = mocker.patch("control_backend.agents.perception.vad_agent.zmq.Poller")
|
||||||
"control_backend.agents.per_agents.per_vad_agent.zmq.Poller"
|
|
||||||
)
|
|
||||||
mock_poller.return_value.poll.return_value = [(audio_in_socket, zmq.POLLIN)]
|
mock_poller.return_value.poll.return_value = [(audio_in_socket, zmq.POLLIN)]
|
||||||
|
|
||||||
audio_out_socket = AsyncMock()
|
audio_out_socket = AsyncMock()
|
||||||
|
|
||||||
vad_streamer = Streaming(audio_in_socket, audio_out_socket)
|
vad_streamer = StreamingBehaviour(audio_in_socket, audio_out_socket)
|
||||||
vad_streamer._ready = True
|
vad_streamer._ready = True
|
||||||
vad_streamer.agent = MagicMock()
|
vad_streamer.agent = MagicMock()
|
||||||
for _ in audio_chunks:
|
for _ in audio_chunks:
|
||||||
@@ -4,12 +4,12 @@ from unittest.mock import AsyncMock, MagicMock, call
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from control_backend.agents.bdi_agents.bdi_core_agent.behaviours.belief_setter_behaviour import (
|
from control_backend.agents.bdi.bdi_core_agent.behaviours.belief_setter_behaviour import (
|
||||||
BeliefSetterBehaviour,
|
BeliefSetterBehaviour,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Define a constant for the collector agent name to use in tests
|
# Define a constant for the collector agent name to use in tests
|
||||||
COLLECTOR_AGENT_NAME = "bdi_belief_collector_agent"
|
COLLECTOR_AGENT_NAME = "belief_collector_agent"
|
||||||
COLLECTOR_AGENT_JID = f"{COLLECTOR_AGENT_NAME}@test"
|
COLLECTOR_AGENT_JID = f"{COLLECTOR_AGENT_NAME}@test"
|
||||||
|
|
||||||
|
|
||||||
@@ -27,8 +27,8 @@ def belief_setter_behaviour(mock_agent, mocker):
|
|||||||
"""Fixture to create an instance of BeliefSetterBehaviour with a mocked agent."""
|
"""Fixture to create an instance of BeliefSetterBehaviour with a mocked agent."""
|
||||||
# Patch the settings to use a predictable agent name
|
# Patch the settings to use a predictable agent name
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
"control_backend.agents.bdi_agents.bdi_core_agent."
|
"control_backend.agents.bdi.bdi_core_agent."
|
||||||
"behaviours.belief_setter_behaviour.settings.agent_settings.bdi_belief_collector_agent_name",
|
"behaviours.belief_setter_behaviour.settings.agent_settings.bdi_belief_collector_name",
|
||||||
COLLECTOR_AGENT_NAME,
|
COLLECTOR_AGENT_NAME,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -3,8 +3,8 @@ from unittest.mock import AsyncMock, MagicMock
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from control_backend.agents.bdi_agents.bdi_belief_collector_agent.behaviours.bel_collector_behaviour import ( # noqa: E501
|
from control_backend.agents.bdi.belief_collector_agent.behaviours.belief_collector_behaviour import ( # noqa: E501
|
||||||
BelCollectorBehaviour,
|
BeliefCollectorBehaviour,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ def create_mock_message(sender_node: str, body: str) -> MagicMock:
|
|||||||
def mock_agent(mocker):
|
def mock_agent(mocker):
|
||||||
"""Fixture to create a mock Agent."""
|
"""Fixture to create a mock Agent."""
|
||||||
agent = MagicMock()
|
agent = MagicMock()
|
||||||
agent.jid = "bdi_belief_collector_agent@test"
|
agent.jid = "belief_collector_agent@test"
|
||||||
return agent
|
return agent
|
||||||
|
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ def bel_collector_behaviouror(mock_agent, mocker):
|
|||||||
# Patch asyncio.sleep to prevent tests from actually waiting
|
# Patch asyncio.sleep to prevent tests from actually waiting
|
||||||
mocker.patch("asyncio.sleep", return_value=None)
|
mocker.patch("asyncio.sleep", return_value=None)
|
||||||
|
|
||||||
collector = BelCollectorBehaviour()
|
collector = BeliefCollectorBehaviour()
|
||||||
collector.agent = mock_agent
|
collector.agent = mock_agent
|
||||||
# Mock the receive method, we will control its return value in each test
|
# Mock the receive method, we will control its return value in each test
|
||||||
collector.receive = AsyncMock()
|
collector.receive = AsyncMock()
|
||||||
@@ -4,8 +4,8 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
|||||||
import pytest
|
import pytest
|
||||||
from spade.message import Message
|
from spade.message import Message
|
||||||
|
|
||||||
from control_backend.agents.bdi_agents.bdi_text_belief_agent.behaviours.bdi_text_belief_behaviour import ( # noqa: E501, We can't shorten this import.
|
from control_backend.agents.bdi.text_belief_extractor_agent.behaviours.text_belief_extractor_behaviour import ( # noqa: E501, We can't shorten this import.
|
||||||
BDITextBeliefBehaviour,
|
TextBeliefExtractorBehaviour,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -17,15 +17,16 @@ def mock_settings():
|
|||||||
"""
|
"""
|
||||||
# Create a mock object that mimics the nested structure
|
# Create a mock object that mimics the nested structure
|
||||||
settings_mock = MagicMock()
|
settings_mock = MagicMock()
|
||||||
settings_mock.agent_settings.per_transcription_agent_name = "transcriber"
|
settings_mock.agent_settings.transcription_name = "transcriber"
|
||||||
settings_mock.agent_settings.bdi_belief_collector_agent_name = "collector"
|
settings_mock.agent_settings.bdi_belief_collector_name = "collector"
|
||||||
settings_mock.agent_settings.host = "fake.host"
|
settings_mock.agent_settings.host = "fake.host"
|
||||||
|
|
||||||
# Use patch to replace the settings object during the test
|
# Use patch to replace the settings object during the test
|
||||||
# Adjust 'control_backend.behaviours.belief_from_text.settings' to where
|
# Adjust 'control_backend.behaviours.belief_from_text.settings' to where
|
||||||
# your behaviour file imports it from.
|
# your behaviour file imports it from.
|
||||||
with patch(
|
with patch(
|
||||||
"control_backend.agents.bdi_agents.bdi_text_belief_agent.behaviours.bdi_text_belief_behaviour.settings",
|
"control_backend.agents.bdi.text_belief_extractor_agent.behaviours"
|
||||||
|
".text_belief_extractor_behaviour.settings",
|
||||||
settings_mock,
|
settings_mock,
|
||||||
):
|
):
|
||||||
yield settings_mock
|
yield settings_mock
|
||||||
@@ -37,7 +38,7 @@ def behavior(mock_settings):
|
|||||||
Creates an instance of the BDITextBeliefBehaviour behaviour and mocks its
|
Creates an instance of the BDITextBeliefBehaviour behaviour and mocks its
|
||||||
agent, logger, send, and receive methods.
|
agent, logger, send, and receive methods.
|
||||||
"""
|
"""
|
||||||
b = BDITextBeliefBehaviour()
|
b = TextBeliefExtractorBehaviour()
|
||||||
|
|
||||||
b.agent = MagicMock()
|
b.agent = MagicMock()
|
||||||
b.send = AsyncMock()
|
b.send = AsyncMock()
|
||||||
@@ -103,7 +104,7 @@ async def test_run_message_from_transcriber_demo(behavior, mock_settings, monkey
|
|||||||
# Arrange: Create a mock message from the transcriber
|
# Arrange: Create a mock message from the transcriber
|
||||||
transcription_text = "hello world"
|
transcription_text = "hello world"
|
||||||
mock_msg = create_mock_message(
|
mock_msg = create_mock_message(
|
||||||
mock_settings.agent_settings.per_transcription_agent_name, transcription_text, None
|
mock_settings.agent_settings.transcription_name, transcription_text, None
|
||||||
)
|
)
|
||||||
behavior.receive.return_value = mock_msg
|
behavior.receive.return_value = mock_msg
|
||||||
|
|
||||||
@@ -122,7 +123,7 @@ async def test_run_message_from_transcriber_demo(behavior, mock_settings, monkey
|
|||||||
|
|
||||||
assert (
|
assert (
|
||||||
sent_msg.to
|
sent_msg.to
|
||||||
== mock_settings.agent_settings.bdi_belief_collector_agent_name
|
== mock_settings.agent_settings.bdi_belief_collector_name
|
||||||
+ "@"
|
+ "@"
|
||||||
+ mock_settings.agent_settings.host
|
+ mock_settings.agent_settings.host
|
||||||
)
|
)
|
||||||
@@ -162,7 +163,7 @@ async def test_process_transcription_success(behavior, mock_settings):
|
|||||||
# 2. Inspect the sent message
|
# 2. Inspect the sent message
|
||||||
sent_msg: Message = behavior.send.call_args[0][0]
|
sent_msg: Message = behavior.send.call_args[0][0]
|
||||||
expected_to = (
|
expected_to = (
|
||||||
mock_settings.agent_settings.bdi_belief_collector_agent_name
|
mock_settings.agent_settings.bdi_belief_collector_name
|
||||||
+ "@"
|
+ "@"
|
||||||
+ mock_settings.agent_settings.host
|
+ mock_settings.agent_settings.host
|
||||||
)
|
)
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from control_backend.agents.per_agents.per_transcription_agent.speech_recognizer import (
|
from control_backend.agents.perception.transcription_agent.speech_recognizer import (
|
||||||
OpenAIWhisperSpeechRecognizer,
|
OpenAIWhisperSpeechRecognizer,
|
||||||
SpeechRecognizer,
|
SpeechRecognizer,
|
||||||
)
|
)
|
||||||
@@ -3,7 +3,7 @@ from unittest.mock import AsyncMock, MagicMock
|
|||||||
import pytest
|
import pytest
|
||||||
import zmq
|
import zmq
|
||||||
|
|
||||||
from control_backend.agents.per_agents.per_vad_agent import SocketPoller
|
from control_backend.agents.perception.vad_agent import SocketPoller
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@@ -16,9 +16,7 @@ async def test_socket_poller_with_data(socket, mocker):
|
|||||||
socket_data = b"test"
|
socket_data = b"test"
|
||||||
socket.recv.return_value = socket_data
|
socket.recv.return_value = socket_data
|
||||||
|
|
||||||
mock_poller: MagicMock = mocker.patch(
|
mock_poller: MagicMock = mocker.patch("control_backend.agents.perception.vad_agent.zmq.Poller")
|
||||||
"control_backend.agents.per_agents.per_vad_agent.zmq.Poller"
|
|
||||||
)
|
|
||||||
mock_poller.return_value.poll.return_value = [(socket, zmq.POLLIN)]
|
mock_poller.return_value.poll.return_value = [(socket, zmq.POLLIN)]
|
||||||
|
|
||||||
poller = SocketPoller(socket)
|
poller = SocketPoller(socket)
|
||||||
@@ -37,9 +35,7 @@ async def test_socket_poller_with_data(socket, mocker):
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_socket_poller_no_data(socket, mocker):
|
async def test_socket_poller_no_data(socket, mocker):
|
||||||
mock_poller: MagicMock = mocker.patch(
|
mock_poller: MagicMock = mocker.patch("control_backend.agents.perception.vad_agent.zmq.Poller")
|
||||||
"control_backend.agents.per_agents.per_vad_agent.zmq.Poller"
|
|
||||||
)
|
|
||||||
mock_poller.return_value.poll.return_value = []
|
mock_poller.return_value.poll.return_value = []
|
||||||
|
|
||||||
poller = SocketPoller(socket)
|
poller = SocketPoller(socket)
|
||||||
@@ -3,7 +3,7 @@ from unittest.mock import AsyncMock, MagicMock
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from control_backend.agents.per_agents.per_vad_agent import Streaming
|
from control_backend.agents.perception.vad_agent import StreamingBehaviour
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@@ -20,7 +20,7 @@ def audio_out_socket():
|
|||||||
def mock_agent(mocker):
|
def mock_agent(mocker):
|
||||||
"""Fixture to create a mock BDIAgent."""
|
"""Fixture to create a mock BDIAgent."""
|
||||||
agent = MagicMock()
|
agent = MagicMock()
|
||||||
agent.jid = "per_vad_agent@test"
|
agent.jid = "vad_agent@test"
|
||||||
return agent
|
return agent
|
||||||
|
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ def streaming(audio_in_socket, audio_out_socket, mock_agent):
|
|||||||
import torch
|
import torch
|
||||||
|
|
||||||
torch.hub.load.return_value = (..., ...) # Mock
|
torch.hub.load.return_value = (..., ...) # Mock
|
||||||
streaming = Streaming(audio_in_socket, audio_out_socket)
|
streaming = StreamingBehaviour(audio_in_socket, audio_out_socket)
|
||||||
streaming._ready = True
|
streaming._ready = True
|
||||||
streaming.agent = mock_agent
|
streaming.agent = mock_agent
|
||||||
return streaming
|
return streaming
|
||||||
Reference in New Issue
Block a user