feat: apply new agent naming standards

Expanding abbreviations to remove ambiguity, simplifying agent names to reduce repetition.

ref: N25B-257
This commit is contained in:
Twirre Meulenbelt
2025-11-19 15:56:09 +01:00
parent f4dbca5b94
commit efe49c219c
39 changed files with 218 additions and 222 deletions

View File

@@ -1 +0,0 @@
from .act_speech_agent import ActSpeechAgent as ActSpeechAgent

View File

@@ -0,0 +1 @@
from .robot_speech_agent import RobotSpeechAgent as RobotSpeechAgent

View File

@@ -10,7 +10,7 @@ from control_backend.core.config import settings
from control_backend.schemas.ri_message import SpeechCommand
class ActSpeechAgent(BaseAgent):
class RobotSpeechAgent(BaseAgent):
subsocket: zmq.Socket
pubsocket: zmq.Socket
address = ""
@@ -64,7 +64,7 @@ class ActSpeechAgent(BaseAgent):
async def setup(self):
"""
Setup the command agent
Setup the robot speech command agent
"""
self.logger.info("Setting up %s", self.jid)

View 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,
)

View File

@@ -57,7 +57,7 @@ class BDICoreAgent(BDIAgent):
class SendBehaviour(OneShotBehaviour):
async def run(self) -> None:
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,
)

View File

@@ -32,7 +32,7 @@ class BeliefSetterBehaviour(CyclicBehaviour):
self.agent.logger.debug("Processing message from sender: %s", sender)
match sender:
case settings.agent_settings.bdi_belief_collector_agent_name:
case settings.agent_settings.bdi_belief_collector_name:
self.agent.logger.debug(
"Message is from the belief collector agent. Processing as belief message."
)

View File

