refactor: agents inherit logger from BaseAgent
Created a class `BaseAgent`, from which all agents inherit. They get assigned a logger with a nice name (something like `control_backend.agents.AgentName`). The BDI core takes care of its own logger, as bdi is still a module. ref: N25B-241
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
import json
|
||||
import logging
|
||||
from spade.agent import Agent
|
||||
from spade.behaviour import CyclicBehaviour
|
||||
import zmq
|
||||
|
||||
import zmq
|
||||
from spade.behaviour import CyclicBehaviour
|
||||
|
||||
from control_backend.agents import BaseAgent
|
||||
from control_backend.core.config import settings
|
||||
from control_backend.core.zmq_context import context
|
||||
from control_backend.schemas.ri_message import SpeechCommand
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RICommandAgent(Agent):
|
||||
class RICommandAgent(BaseAgent):
|
||||
subsocket: zmq.Socket
|
||||
pubsocket: zmq.Socket
|
||||
address = ""
|
||||
@@ -47,13 +45,13 @@ class RICommandAgent(Agent):
|
||||
# Send to the robot.
|
||||
await self.agent.pubsocket.send_json(message.model_dump())
|
||||
except Exception as e:
|
||||
logger.error("Error processing message: %s", e)
|
||||
self.logger.error("Error processing message: %s", e)
|
||||
|
||||
async def setup(self):
|
||||
"""
|
||||
Setup the command agent
|
||||
"""
|
||||
logger.info("Setting up %s", self.jid)
|
||||
self.logger.info("Setting up %s", self.jid)
|
||||
|
||||
# To the robot
|
||||
self.pubsocket = context.socket(zmq.PUB)
|
||||
@@ -71,4 +69,4 @@ class RICommandAgent(Agent):
|
||||
commands_behaviour = self.SendCommandsBehaviour()
|
||||
self.add_behaviour(commands_behaviour)
|
||||
|
||||
logger.info("Finished setting up %s", self.jid)
|
||||
self.logger.info("Finished setting up %s", self.jid)
|
||||
|
||||
Reference in New Issue
Block a user