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 <merwanehamadi@gmail.com>
This commit is contained in:
Andres Caicedo
2023-05-17 13:38:42 +02:00
committed by GitHub
parent feae20d8fa
commit 7508e9941f
3 changed files with 36 additions and 3 deletions

View File

@@ -13,6 +13,8 @@ from autogpt.llm.token_counter import count_string_tokens
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 @@ class Agent:
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

View File

@@ -10,6 +10,8 @@ CURRENT_CONTEXT_FILE_NAME = "current_context.json"
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"

View File

@@ -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,