@@ -15,14 +15,14 @@ class ReceiveLLMResponseBehaviour(CyclicBehaviour):
sender = msg.sender.node
match sender:
case settings.agent_settings.llm_agent_name:
case settings.agent_settings.llm_name:
content = msg.body
self.agent.logger.info("Received LLM response: %s", content)
speech_command = SpeechCommand(data=content)
message = Message(
to=settings.agent_settings.act_speech_agent_name
to=settings.agent_settings.robot_speech_name
+ "@"
+ settings.agent_settings.host,
sender=self.agent.jid,

View File

@@ -7,7 +7,7 @@ from spade.behaviour import CyclicBehaviour
from control_backend.core.config import settings
class BelCollectorBehaviour(CyclicBehaviour):
class BeliefCollectorBehaviour(CyclicBehaviour):
"""
Continuously collects beliefs/emotions from extractor agents:
Then we send a unified belief packet to the BDI agent.
@@ -83,9 +83,7 @@ class BelCollectorBehaviour(CyclicBehaviour):
if not beliefs:
return
to_jid = (
f"{settings.agent_settings.bdi_core_agent_agent_name}@{settings.agent_settings.host}"
)
to_jid = f"{settings.agent_settings.bdi_core_name}@{settings.agent_settings.host}"
msg = Message(to=to_jid, sender=self.agent.jid, thread="beliefs")
msg.body = json.dumps(beliefs)

View File

@@ -1,11 +1,11 @@
from control_backend.agents.base import BaseAgent
from .behaviours.bel_collector_behaviour import BelCollectorBehaviour
from .behaviours.belief_collector_behaviour import BeliefCollectorBehaviour
class BDIBeliefCollectorAgent(BaseAgent):
async def setup(self):
self.logger.info("BDIBeliefCollectorAgent starting (%s)", self.jid)
# Attach the continuous collector behaviour (listens and forwards to BDI)
self.add_behaviour(BelCollectorBehaviour())
self.add_behaviour(BeliefCollectorBehaviour())
self.logger.info("BDIBeliefCollectorAgent ready.")

View File

@@ -7,7 +7,7 @@ from spade.message import Message
from control_backend.core.config import settings
class BDITextBeliefBehaviour(CyclicBehaviour):
class TextBeliefExtractorBehaviour(CyclicBehaviour):
logger = logging.getLogger(__name__)
# TODO: LLM prompt nog hardcoded
@@ -44,7 +44,7 @@ class BDITextBeliefBehaviour(CyclicBehaviour):
sender = msg.sender.node
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)
await self._process_transcription_demo(msg.body)
case _:
@@ -71,7 +71,7 @@ class BDITextBeliefBehaviour(CyclicBehaviour):
belief_message = Message()
belief_message.to = (
settings.agent_settings.bdi_belief_collector_agent_name
settings.agent_settings.bdi_belief_collector_name
+ "@"
+ settings.agent_settings.host
)
@@ -95,9 +95,7 @@ class BDITextBeliefBehaviour(CyclicBehaviour):
belief_msg = Message()
belief_msg.to = (
settings.agent_settings.bdi_belief_collector_agent_name
+ "@"
+ settings.agent_settings.host
settings.agent_settings.bdi_belief_collector_name + "@" + settings.agent_settings.host
)
belief_msg.body = payload
belief_msg.thread = "beliefs"

View File

@@ -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())

View File

@@ -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

View File

@@ -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())

View File

@@ -1 +0,0 @@
from .com_ri_agent import ComRIAgent as ComRIAgent

View File

@@ -0,0 +1 @@
from .ri_communication_agent import RICommunicationAgent as RICommunicationAgent

View File

@@ -8,10 +8,10 @@ from zmq.asyncio import Context
from control_backend.agents import BaseAgent
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
_address = ""
_bind = True
@@ -204,11 +204,11 @@ class ComRIAgent(BaseAgent):
else:
self._req_socket.bind(addr)
case "actuation":
ri_commands_agent = ActSpeechAgent(
settings.agent_settings.act_speech_agent_name
ri_commands_agent = RobotSpeechAgent(
settings.agent_settings.robot_speech_name
+ "@"
+ settings.agent_settings.host,
settings.agent_settings.act_speech_agent_name,
settings.agent_settings.robot_speech_name,
address=addr,
bind=bind,
)

View File

@@ -39,7 +39,7 @@ class LLMAgent(BaseAgent):
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")
await self._process_bdi_message(msg)
else:
@@ -63,9 +63,7 @@ class LLMAgent(BaseAgent):
Sends a response message back to the BDI Core Agent.
"""
reply = Message(
to=settings.agent_settings.bdi_core_agent_agent_name
+ "@"
+ settings.agent_settings.host,
to=settings.agent_settings.bdi_core_name + "@" + settings.agent_settings.host,
body=msg,
)
await self.send(reply)

View File

@@ -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)

View File

@@ -1,4 +0,0 @@
from .per_transcription_agent.per_transcription_agent import (
PerTranscriptionAgent as PerTranscriptionAgent,
)
from .per_vad_agent import PerVADAgent as PerVADAgent

View File

@@ -0,0 +1,4 @@
from .transcription_agent.transcription_agent import (
TranscriptionAgent as TranscriptionAgent,
)
from .vad_agent import VADAgent as VADAgent

View File

