Skip to content

Commit

Permalink
Implement Logging of Self-Feedback in logs/Debug Folder (Significant-…
Browse files Browse the repository at this point in the history
…Gravitas#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 <[email protected]>
  • Loading branch information
2 people authored and ppetermann committed May 22, 2023
1 parent 2e9559c commit 95eb795
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
25 changes: 22 additions & 3 deletions autogpt/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions autogpt/log_cycle/log_cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_get_self_feedback.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 95eb795

Please sign in to comment.