import logging

from spade.behaviour import CyclicBehaviour

from control_backend.core.config import settings


class ReceiveLLMResponseBehaviour(CyclicBehaviour):
    """
    Adds behavior to receive responses from the LLM Agent.
    """

    logger = logging.getLogger("BDI/LLM Reciever")

    async def run(self):
        msg = await self.receive(timeout=2)
        if not msg:
            return

        sender = msg.sender.node
        match sender:
            case settings.agent_settings.llm_agent_name:
                content = msg.body
                self.logger.info("Received LLM response: %s", content)
                # Here the BDI can pass the message back as a response
            case _:
                self.logger.debug("Not from the llm, discarding message")
                pass
