diff --git a/src/wiseagents/utils.py b/src/wiseagents/utils.py index f471ad1..ef27337 100644 --- a/src/wiseagents/utils.py +++ b/src/wiseagents/utils.py @@ -25,7 +25,7 @@ def enforce_no_abstract_class_instances(cls: type, check: type): def log_messages_exchanged(messages: List[ChatCompletionMessageParam], agent_name: str, - context_name: str, dir_path: Optional[str] = './log'): + context_name: str, dir_path: Optional[str] = './log/messages'): """ Log the messages exchanged in a conversation to the given file. @@ -35,13 +35,17 @@ def log_messages_exchanged(messages: List[ChatCompletionMessageParam], agent_nam context_name: the name of the context in which the conversation took place dir_path: the directory path to output the log file to, defaults to './log' """ - if not os.path.exists(dir_path): - os.makedirs(dir_path) - with open(f'{dir_path}/messages-{agent_name}-{context_name}.md', 'w') as file: + context_name = context_name.replace("_", "/") + if not os.path.exists(f'{dir_path}/{context_name}/md') : + os.makedirs(f'{dir_path}/{context_name}/md') + if not os.path.exists(f'{dir_path}/{context_name}/json') : + os.makedirs(f'{dir_path}/{context_name}/json') + + with open(f'{dir_path}/{context_name}/md/{agent_name}.md', 'w') as file: message : ChatCompletionMessageParam for message in messages: file.write(f"## {message.get('role')}\n {message.get('content')}\n\n\n") #file.write(f"{message}\n\n\n") - with open(f'{dir_path}/messages-{agent_name}-{context_name}.log', 'w') as file: + with open(f'{dir_path}/{context_name}/json/{agent_name}.json', 'w') as file: json.dump(messages, file, indent=2) - print(f"[{agent_name}] Logged messages to {dir_path}/messages-{agent_name}-{context_name}.log for the current request") + print(f"[{agent_name}] Logged messages to {dir_path}/{context_name}/ for the current request")