feat: added a functionality for monitoring page

ref: N25B-400
This commit is contained in:
Pim Hutting
2026-01-08 09:56:10 +01:00
parent 20e5e46639
commit 4bf2be6359
5 changed files with 161 additions and 40 deletions

View File

@@ -1,5 +1,6 @@
phase("0e0f239c-efe9-442c-bdd7-3aabfccd1c49").
phase("db4c68c3-0316-4905-a8db-22dd5bec7abf").
keyword_said(Keyword) :- (user_said(Message) & .substring(Keyword, Message, Pos)) & (Pos >= 0).
norm("do nothing and make a little dance, do a little laugh") :- phase("db4c68c3-0316-4905-a8db-22dd5bec7abf") & keyword_said("hi").
+!reply_with_goal(Goal)
@@ -19,36 +20,30 @@ keyword_said(Keyword) :- (user_said(Message) & .substring(Keyword, Message, Pos)
.reply(Message, Norms).
+user_said(Message)
: phase("0e0f239c-efe9-442c-bdd7-3aabfccd1c49")
: phase("db4c68c3-0316-4905-a8db-22dd5bec7abf")
<- .notify_user_said(Message);
-responded_this_turn;
!check_triggers;
!transition_phase.
+!transition_phase
: phase("0e0f239c-efe9-442c-bdd7-3aabfccd1c49") &
not responded_this_turn
<- -phase("0e0f239c-efe9-442c-bdd7-3aabfccd1c49");
+phase("1fc60869-86db-483d-b475-b8ecdec4bba8");
?user_said(Message);
-+user_said(Message);
.notify_transition_phase("0e0f239c-efe9-442c-bdd7-3aabfccd1c49", "1fc60869-86db-483d-b475-b8ecdec4bba8").
+!check_triggers
: phase("db4c68c3-0316-4905-a8db-22dd5bec7abf") &
semantic_hello
<- .notify_trigger_start("trigger_");
.notify_trigger_end("trigger_").
+user_said(Message)
: phase("1fc60869-86db-483d-b475-b8ecdec4bba8")
<- .notify_user_said(Message);
-responded_this_turn;
!check_triggers;
!transition_phase.
+!trigger_
<- .notify_trigger_start("trigger_");
.notify_trigger_end("trigger_").
+!transition_phase
: phase("1fc60869-86db-483d-b475-b8ecdec4bba8") &
: phase("db4c68c3-0316-4905-a8db-22dd5bec7abf") &
not responded_this_turn
<- -phase("1fc60869-86db-483d-b475-b8ecdec4bba8");
<- .notify_transition_phase("db4c68c3-0316-4905-a8db-22dd5bec7abf", "end");
-phase("db4c68c3-0316-4905-a8db-22dd5bec7abf");
+phase("end");
?user_said(Message);
-+user_said(Message);
.notify_transition_phase("1fc60869-86db-483d-b475-b8ecdec4bba8", "end").
-+user_said(Message).
+user_said(Message)
: phase("end")

View File

@@ -176,6 +176,16 @@ class AgentSpeakGenerator:
context.append(self._astify(from_phase.goals[-1], achieved=True))
body = [
AstStatement(
StatementType.DO_ACTION,
AstLiteral(
"notify_transition_phase",
[
AstString(str(from_phase.id)),
AstString(str(to_phase.id) if to_phase else "end"),
],
),
),
AstStatement(StatementType.REMOVE_BELIEF, from_phase_ast),
AstStatement(StatementType.ADD_BELIEF, to_phase_ast),
]
@@ -192,20 +202,6 @@ class AgentSpeakGenerator:
]
)
# Notify outside world about transition
body.append(
AstStatement(
StatementType.DO_ACTION,
AstLiteral(
"notify_transition_phase",
[
AstString(str(from_phase.id)),
AstString(str(to_phase.id) if to_phase else "end"),
],
),
)
)
self._asp.plans.append(
AstPlan(TriggerType.ADDED_GOAL, AstLiteral("transition_phase"), context, body)
)

View File

@@ -311,6 +311,15 @@ class BDICoreAgent(BaseAgent):
message_text = agentspeak.grounded(term.args[0], intention.scope)
norms = agentspeak.grounded(term.args[1], intention.scope)
norm_update_message = InternalMessage(
to=settings.agent_settings.user_interrupt_name,
sender=self.name,
thread="active_norms_update",
body=str(norms),
)
self.add_behavior(self.send(norm_update_message))
self.logger.debug("Norms: %s", norms)
self.logger.debug("User text: %s", message_text)

View File

@@ -75,7 +75,12 @@ class BDIProgramManager(BaseAgent):
self._transition_phase(phases["old"], phases["new"])
def _transition_phase(self, old: str, new: str):
assert old == str(self._phase.id)
if old != str(self._phase.id):
self.logger.warning(
f"Phase transition desync detected! ASL requested move from '{old}', "
f"but Python is currently in '{self._phase.id}'. Request ignored."
)
return
if new == "end":
self._phase = None
@@ -208,6 +213,7 @@ class BDIProgramManager(BaseAgent):
self._initialize_internal_state(program)
await self._send_program_to_user_interrupt(program)
await self._send_clear_llm_history()
await asyncio.gather(
@@ -216,6 +222,21 @@ class BDIProgramManager(BaseAgent):
self._send_goals_to_semantic_belief_extractor(),
)
async def _send_program_to_user_interrupt(self, program: Program):
"""
Send the received program to the User Interrupt Agent.
:param program: The program object received from the API.
"""
msg = InternalMessage(
sender=self.name,
to=settings.agent_settings.user_interrupt_name,
body=program.model_dump_json(),
thread="new_program",
)
await self.send(msg)
async def setup(self):
"""
Initialize the agent.