From 8cd8988fe0dc445c0fbbc47cba3b96a50b98f2c8 Mon Sep 17 00:00:00 2001 From: Kasper Marinus Date: Wed, 12 Nov 2025 14:00:50 +0100 Subject: [PATCH] feat: (hopefully) optional norms and goals ref: N25B-200 --- src/control_backend/agents/bdi/bdi_core.py | 46 +++++++++++++++++----- src/control_backend/agents/bdi/rules.asl | 15 +++++-- src/control_backend/agents/llm/llm.py | 2 +- 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/control_backend/agents/bdi/bdi_core.py b/src/control_backend/agents/bdi/bdi_core.py index 1c267d3..a014e08 100644 --- a/src/control_backend/agents/bdi/bdi_core.py +++ b/src/control_backend/agents/bdi/bdi_core.py @@ -45,17 +45,45 @@ class BDICoreAgent(BDIAgent): Example: .reply("Hello LLM!") """ message_text = agentspeak.grounded(term.args[0], intention.scope) - norm = agentspeak.grounded(term.args[1], intention.scope) - goal = agentspeak.grounded(term.args[2], intention.scope) + norms = agentspeak.grounded(term.args[1], intention.scope) + goals = agentspeak.grounded(term.args[2], intention.scope) - self.logger.debug("Norms: %s", norm) - self.logger.debug("Goals: %s", goal) - self.logger.debug("Reply action sending: %s", message_text) + self.logger.debug("Norms: %s", norms) + self.logger.debug("Goals: %s", goals) + self.logger.debug("User text: %s", message_text) - self._send_to_llm(str(message_text), str(norm), str(goal)) + self._send_to_llm(str(message_text), str(norms), str(goals)) yield - def _send_to_llm(self, text: str, norm: str, goal: str): + @actions.add(".reply_no_norms", 2) + def _reply_no_norms(agent: "BDICoreAgent", term, intention): + message_text = agentspeak.grounded(term.args[0], intention.scope) + goals = agentspeak.grounded(term.args[1], intention.scope) + + self.logger.debug("Goals: %s", goals) + self.logger.debug("User text: %s", message_text) + + self._send_to_llm(str(message_text), goals=str(goals)) + + @actions.add(".reply_no_goals", 2) + def _reply_no_goals(agent: "BDICoreAgent", term, intention): + message_text = agentspeak.grounded(term.args[0], intention.scope) + norms = agentspeak.grounded(term.args[1], intention.scope) + + self.logger.debug("Norms: %s", norms) + self.logger.debug("User text: %s", message_text) + + self._send_to_llm(str(message_text), norms=str(norms)) + + @actions.add(".reply_no_goals_no_norms", 1) + def _reply_no_goals_no_norms(agent: "BDICoreAgent", term, intention): + message_text = agentspeak.grounded(term.args[0], intention.scope) + + self.logger.debug("User text: %s", message_text) + + self._send_to_llm(message_text) + + def _send_to_llm(self, text: str, norms: str = None, goals: str = None): """ Sends a text query to the LLM Agent asynchronously. """ @@ -64,8 +92,8 @@ class BDICoreAgent(BDIAgent): async def run(self) -> None: message_dict = { "text": text, - "norms": norm, - "goals": goal, + "norms": norms if norms else "", + "goals": goals if goals else "", } msg = Message( to=settings.agent_settings.llm_agent_name + "@" + settings.agent_settings.host, diff --git a/src/control_backend/agents/bdi/rules.asl b/src/control_backend/agents/bdi/rules.asl index 76369af..1167743 100644 --- a/src/control_backend/agents/bdi/rules.asl +++ b/src/control_backend/agents/bdi/rules.asl @@ -1,6 +1,15 @@ -norms(test_norm). -goals(test_goal). - +new_message : user_said(Message) & norms(Norms) & goals(Goals) <- -new_message; .reply(Message, Norms, Goals). + ++new_message : user_said(Message) & norms(Norms) <- + -new_message; + .reply_no_goals(Message, Norms). + ++new_message : user_said(Message) & goals(Goals) <- + -new_message; + .reply_no_norms(Message, Goals). + ++new_message : user_said(Message) <- + -new_message; + .reply_no_goals_no_norms(Message). \ No newline at end of file diff --git a/src/control_backend/agents/llm/llm.py b/src/control_backend/agents/llm/llm.py index 3fa9adf..4fd58e6 100644 --- a/src/control_backend/agents/llm/llm.py +++ b/src/control_backend/agents/llm/llm.py @@ -82,7 +82,7 @@ class LLMAgent(BaseAgent): :param prompt: Input text prompt to pass to the LLM. :yield: Fragments of the LLM-generated content. """ - instructions = LLMInstructions(norms, goals) + instructions = LLMInstructions(norms if norms else None, goals if goals else None) messages = [ { "role": "developer",