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

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