diff --git a/polymind/core/memory.py b/polymind/core/memory.py index f1bee7b..849456a 100644 --- a/polymind/core/memory.py +++ b/polymind/core/memory.py @@ -21,6 +21,7 @@ class LinearMemory(Memory): """ memory_list: List[str] = Field(default=[], description="The list of memory stored in the memory.") + capacity: int = Field(default=100, description="The capacity of the memory.") def set_memory(self, piece: str, **kwargs) -> None: """Set the memory. @@ -29,9 +30,15 @@ def set_memory(self, piece: str, **kwargs) -> None: piece (str): The piece of memory to store. """ self.memory_list.append(piece) + if len(self.memory_list) > self.capacity: + self.memory_list.pop(0) def get_memory(self, last_k: int = 5, **kwargs) -> str: - """Get the last k pieces of memory.""" + """Get the last k pieces of memory. + + Args: + last_k (int): The number of last pieces of memory to retrieve. + """ if last_k == 0 or last_k > len(self.memory_list): return "\n".join(self.memory_list) else: diff --git a/polymind/core/task.py b/polymind/core/task.py index a39e928..0359482 100644 --- a/polymind/core/task.py +++ b/polymind/core/task.py @@ -141,17 +141,17 @@ class AtomTask(BaseTask): Example inputs: 1. --- - '{{"context": "I\'m unable to provide real-time data."}}' + '{{"context": "I\'m unable to connect the Internet.", "answer": "Please check the network connection}}' --- 2. --- - '{{"question": "\n\n what's the biggest news about AI today?\n\t\t\t\n\n.", "answer": "OpenAI has released GPT-10."}}' + '{{"context": "\n what's the biggest news about AI today?\n\t\t\n\n.", "answer": "OpenAI released GPT-10."}}' --- Corresponding outputs: 1. ``` {{ - "output": "I'm unable to provide real-time data." + "output": "If unable to provide real-time data, please check the network connection." }} ``` 2. @@ -161,12 +161,11 @@ class AtomTask(BaseTask): }} ``` - The real input is as below: - --- + The real input is available in the below json blob. + Please consolidate and convert the info into the ```json blob```, and the key should be "output". + ```json {input} - --- - - Please extract and post-process the result into the ```json blob```, and the key should be "output". + ``` """ def __init__(self, tool_manager: ToolManager, tool_retriever: RetrieveTool, **kwargs): @@ -266,10 +265,10 @@ async def _execute(self, input: Message) -> Message: input.content[ "input" ] = f""" - Context: + Context: Output of the previous steps: ------ - {memory_context} + [{memory_context}] ------ {input_field} Objective: {self.task_name} @@ -303,7 +302,8 @@ async def _execute(self, input: Message) -> Message: response = await self._use_tool(objective=self.task_name, tool_description=answer_blob["action"]) self._logger.task_log(f"Output of task {self.task_name}: {response.content}") # Add the objective and output to the memory. - self.memory.set_memory(piece=f"{self.task_name}: {response.content}") + response_output = response.content["output"] + self.memory.set_memory(piece=f"{self.task_name}: {response_output}") return response @@ -344,11 +344,17 @@ async def _execute(self, input: Message) -> Message: Message: The result of the composite task carried in a message. """ message = input - updated_message = self._update_context(input=message) - task = self._get_next_task(updated_message) + # updated_message = self._update_context(input=message) + # task = self._get_next_task(updated_message) + # while task: + # task_result_message = await task(input=updated_message) + # output_message = self._update_context(input=task_result_message) + # task = self._get_next_task(output_message) + self._update_context(input=message) + task = self._get_next_task(message) while task: - task_result_message = await task(input=updated_message) - output_message = self._update_context(input=task_result_message) + message = await task(message) + output_message = self._update_context(input=message) task = self._get_next_task(output_message) return output_message