fix: separate trigger plan generation
ref: N25B-376
This commit is contained in:
@@ -310,6 +310,54 @@ class AgentSpeakGenerator:
|
||||
|
||||
lines.append("")
|
||||
|
||||
extra_previous_goal: Goal | None = None
|
||||
for extra_goal in extra_goals_to_generate:
|
||||
lines += self._generate_trigger_plan_recursive(extra_goal, phase, extra_previous_goal)
|
||||
extra_previous_goal = extra_goal
|
||||
|
||||
return lines
|
||||
|
||||
def _generate_trigger_plan_recursive(
|
||||
self, goal: Goal, phase: Phase, previous_goal: Goal | None = None
|
||||
) -> list[str]:
|
||||
lines = []
|
||||
lines.append(f"+{self._slugify(goal, include_prefix=True)}")
|
||||
|
||||
extra_goals_to_generate = []
|
||||
|
||||
steps = goal.plan.steps
|
||||
|
||||
if len(steps) == 0:
|
||||
lines.append(f"{' ' * 2}<-{' ' * 2}true.")
|
||||
return lines
|
||||
|
||||
first_step = steps[0]
|
||||
lines.append(
|
||||
f"{' ' * 2}<-{' ' * 2}{self._slugify(first_step, include_prefix=True)}"
|
||||
f"{'.' if len(steps) == 1 and goal.can_fail else ';'}"
|
||||
)
|
||||
if isinstance(first_step, Goal):
|
||||
extra_goals_to_generate.append(first_step)
|
||||
|
||||
for step in steps[1:-1]:
|
||||
lines.append(f"{' ' * 6}{self._slugify(step, include_prefix=True)};")
|
||||
if isinstance(step, Goal):
|
||||
extra_goals_to_generate.append(step)
|
||||
|
||||
if len(steps) > 1:
|
||||
last_step = steps[-1]
|
||||
lines.append(
|
||||
f"{' ' * 6}{self._slugify(last_step, include_prefix=True)}"
|
||||
f"{'.' if goal.can_fail else ';'}"
|
||||
)
|
||||
if isinstance(last_step, Goal):
|
||||
extra_goals_to_generate.append(last_step)
|
||||
|
||||
if not goal.can_fail:
|
||||
lines.append(f"{' ' * 6}+achieved_{self._slugify(goal)}.")
|
||||
|
||||
lines.append("")
|
||||
|
||||
extra_previous_goal: Goal | None = None
|
||||
for extra_goal in extra_goals_to_generate:
|
||||
lines += self._generate_goal_plan_recursive(extra_goal, phase, extra_previous_goal)
|
||||
@@ -457,3 +505,7 @@ class BDIProgramManager(BaseAgent):
|
||||
self.sub_socket.subscribe("program")
|
||||
|
||||
self.add_behavior(self._receive_programs())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
do_things()
|
||||
|
||||
Reference in New Issue
Block a user