fix: sync issues

ref: N25B-447
This commit is contained in:
2026-01-14 15:28:29 +01:00
parent 8f6662e64a
commit 39e1bb1ead
5 changed files with 47 additions and 22 deletions

View File

@@ -50,6 +50,8 @@ class AgentSpeakGenerator:
else:
self._asp.rules.append(AstRule(AstLiteral("phase", [AstString("end")])))
self._asp.rules.append(AstRule(AstLiteral("!notify_cycle")))
self._add_keyword_inference()
self._add_default_plans()
@@ -147,8 +149,18 @@ class AgentSpeakGenerator:
AstLiteral("notify_cycle"),
[],
[
AstStatement(StatementType.DO_ACTION, AstLiteral("notify_ui")),
AstStatement(StatementType.DO_ACTION, AstLiteral("wait", [AstNumber(1)])),
AstStatement(
StatementType.DO_ACTION,
AstLiteral(
"findall",
[AstVar("Norm"), AstLiteral("norm", [AstVar("Norm")]), AstVar("Norms")],
),
),
AstStatement(
StatementType.DO_ACTION, AstLiteral("notify_norms", [AstVar("Norms")])
),
AstStatement(StatementType.DO_ACTION, AstLiteral("wait", [AstNumber(100)])),
AstStatement(StatementType.ACHIEVE_GOAL, AstLiteral("notify_cycle")),
],
)
)
@@ -365,6 +377,10 @@ class AgentSpeakGenerator:
if isinstance(step, Goal):
step.can_fail = False # triggers are continuous sequence
subgoals.append(step)
# Arbitrary wait for UI to display nicely
body.append(AstStatement(StatementType.DO_ACTION, AstLiteral("wait", [AstNumber(2000)])))
body.append(
AstStatement(
StatementType.DO_ACTION,

View File

@@ -107,7 +107,6 @@ class BDICoreAgent(BaseAgent):
if not maybe_more_work:
deadline = self.bdi_agent.shortest_deadline()
if deadline:
self.logger.debug("Sleeping until %s", deadline)
await asyncio.sleep(deadline - time.time())
maybe_more_work = True
else:
@@ -335,14 +334,6 @@ 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,
thread="active_norms_update",
body=str(norms),
)
self.add_behavior(self.send(norm_update_message))
self.add_behavior(self._send_to_llm(str(message_text), str(norms), ""))
yield
@@ -355,14 +346,20 @@ class BDICoreAgent(BaseAgent):
message_text = agentspeak.grounded(term.args[0], intention.scope)
norms = agentspeak.grounded(term.args[1], intention.scope)
goal = agentspeak.grounded(term.args[2], intention.scope)
self.add_behavior(self._send_to_llm(str(message_text), str(norms), str(goal)))
yield
@self.actions.add(".notify_norms", 1)
def _notify_norms(agent, term, intention):
norms = agentspeak.grounded(term.args[0], intention.scope)
norm_update_message = InternalMessage(
to=settings.agent_settings.user_interrupt_name,
thread="active_norms_update",
body=str(norms),
)
self.add_behavior(self.send(norm_update_message))
self.add_behavior(self._send_to_llm(str(message_text), str(norms), str(goal)))
self.add_behavior(self.send(norm_update_message, should_log=False))
yield
@self.actions.add(".say", 1)
@@ -473,7 +470,6 @@ class BDICoreAgent(BaseAgent):
body=str(trigger_name),
)
# TODO: check with Pim
self.add_behavior(self.send(msg))
yield

View File

@@ -97,6 +97,15 @@ class BDIProgramManager(BaseAgent):
if new == "end":
self._phase = None
# Notify user interaction agent
msg = InternalMessage(
to=settings.agent_settings.user_interrupt_name,
thread="transition_phase",
body="end",
)
self.logger.info("Transitioned to end phase, notifying UserInterruptAgent.")
self.add_behavior(self.send(msg))
return
for phase in self._program.phases: