fix: default behavior and end phase
ref: N25B-448
This commit is contained in:
@@ -7,6 +7,7 @@ from control_backend.agents.bdi.agentspeak_ast import (
|
||||
AstBinaryOp,
|
||||
AstExpression,
|
||||
AstLiteral,
|
||||
AstNumber,
|
||||
AstPlan,
|
||||
AstProgram,
|
||||
AstRule,
|
||||
@@ -44,7 +45,11 @@ class AgentSpeakGenerator:
|
||||
def generate(self, program: Program) -> str:
|
||||
self._asp = AstProgram()
|
||||
|
||||
self._asp.rules.append(AstRule(self._astify(program.phases[0])))
|
||||
if program.phases:
|
||||
self._asp.rules.append(AstRule(self._astify(program.phases[0])))
|
||||
else:
|
||||
self._asp.rules.append(AstRule(AstLiteral("phase", [AstString("end")])))
|
||||
|
||||
self._add_keyword_inference()
|
||||
self._add_default_plans()
|
||||
|
||||
@@ -72,6 +77,7 @@ class AgentSpeakGenerator:
|
||||
self._add_reply_with_goal_plan()
|
||||
self._add_say_plan()
|
||||
self._add_reply_plan()
|
||||
self._add_notify_cycle_plan()
|
||||
|
||||
def _add_reply_with_goal_plan(self):
|
||||
self._asp.plans.append(
|
||||
@@ -134,6 +140,19 @@ class AgentSpeakGenerator:
|
||||
)
|
||||
)
|
||||
|
||||
def _add_notify_cycle_plan(self):
|
||||
self._asp.plans.append(
|
||||
AstPlan(
|
||||
TriggerType.ADDED_GOAL,
|
||||
AstLiteral("notify_cycle"),
|
||||
[],
|
||||
[
|
||||
AstStatement(StatementType.DO_ACTION, AstLiteral("notify_ui")),
|
||||
AstStatement(StatementType.DO_ACTION, AstLiteral("wait", [AstNumber(1)])),
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
def _process_phases(self, phases: list[Phase]) -> None:
|
||||
for curr_phase, next_phase in zip([None] + phases, phases + [None], strict=True):
|
||||
if curr_phase:
|
||||
@@ -148,7 +167,9 @@ class AgentSpeakGenerator:
|
||||
trigger_literal=AstLiteral("user_said", [AstVar("Message")]),
|
||||
context=[AstLiteral("phase", [AstString("end")])],
|
||||
body=[
|
||||
AstStatement(StatementType.DO_ACTION, AstLiteral("notify_user_said")),
|
||||
AstStatement(
|
||||
StatementType.DO_ACTION, AstLiteral("notify_user_said", [AstVar("Message")])
|
||||
),
|
||||
AstStatement(StatementType.ACHIEVE_GOAL, AstLiteral("reply")),
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user