fix: allow subgoals in triggers and empty plan
Copies the goal and changes can_fail to false. Also add a warning for empty plans in goals. ref: N25B-460
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import logging
|
||||
from functools import singledispatchmethod
|
||||
|
||||
from slugify import slugify
|
||||
@@ -59,6 +60,7 @@ class AgentSpeakGenerator:
|
||||
"""
|
||||
|
||||
_asp: AstProgram
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def generate(self, program: Program) -> str:
|
||||
"""
|
||||
@@ -472,6 +474,7 @@ class AgentSpeakGenerator:
|
||||
:param main_goal: Whether this is a main goal (for UI notification purposes).
|
||||
"""
|
||||
context: list[AstExpression] = [self._astify(phase)]
|
||||
if goal.can_fail:
|
||||
context.append(~self._astify(goal, achieved=True))
|
||||
if previous_goal and previous_goal.can_fail:
|
||||
context.append(self._astify(previous_goal, achieved=True))
|
||||
@@ -496,6 +499,10 @@ class AgentSpeakGenerator:
|
||||
if not goal.can_fail and not continues_response:
|
||||
body.append(AstStatement(StatementType.ADD_BELIEF, self._astify(goal, achieved=True)))
|
||||
|
||||
if len(body) == 0:
|
||||
self.logger.warning("Goal with no plan detected: %s", goal.name)
|
||||
body.append(AstStatement(StatementType.EMPTY, AstLiteral("true")))
|
||||
|
||||
self._asp.plans.append(AstPlan(TriggerType.ADDED_GOAL, self._astify(goal), context, body))
|
||||
|
||||
self._asp.plans.append(
|
||||
@@ -556,10 +563,10 @@ class AgentSpeakGenerator:
|
||||
)
|
||||
)
|
||||
for step in trigger.plan.steps:
|
||||
body.append(self._step_to_statement(step))
|
||||
if isinstance(step, Goal):
|
||||
step.can_fail = False # triggers are continuous sequence
|
||||
subgoals.append(step)
|
||||
new_step = step.model_copy(update={"can_fail": False}) # triggers are sequence
|
||||
subgoals.append(new_step)
|
||||
body.append(self._step_to_statement(step))
|
||||
|
||||
# Arbitrary wait for UI to display nicely
|
||||
body.append(
|
||||
|
||||
Reference in New Issue
Block a user