fix: fix test race condition
ref: N25B-301
This commit is contained in:
@@ -45,7 +45,7 @@ class RobotSpeechAgent(BaseAgent):
|
||||
self.subsocket.connect(settings.zmq_settings.internal_sub_address)
|
||||
self.subsocket.setsockopt(zmq.SUBSCRIBE, b"command")
|
||||
|
||||
await self.add_behavior(self._zmq_command_loop())
|
||||
self.add_behavior(self._zmq_command_loop())
|
||||
|
||||
self.logger.info("Finished setting up %s", self.name)
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class BDICoreAgent(BaseAgent):
|
||||
await self._load_asl()
|
||||
|
||||
# Start the BDI cycle loop
|
||||
await self.add_behavior(self._bdi_loop())
|
||||
self.add_behavior(self._bdi_loop())
|
||||
self._wake_bdi_loop.set()
|
||||
self.logger.debug("Setup complete.")
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class RICommunicationAgent(BaseAgent):
|
||||
|
||||
if await self._negotiate_connection():
|
||||
self.connected = True
|
||||
await self.add_behavior(self._listen_loop())
|
||||
self.add_behavior(self._listen_loop())
|
||||
else:
|
||||
self.logger.warning("Failed to negotiate connection during setup.")
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class TranscriptionAgent(BaseAgent):
|
||||
self.speech_recognizer.load_model() # Warmup
|
||||
|
||||
# Start background loop
|
||||
await self.add_behavior(self._transcribing_loop())
|
||||
self.add_behavior(self._transcribing_loop())
|
||||
|
||||
self.logger.info("Finished setting up %s", self.name)
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ class VADAgent(BaseAgent):
|
||||
# Warmup/reset
|
||||
await self.reset_stream()
|
||||
|
||||
await self.add_behavior(self._streaming_loop())
|
||||
self.add_behavior(self._streaming_loop())
|
||||
|
||||
# Start agents dependent on the output audio fragments here
|
||||
transcriber = TranscriptionAgent(audio_out_address)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from abc import ABC, abstractmethod
|
||||
from asyncio import Task
|
||||
from collections.abc import Coroutine
|
||||
|
||||
import zmq
|
||||
@@ -75,8 +76,8 @@ class BaseAgent(ABC):
|
||||
await self.setup()
|
||||
|
||||
# Start processing inbox and ZMQ messages
|
||||
await self.add_behavior(self._process_inbox())
|
||||
await self.add_behavior(self._receive_internal_zmq_loop())
|
||||
self.add_behavior(self._process_inbox())
|
||||
self.add_behavior(self._receive_internal_zmq_loop())
|
||||
|
||||
async def stop(self):
|
||||
"""Stops the agent."""
|
||||
@@ -128,7 +129,7 @@ class BaseAgent(ABC):
|
||||
"""Override this to handle incoming messages."""
|
||||
raise NotImplementedError
|
||||
|
||||
async def add_behavior(self, coro: Coroutine):
|
||||
def add_behavior(self, coro: Coroutine) -> Task:
|
||||
"""
|
||||
Helper to add a behavior to the agent. To add asynchronous behavior to an agent, define
|
||||
an `async` function and add it to the task list by calling :func:`add_behavior`
|
||||
@@ -138,3 +139,4 @@ class BaseAgent(ABC):
|
||||
task = asyncio.create_task(coro)
|
||||
self._tasks.add(task)
|
||||
task.add_done_callback(self._tasks.discard)
|
||||
return task
|
||||
|
||||
Reference in New Issue
Block a user