From c266df4d3c505b17c6c9b660fe620aea86dfe2f3 Mon Sep 17 00:00:00 2001 From: DavdGao Date: Wed, 14 Aug 2024 09:39:39 +0800 Subject: [PATCH] Allow user to initialize agent without calling agentscope.init (#404) --- src/agentscope/logging.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/agentscope/logging.py b/src/agentscope/logging.py index a4c4a5f4c..47d7709b7 100644 --- a/src/agentscope/logging.py +++ b/src/agentscope/logging.py @@ -89,15 +89,18 @@ def _save_msg(msg: Msg) -> None: msg (`Msg`): The message object to be saved. """ - logger.log( - LEVEL_SAVE_LOG, - msg.formatted_str(colored=False), - ) - - logger.log( - LEVEL_SAVE_MSG, - json.dumps(msg, ensure_ascii=False, default=lambda _: None), - ) + # TODO: Unified into a manager rather than an indicated attribute here + if hasattr(logger, "chat"): + # Not initialize yet + logger.log( + LEVEL_SAVE_LOG, + msg.formatted_str(colored=False), + ) + + logger.log( + LEVEL_SAVE_MSG, + json.dumps(msg, ensure_ascii=False, default=lambda _: None), + ) def log_msg(msg: Msg, disable_gradio: bool = False) -> None: