From 7508e9941f6f743d4e3dbcf8e7028db77911e1cb Mon Sep 17 00:00:00 2001 From: Andres Caicedo <73312784+AndresCdo@users.noreply.github.com> Date: Wed, 17 May 2023 13:38:42 +0200 Subject: [PATCH] Implement Logging of Self-Feedback in logs/Debug Folder (#3868) * Adds SELF_FEEDBACK_FILE_NAME * Add self-feedback logging to logs/Debug folder * Reformatting * Uses JSON file * Update agent.py Changes position * Update agent.py * Adds PROMPT_FEEDBACK_FILE_NAME * Update agent.py * Update agent.py * Reformatting * Update agent.py * Update agent.py * Changes file names * Update agent.py * Reformatting * Update agent.py * Changes conts names * Update agent_manager.py * Update agent_manager.py * HARD reset * Update test_get_self_feedback.py * Update test_get_self_feedback.py --------- Co-authored-by: merwanehamadi --- autogpt/agent/agent.py | 25 ++++++++++++++++++++++--- autogpt/log_cycle/log_cycle.py | 2 ++ tests/unit/test_get_self_feedback.py | 12 ++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/autogpt/agent/agent.py b/autogpt/agent/agent.py index 68888401913b..e68bf9895463 100644 --- a/autogpt/agent/agent.py +++ b/autogpt/agent/agent.py @@ -13,6 +13,8 @@ from autogpt.log_cycle.log_cycle import ( FULL_MESSAGE_HISTORY_FILE_NAME, NEXT_ACTION_FILE_NAME, + PROMPT_SUPERVISOR_FEEDBACK_FILE_NAME, + SUPERVISOR_FEEDBACK_FILE_NAME, USER_INPUT_FILE_NAME, LogCycleHandler, ) @@ -340,7 +342,24 @@ def get_self_feedback(self, thoughts: dict, llm_model: str) -> str: plan = thoughts.get("plan", "") thought = thoughts.get("thoughts", "") feedback_thoughts = thought + reasoning + plan - return create_chat_completion( - [{"role": "user", "content": feedback_prompt + feedback_thoughts}], - llm_model, + + messages = {"role": "user", "content": feedback_prompt + feedback_thoughts} + + self.log_cycle_handler.log_cycle( + self.config.ai_name, + self.created_at, + self.cycle_count, + messages, + PROMPT_SUPERVISOR_FEEDBACK_FILE_NAME, + ) + + feedback = create_chat_completion(messages) + + self.log_cycle_handler.log_cycle( + self.config.ai_name, + self.created_at, + self.cycle_count, + feedback, + SUPERVISOR_FEEDBACK_FILE_NAME, ) + return feedback diff --git a/autogpt/log_cycle/log_cycle.py b/autogpt/log_cycle/log_cycle.py index cff3ac1a57fb..8daed25c4654 100644 --- a/autogpt/log_cycle/log_cycle.py +++ b/autogpt/log_cycle/log_cycle.py @@ -10,6 +10,8 @@ NEXT_ACTION_FILE_NAME = "next_action.json" PROMPT_SUMMARY_FILE_NAME = "prompt_summary.json" SUMMARY_FILE_NAME = "summary.txt" +SUPERVISOR_FEEDBACK_FILE_NAME = "supervisor_feedback.txt" +PROMPT_SUPERVISOR_FEEDBACK_FILE_NAME = "prompt_supervisor_feedback.json" USER_INPUT_FILE_NAME = "user_input.txt" diff --git a/tests/unit/test_get_self_feedback.py b/tests/unit/test_get_self_feedback.py index e1e9bd4ad4ee..5e59757e1675 100644 --- a/tests/unit/test_get_self_feedback.py +++ b/tests/unit/test_get_self_feedback.py @@ -1,6 +1,9 @@ +from datetime import datetime + from autogpt.agent.agent import Agent from autogpt.config import AIConfig from autogpt.llm import create_chat_completion +from autogpt.log_cycle.log_cycle import LogCycleHandler def test_get_self_feedback(mocker): @@ -31,6 +34,15 @@ def test_get_self_feedback(mocker): # Mock the config attribute of the Agent instance agent_mock.config = AIConfig() + # Mock the log_cycle_handler attribute of the Agent instance + agent_mock.log_cycle_handler = LogCycleHandler() + + # Mock the create_nested_directory method of the LogCycleHandler instance + agent_mock.created_at = datetime.now().strftime("%Y%m%d_%H%M%S") + + # Mock the cycle_count attribute of the Agent instance + agent_mock.cycle_count = 0 + # Call the get_self_feedback method feedback = Agent.get_self_feedback( agent_mock,