@@ -12,24 +12,20 @@ from control_backend.core.config import settings
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
transcription to other agents.
"""
def __init__(self, audio_in_address: str):
jid = (
settings.agent_settings.per_transcription_agent_name
+ "@"
+ settings.agent_settings.host
)
super().__init__(jid, settings.agent_settings.per_transcription_agent_name)
jid = settings.agent_settings.transcription_name + "@" + settings.agent_settings.host
super().__init__(jid, settings.agent_settings.transcription_name)
self.audio_in_address = audio_in_address
self.audio_in_socket: azmq.Socket | None = None
class Transcribing(CyclicBehaviour):
class TranscribingBehaviour(CyclicBehaviour):
def __init__(self, audio_in_socket: azmq.Socket):
super().__init__()
self.audio_in_socket = audio_in_socket
@@ -83,7 +79,7 @@ class PerTranscriptionAgent(BaseAgent):
self._connect_audio_in_socket()
transcribing = self.Transcribing(self.audio_in_socket)
transcribing = self.TranscribingBehaviour(self.audio_in_socket)
transcribing.warmup()
self.add_behaviour(transcribing)

View File

@@ -7,7 +7,7 @@ from spade.behaviour import CyclicBehaviour
from control_backend.agents import BaseAgent
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]:
@@ -40,7 +40,7 @@ class SocketPoller[T]:
return None
class Streaming(CyclicBehaviour):
class StreamingBehaviour(CyclicBehaviour):
def __init__(self, audio_in_socket: azmq.Socket, audio_out_socket: azmq.Socket):
super().__init__()
self.audio_in_poller = SocketPoller[bytes](audio_in_socket)
@@ -102,15 +102,15 @@ class Streaming(CyclicBehaviour):
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
fragments with detected speech to other agents over ZeroMQ.
"""
def __init__(self, audio_in_address: str, audio_in_bind: bool):
jid = settings.agent_settings.per_vad_agent_name + "@" + settings.agent_settings.host
super().__init__(jid, settings.agent_settings.per_vad_agent_name)
jid = settings.agent_settings.vad_name + "@" + settings.agent_settings.host
super().__init__(jid, settings.agent_settings.vad_name)
self.audio_in_address = audio_in_address
self.audio_in_bind = audio_in_bind
@@ -118,7 +118,7 @@ class PerVADAgent(BaseAgent):
self.audio_in_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):
"""
@@ -162,11 +162,11 @@ class PerVADAgent(BaseAgent):
return
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)
# Start agents dependent on the output audio fragments here
transcriber = PerTranscriptionAgent(audio_out_address)
transcriber = TranscriptionAgent(audio_out_address)
await transcriber.start()
self.logger.info("Finished setting up %s", self.jid)

View File

@@ -9,16 +9,16 @@ class ZMQSettings(BaseModel):
class AgentSettings(BaseModel):
host: str = "localhost"
bdi_core_agent_agent_name: str = "bdi_core_agent"
bdi_belief_collector_agent_name: str = "bdi_belief_collector_agent"
bdi_text_belief_agent_name: str = "bdi_text_belief_agent"
per_vad_agent_name: str = "per_vad_agent"
llm_agent_name: str = "llm_agent"
test_agent_name: str = "test_agent"
per_transcription_agent_name: str = "per_transcription_agent"
bdi_core_name: str = "bdi_core_agent"
bdi_belief_collector_name: str = "belief_collector_agent"
text_belief_extractor_name: str = "text_belief_extractor_agent"
vad_name: str = "vad_agent"
llm_name: str = "llm_agent"
test_name: str = "test_agent"
transcription_name: str = "transcription_agent"
com_ri_agent_name: str = "com_ri_agent"
act_speech_agent_name: str = "act_speech_agent"
ri_communication_name: str = "ri_communication_agent"
robot_speech_name: str = "robot_speech_agent"
class LLMSettings(BaseModel):

View File

@@ -9,21 +9,21 @@ from zmq.asyncio import Context
# Act agents
# BDI agents
from control_backend.agents.bdi_agents import (
from control_backend.agents.bdi import (
BDIBeliefCollectorAgent,
BDICoreAgent,
BDITextBeliefAgent,
TextBeliefExtractorAgent,
)
# Communication agents
from control_backend.agents.com_agents import ComRIAgent
from control_backend.agents.communication import RICommunicationAgent
# Emotional Agents
# LLM Agents
from control_backend.agents.llm_agents import LLMAgent
from control_backend.agents.llm import LLMAgent
# Perceive agents
from control_backend.agents.per_agents import PerVADAgent
from control_backend.agents.perception import VADAgent
# Other backend imports
from control_backend.api.v1.router import api_router
@@ -77,12 +77,12 @@ async def lifespan(app: FastAPI):
logger.info("Initializing and starting agents.")
agents_to_start = {
"ComRIAgent": (
ComRIAgent,
RICommunicationAgent,
{
"name": settings.agent_settings.com_ri_agent_name,
"jid": f"{settings.agent_settings.com_ri_agent_name}"
"name": settings.agent_settings.ri_communication_name,
"jid": f"{settings.agent_settings.ri_communication_name}"
f"@{settings.agent_settings.host}",
"password": settings.agent_settings.com_ri_agent_name,
"password": settings.agent_settings.ri_communication_name,
"address": "tcp://*:5555",
"bind": True,
},
@@ -90,56 +90,61 @@ async def lifespan(app: FastAPI):
"LLMAgent": (
LLMAgent,
{
"name": settings.agent_settings.llm_agent_name,
"jid": f"{settings.agent_settings.llm_agent_name}@{settings.agent_settings.host}",
"password": settings.agent_settings.llm_agent_name,
"name": settings.agent_settings.llm_name,
"jid": f"{settings.agent_settings.llm_name}@{settings.agent_settings.host}",
"password": settings.agent_settings.llm_name,
},
),
"BDICoreAgent": (
BDICoreAgent,
{
"name": settings.agent_settings.bdi_core_agent_agent_name,
"jid": f"{settings.agent_settings.bdi_core_agent_agent_name}@"
f"{settings.agent_settings.host}",
"password": settings.agent_settings.bdi_core_agent_agent_name,
"asl": "src/control_backend/agents/bdi_agents/bdi_core_agent/rules.asl",
"name": settings.agent_settings.bdi_core_name,
"jid": f"{settings.agent_settings.bdi_core_name}@{settings.agent_settings.host}",
"password": settings.agent_settings.bdi_core_name,
"asl": "src/control_backend/agents/bdi/bdi_core_agent/rules.asl",
},
),
"BDIBeliefCollectorAgent": (
BDIBeliefCollectorAgent,
{
"name": settings.agent_settings.bdi_belief_collector_agent_name,
"jid": f"{settings.agent_settings.bdi_belief_collector_agent_name}@"
"name": settings.agent_settings.bdi_belief_collector_name,
"jid": f"{settings.agent_settings.bdi_belief_collector_name}@"
f"{settings.agent_settings.host}",
"password": settings.agent_settings.bdi_belief_collector_agent_name,
"password": settings.agent_settings.bdi_belief_collector_name,
},
),
"BDITextBeliefAgent": (
BDITextBeliefAgent,
TextBeliefExtractorAgent,
{
"name": settings.agent_settings.bdi_text_belief_agent_name,
"jid": f"{settings.agent_settings.bdi_text_belief_agent_name}@"
"name": settings.agent_settings.text_belief_extractor_name,
"jid": f"{settings.agent_settings.text_belief_extractor_name}@"
f"{settings.agent_settings.host}",
"password": settings.agent_settings.bdi_text_belief_agent_name,
"password": settings.agent_settings.text_belief_extractor_name,
},
),
"PerVADAgent": (
PerVADAgent,
VADAgent,
{"audio_in_address": "tcp://localhost:5558", "audio_in_bind": False},
),
}
vad_agent = None
for name, (agent_class, kwargs) in agents_to_start.items():
try:
logger.debug("Starting agent: %s", name)
agent_instance = agent_class(**{k: v for k, v in kwargs.items() if k != "name"})
await agent_instance.start()
if isinstance(agent_instance, VADAgent):
vad_agent = agent_instance
logger.info("Agent '%s' started successfully.", name)
except Exception as e:
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.
raise
await vad_agent.streaming_behaviour.reset()
logger.info("Application startup complete.")
yield

View File

@@ -4,13 +4,13 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest
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
def zmq_context(mocker):
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()
return mock_context
@@ -21,8 +21,8 @@ async def test_setup_bind(zmq_context, mocker):
"""Test setup with bind=True"""
fake_socket = zmq_context.return_value.socket.return_value
agent = ActSpeechAgent("test@server", "password", address="tcp://localhost:5555", bind=True)
settings = mocker.patch("control_backend.agents.act_agents.act_speech_agent.settings")
agent = RobotSpeechAgent("test@server", "password", address="tcp://localhost:5555", bind=True)
settings = mocker.patch("control_backend.agents.actuation.robot_speech_agent.settings")
settings.zmq_settings.internal_sub_address = "tcp://internal:1234"
await agent.setup()
@@ -40,8 +40,8 @@ async def test_setup_connect(zmq_context, mocker):
"""Test setup with bind=False"""
fake_socket = zmq_context.return_value.socket.return_value
agent = ActSpeechAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
settings = mocker.patch("control_backend.agents.act_agents.act_speech_agent.settings")
agent = RobotSpeechAgent("test@server", "password", address="tcp://localhost:5555", bind=False)
settings = mocker.patch("control_backend.agents.actuation.robot_speech_agent.settings")
settings.zmq_settings.internal_sub_address = "tcp://internal:1234"
await agent.setup()
@@ -59,7 +59,7 @@ async def test_send_commands_behaviour_valid_message():
)
fake_socket.send_json = AsyncMock()
agent = ActSpeechAgent("test@server", "password")
agent = RobotSpeechAgent("test@server", "password")
agent.subsocket = fake_socket
agent.pubsocket = fake_socket
@@ -67,7 +67,7 @@ async def test_send_commands_behaviour_valid_message():
behaviour.agent = agent
with patch(
"control_backend.agents.act_agents.act_speech_agent.SpeechCommand"
"control_backend.agents.actuation.robot_speech_agent.SpeechCommand"
) as MockSpeechCommand:
mock_message = MagicMock()
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.send_json = AsyncMock()
agent = ActSpeechAgent("test@server", "password")
agent = RobotSpeechAgent("test@server", "password")
agent.subsocket = fake_socket
agent.pubsocket = fake_socket

View File

@@ -3,11 +3,11 @@ from unittest.mock import ANY, AsyncMock, MagicMock, patch
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():
return "control_backend.agents.com_agents.com_ri_agent.ActSpeechAgent"
def speech_agent_path():
return "control_backend.agents.communication.ri_communication_agent.RobotSpeechAgent"
def fake_json_correct_negototiate_1():
@@ -91,7 +91,7 @@ def fake_json_invalid_id_negototiate():
@pytest.fixture
def zmq_context(mocker):
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()
return mock_context
@@ -109,12 +109,17 @@ async def test_setup_creates_socket_and_negotiate_1(zmq_context):
fake_socket.send_multipart = AsyncMock()
# 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.start = AsyncMock()
# --- 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()
# --- Assert ---
@@ -144,12 +149,17 @@ async def test_setup_creates_socket_and_negotiate_2(zmq_context):
fake_socket.send_multipart = AsyncMock()
# 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.start = AsyncMock()
# --- 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()
# --- 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,
# 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.start = AsyncMock()
# --- 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)
# --- Assert ---
@@ -213,11 +228,16 @@ async def test_setup_creates_socket_and_negotiate_4(zmq_context):
fake_socket.send_multipart = AsyncMock()
# 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.start = AsyncMock()
# --- 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()
# --- Assert ---
@@ -247,11 +267,16 @@ async def test_setup_creates_socket_and_negotiate_5(zmq_context):
fake_socket.send_multipart = AsyncMock()
# 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.start = AsyncMock()
# --- 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()
# --- Assert ---
@@ -281,11 +306,16 @@ async def test_setup_creates_socket_and_negotiate_6(zmq_context):
fake_socket.send_multipart = AsyncMock()
# 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.start = AsyncMock()
# --- 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()
# --- 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,
# 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.start = AsyncMock()
# --- 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)
# --- 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.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.start = AsyncMock()
# --- 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)
# --- Assert ---
@@ -372,7 +412,7 @@ async def test_listen_behaviour_ping_correct():
fake_socket.recv_json = AsyncMock(return_value={"endpoint": "ping", "data": {}})
fake_socket.send_multipart = AsyncMock()
agent = ComRIAgent("test@server", "password")
agent = RICommunicationAgent("test@server", "password")
agent._req_socket = fake_socket
agent.connected = True
@@ -405,7 +445,7 @@ async def test_listen_behaviour_ping_wrong_endpoint():
)
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.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.send_multipart = AsyncMock()
agent = ComRIAgent("test@server", "password")
agent = RICommunicationAgent("test@server", "password")
agent._req_socket = fake_socket
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.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.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)
@@ -500,11 +545,16 @@ async def test_setup_unpacking_exception(zmq_context):
fake_socket.recv_json = AsyncMock(return_value=malformed_data)
# 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.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 ---

View File

@@ -5,27 +5,25 @@ import pytest
import zmq
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
def zmq_context(mocker):
mock_context = mocker.patch(
"control_backend.agents.per_agents.per_vad_agent.azmq.Context.instance"
)
mock_context = mocker.patch("control_backend.agents.perception.vad_agent.azmq.Context.instance")
mock_context.return_value = MagicMock()
return mock_context
@pytest.fixture
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
def per_transcription_agent(mocker):
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):
"""
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()
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
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()
@@ -78,7 +76,7 @@ def test_out_socket_creation(zmq_context):
"""
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()
@@ -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.ZMQBindError
)
per_vad_agent = PerVADAgent("tcp://localhost:12345", False)
per_vad_agent = VADAgent("tcp://localhost:12345", False)
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.
"""
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(
1000,
10000,

View File

@@ -5,7 +5,7 @@ import pytest
import soundfile as sf
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]:
@@ -42,14 +42,12 @@ async def test_real_audio(mocker):
audio_in_socket = AsyncMock()
audio_in_socket.recv.side_effect = audio_chunks
mock_poller: MagicMock = mocker.patch(
"control_backend.agents.per_agents.per_vad_agent.zmq.Poller"
)
mock_poller: MagicMock = mocker.patch("control_backend.agents.perception.vad_agent.zmq.Poller")
mock_poller.return_value.poll.return_value = [(audio_in_socket, zmq.POLLIN)]
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.agent = MagicMock()
for _ in audio_chunks:

