Пример #1
0
    def __init__(self, agent, task_data={}, memid=None):
        self.agent = agent
        self.run_count = 0
        self.interrupted = False
        self.finished = False
        self.name = None
        self.undone = False
        self.last_stepped_time = None

        if memid:
            self.memid = memid
            N = TaskNode(agent.memory, self.memid).update_task(task=self)
            # this is an egg, hatch it
            if N.prio == -3:
                N.get_update_status({"prio": -1})
        else:
            TaskNode.create(self.agent.memory, self)
        # remember to get children of blocking tasks (and delete this comment)
        if task_data.get("blocking"):
            TripleNode.create(self.agent.memory,
                              subj=self.memid,
                              pred_text="has_tag",
                              obj_text="blocking_task")

        # TODO put these in memory in a new table?
        # TODO methods for safely changing these
        i, s, ru, re = self.get_default_conditions(task_data, agent)
        self.init_condition = i
        self.stop_condition = s
        self.run_condition = ru
        self.remove_condition = re
        TripleNode.create(
            self.agent.memory,
            subj=self.memid,
            pred_text="has_name",
            obj_text=self.__class__.__name__.lower(),
        )
        TaskNode(agent.memory, self.memid).update_task(task=self)
Пример #2
0
    def task_stack_push(self,
                        task,
                        parent_memid: str = None,
                        chat_effect: bool = False) -> "TaskNode":
        """Create a task object in memory, add triples and add to task stack

        Args:
            task (Task): The task to be pushed
            parent_memid (string): Memory ID of the task's parent
            chat_effect (bool): If the task was a result of a chat, add the triple.

        Returns:
            TaskNode: A TaskNode object

        Examples ::
            >>> task = Move(agent, {"target": pos_to_np([0, 0 , 0]), "approx" : 3})
            >>> parent_memid = '10517cc584844659907ccfa6161e9d32'
            >>> task_stack_push(task, parent_memid)
        """

        memid = TaskNode.create(self, task)

        # Relations
        if parent_memid:
            self.add_triple(subj=memid,
                            pred_text="_has_parent_task",
                            obj=parent_memid)
        if chat_effect:
            chat = self.get_most_recent_incoming_chat()
            assert chat is not None, "chat_effect=True with no incoming chats"
            self.add_triple(subj=chat.memid,
                            pred_text="chat_effect_",
                            obj=memid)

        # Return newly created object
        return TaskNode(self, memid)