fix: made beliefs a dict of lists

[
    Before it was a list of a dict of lists of lists of strings
    now it is a dict of lists of lists of strings as prescribed by architecture (knowledge base)
    *also added some tests, but will have to add some more
]

[ref]: N25B-206
This commit is contained in:
Pim Hutting
2025-10-28 14:17:07 +01:00
parent 1f34b14dfa
commit 2efce93a37
3 changed files with 110 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
import json
import logging
from spade.behaviour import CyclicBehaviour
from spade.message import Message
from spade.agent import Message
from control_backend.core.config import settings
logger = logging.getLogger(__name__)
@@ -62,20 +62,29 @@ class ContinuousBeliefCollector(CyclicBehaviour):
Expected payload:
{
"type": "belief_extraction_text",
"beliefs": [
{"user_said": [["hello"],["Can you help me?"],["stop talking to me"],["No"],["Pepper do a dance"]]}
]
"beliefs": {"user_said": [["hello","test"],["Can you help me?"],["stop talking to me"],["No"],["Pepper do a dance"]]}
}
"""
beliefs = payload.get("beliefs", [])
if not isinstance(beliefs, list):
logger.warning("BeliefCollector: 'beliefs' is not a list: %r", beliefs)
beliefs = payload.get("beliefs", dict)
if not beliefs:
logger.info("BeliefCollector: no beliefs to process.")
return
if not isinstance(beliefs, dict):
logger.warning("BeliefCollector: 'beliefs' is not a dict: %r", beliefs)
return
if not all(isinstance(v, list) for v in beliefs.values()):
logger.warning("BeliefCollector: 'beliefs' values are not all lists: %r", beliefs)
return
logger.info("BeliefCollector: forwarding %d beliefs.", len(beliefs))
for b in beliefs:
logger.info(" - %s", b)
for belief_name, belief_lists in beliefs.items():
for args in belief_lists:
logger.info(" - %s %s", belief_name, " ".join(map(str, args)))
await self._send_beliefs_to_bdi(beliefs, origin=origin)

View File

@@ -12,9 +12,8 @@ class BeliefTextAgent(Agent):
# Send multiple beliefs in one JSON payload
payload = {
"type": "belief_extraction_text",
"beliefs": [
{"user_said": [["hello"],["Can you help me?"],["stop talking to me"],["No"],["Pepper do a dance"]]}
]
"beliefs": {"user_said": [["hello","test"],["Can you help me?"],["stop talking to me"],["No"],["Pepper do a dance"]]}
}
msg = Message(to=to_jid)