Source code for agents.rules.stopped_long_trigger

 1"""Example of a :py:class:`MultiRule` if the agent does not perform any actions for a certain time."""
 2
 3from typing import List
 4
 5from agents.tools.logs import logger
 6from classes.constants import AgentState, Phase
 7from classes.rule import ConditionFunction, Context, MultiRule, Rule
 8
 9
[docs] 10class StoppedTooLongTrigger(MultiRule): 11 """Triggers child rules if the agent has stopped for a too long time""" 12 13 phase = Phase.UPDATE_INFORMATION | Phase.END 14 15 _warning_given = False 16 17 stop_time_threshold = 60 18 """Time in seconds the agent is allowed to stop before triggering the rule.""" 19
[docs] 20 @ConditionFunction 21 def condition(self, ctx: Context) -> bool: 22 # time stopped in seconds # NOTE: Only in sync mode! 23 s_stopped = ctx.agent.current_states[AgentState.STOPPED] * ctx.config.planner.dt 24 if s_stopped < self.stop_time_threshold: 25 self._warning_given = False 26 return False 27 return True
28
[docs] 29 def action(self, ctx: Context) -> None: 30 if not self._warning_given: 31 self._warning_given = True 32 logger.warning("Agent has stopped for too long.")
33 34 # ... Child rules to be executed 35 rules: List[Rule] = []