View File

@@ -4,12 +4,12 @@ from unittest.mock import AsyncMock, MagicMock, call
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,
)
# 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"
@@ -27,8 +27,8 @@ def belief_setter_behaviour(mock_agent, mocker):
"""Fixture to create an instance of BeliefSetterBehaviour with a mocked agent."""
# Patch the settings to use a predictable agent name
mocker.patch(
"control_backend.agents.bdi_agents.bdi_core_agent."
"behaviours.belief_setter_behaviour.settings.agent_settings.bdi_belief_collector_agent_name",
"control_backend.agents.bdi.bdi_core_agent."
"behaviours.belief_setter_behaviour.settings.agent_settings.bdi_belief_collector_name",
COLLECTOR_AGENT_NAME,
)

View File

@@ -3,8 +3,8 @@ from unittest.mock import AsyncMock, MagicMock
import pytest
from control_backend.agents.bdi_agents.bdi_belief_collector_agent.behaviours.bel_collector_behaviour import ( # noqa: E501
BelCollectorBehaviour,
from control_backend.agents.bdi.belief_collector_agent.behaviours.belief_collector_behaviour import ( # noqa: E501
BeliefCollectorBehaviour,
)
@@ -20,7 +20,7 @@ def create_mock_message(sender_node: str, body: str) -> MagicMock:
def mock_agent(mocker):
"""Fixture to create a mock Agent."""
agent = MagicMock()
agent.jid = "bdi_belief_collector_agent@test"
agent.jid = "belief_collector_agent@test"
return agent
@@ -30,7 +30,7 @@ def bel_collector_behaviouror(mock_agent, mocker):
# Patch asyncio.sleep to prevent tests from actually waiting
mocker.patch("asyncio.sleep", return_value=None)
collector = BelCollectorBehaviour()
collector = BeliefCollectorBehaviour()
collector.agent = mock_agent
# Mock the receive method, we will control its return value in each test
collector.receive = AsyncMock()

View File

@@ -4,8 +4,8 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest
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.
BDITextBeliefBehaviour,
from control_backend.agents.bdi.text_belief_extractor_agent.behaviours.text_belief_extractor_behaviour import ( # noqa: E501, We can't shorten this import.
TextBeliefExtractorBehaviour,
)
@@ -17,15 +17,16 @@ def mock_settings():
"""
# Create a mock object that mimics the nested structure
settings_mock = MagicMock()
settings_mock.agent_settings.per_transcription_agent_name = "transcriber"
settings_mock.agent_settings.bdi_belief_collector_agent_name = "collector"
settings_mock.agent_settings.transcription_name = "transcriber"
settings_mock.agent_settings.bdi_belief_collector_name = "collector"
settings_mock.agent_settings.host = "fake.host"
# Use patch to replace the settings object during the test
# Adjust 'control_backend.behaviours.belief_from_text.settings' to where
# your behaviour file imports it from.
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,
):
yield settings_mock
@@ -37,7 +38,7 @@ def behavior(mock_settings):
Creates an instance of the BDITextBeliefBehaviour behaviour and mocks its
agent, logger, send, and receive methods.
"""
b = BDITextBeliefBehaviour()
b = TextBeliefExtractorBehaviour()
b.agent = MagicMock()
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
transcription_text = "hello world"
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
@@ -122,7 +123,7 @@ async def test_run_message_from_transcriber_demo(behavior, mock_settings, monkey
assert (
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
)
@@ -162,7 +163,7 @@ async def test_process_transcription_success(behavior, mock_settings):
# 2. Inspect the sent message
sent_msg: Message = behavior.send.call_args[0][0]
expected_to = (
mock_settings.agent_settings.bdi_belief_collector_agent_name
mock_settings.agent_settings.bdi_belief_collector_name
+ "@"
+ mock_settings.agent_settings.host
)

View File

@@ -1,6 +1,6 @@
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,
SpeechRecognizer,
)

View File

@@ -3,7 +3,7 @@ from unittest.mock import AsyncMock, MagicMock
import pytest
import zmq
from control_backend.agents.per_agents.per_vad_agent import SocketPoller
from control_backend.agents.perception.vad_agent import SocketPoller
@pytest.fixture
@@ -16,9 +16,7 @@ async def test_socket_poller_with_data(socket, mocker):
socket_data = b"test"
socket.recv.return_value = socket_data
mock_poller: MagicMock = mocker.patch(
"control_backend.agents.per_agents.per_vad_agent.zmq.Poller"
)
mock_poller: MagicMock = mocker.patch("control_backend.agents.perception.vad_agent.zmq.Poller")
mock_poller.return_value.poll.return_value = [(socket, zmq.POLLIN)]
poller = SocketPoller(socket)
@@ -37,9 +35,7 @@ async def test_socket_poller_with_data(socket, mocker):
@pytest.mark.asyncio
async def test_socket_poller_no_data(socket, mocker):
mock_poller: MagicMock = mocker.patch(
"control_backend.agents.per_agents.per_vad_agent.zmq.Poller"
)
mock_poller: MagicMock = mocker.patch("control_backend.agents.perception.vad_agent.zmq.Poller")
mock_poller.return_value.poll.return_value = []
poller = SocketPoller(socket)

View File

@@ -3,7 +3,7 @@ from unittest.mock import AsyncMock, MagicMock
import numpy as np
import pytest
from control_backend.agents.per_agents.per_vad_agent import Streaming
from control_backend.agents.perception.vad_agent import StreamingBehaviour
@pytest.fixture
@@ -20,7 +20,7 @@ def audio_out_socket():
def mock_agent(mocker):
"""Fixture to create a mock BDIAgent."""
agent = MagicMock()
agent.jid = "per_vad_agent@test"
agent.jid = "vad_agent@test"
return agent
@@ -29,7 +29,7 @@ def streaming(audio_in_socket, audio_out_socket, mock_agent):
import torch
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.agent = mock_agent
return streaming