(self)
| 58 | self._agent_push_keys = None |
| 59 | @masf_hook(Node.Hook.BUILD) |
| 60 | def build(self): |
| 61 | assert self._pull_keys is not None, "pull_keys must be provided" |
| 62 | assert self._push_keys is not None, "push_keys must be provided" |
| 63 | if self._agent_pull_keys == None: |
| 64 | self._agent_pull_keys = self._pull_keys |
| 65 | if self._agent_push_keys == None: |
| 66 | self._agent_push_keys = self._push_keys |
| 67 | self._attributes_store = {**self._attributes_store,**self._pull_keys} |
| 68 | def role_playing_terminate_condition_function(message: dict, attributes: dict[str, object],controller:Node) -> bool: |
| 69 | discussion_finished = attributes.get("discussion_finished", False) |
| 70 | if discussion_finished in ["False", "false", "FALSE", False]: |
| 71 | logger.debug("%s discussion_finished is False; continue role playing", controller.name) |
| 72 | return False |
| 73 | logger.debug("%s discussion_finished is True; terminate role playing", controller.name) |
| 74 | return True |
| 75 | pre_action = self.create_node( |
| 76 | CustomNode, |
| 77 | name=self._name + "_pre_action_custom_node", |
| 78 | forward=self._pre_action_func |
| 79 | ) |
| 80 | |
| 81 | post_action = self.create_node( |
| 82 | CustomNode, |
| 83 | name=self._name + "_after_phase_action", |
| 84 | forward=self._post_action_func |
| 85 | ) |
| 86 | role_playing = self.create_node( |
| 87 | InstructorAssistantGraph, |
| 88 | name=self._name + "_role_playing_graph", |
| 89 | instructor_role_name=self._instructor_role_name, |
| 90 | instructor_instructions=self._instructor_instructions, |
| 91 | assistant_role_name=self._assistant_role_name, |
| 92 | assistant_instructions=self._assistant_instructions, |
| 93 | phase_instructions=self._phase_instructions, |
| 94 | instructor_memories=[self._memory], |
| 95 | assistant_memories=[self._memory], |
| 96 | model=self._model, |
| 97 | max_turns=2 * self._max_turns - 1, |
| 98 | terminate_condition_function=role_playing_terminate_condition_function, |
| 99 | pull_keys=self._agent_pull_keys, |
| 100 | push_keys=self._agent_push_keys |
| 101 | ) |
| 102 | # reflection |
| 103 | if self._need_reflect: |
| 104 | reflection_placeholders= { |
| 105 | "conversations":"", |
| 106 | "question":"", |
| 107 | } |
| 108 | def reflection_set_inputs(IAGraph:InstructorAssistantGraph,result:dict,input:dict) -> str: |
| 109 | conversations = [] |
| 110 | instructor_chat_history = IAGraph.instructor_chat_history.get_messages(top_k=10000) |
| 111 | assistant_chat_history = IAGraph.assistant_chat_history.get_messages(top_k=10000) |
| 112 | chat_history = instructor_chat_history if len(instructor_chat_history) > len(assistant_chat_history) else assistant_chat_history |
| 113 | assistant_role_name = self._instructor_role_name if len(instructor_chat_history) > len(assistant_chat_history) else self._assistant_role_name |
| 114 | user_role_name = self._instructor_role_name if len(instructor_chat_history) <= len(assistant_chat_history) else self._assistant_role_name |
| 115 | |
| 116 | for message in chat_history: |
| 117 | if message["role"] == "assistant": |
no test coverage detected