From f94560b70ec362be55a3fdbb70ae14cbb1647ac4 Mon Sep 17 00:00:00 2001 From: garyzhang99 <46197280+garyzhang99@users.noreply.github.com> Date: Tue, 16 Apr 2024 13:42:14 +0800 Subject: [PATCH] [Hot fix]Fix bug when dialog agent self.memory is None (#157) --- src/agentscope/agents/dialog_agent.py | 5 ++++- src/agentscope/agents/dict_dialog_agent.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/agentscope/agents/dialog_agent.py b/src/agentscope/agents/dialog_agent.py index 8cbaaed30..8e8996753 100644 --- a/src/agentscope/agents/dialog_agent.py +++ b/src/agentscope/agents/dialog_agent.py @@ -56,6 +56,7 @@ def __init__( "will be removed in the future.", ) + # TODO change typing from dict to MSG def reply(self, x: dict = None) -> dict: """Reply function of the agent. Processes the input data, generates a prompt using the current dialogue memory and system @@ -78,7 +79,9 @@ def reply(self, x: dict = None) -> dict: # prepare prompt prompt = self.model.format( Msg("system", self.sys_prompt, role="system"), - self.memory and self.memory.get_memory(), # type: ignore[arg-type] + self.memory + and self.memory.get_memory() + or x, # type: ignore[arg-type] ) # call llm and generate response diff --git a/src/agentscope/agents/dict_dialog_agent.py b/src/agentscope/agents/dict_dialog_agent.py index 3dd255da0..b1c6b27b8 100644 --- a/src/agentscope/agents/dict_dialog_agent.py +++ b/src/agentscope/agents/dict_dialog_agent.py @@ -121,6 +121,7 @@ def __init__( "will be removed in the future.", ) + # TODO change typing from dict to MSG def reply(self, x: dict = None) -> dict: """Reply function of the agent. Processes the input data, generates a prompt using the current @@ -150,7 +151,9 @@ def reply(self, x: dict = None) -> dict: # prepare prompt prompt = self.model.format( Msg("system", self.sys_prompt, role="system"), - self.memory and self.memory.get_memory(), # type: ignore[arg-type] + self.memory + and self.memory.get_memory() + or x, # type: ignore[arg-type] ) # call llm