Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a mechanism for self-improvement #353

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Conversation

mczhuge
Copy link

@mczhuge mczhuge commented Sep 21, 2023

Summary of Updates

1️⃣ Internal Feedback Action:
Added the Feedback action in metagpt/actions/internal_feedback.py to allow internal evaluation among agents (currently supporting the handover process).

2️⃣ Action Functions Enhancement:
Introduced two new methods, _add_action_at_head() and _add_action_at_tail(), for improved clarity and ease of defining actions.

3️⃣ Long-Term Memory Utilization:
Commenced utilization of the previously underutilized longterm_memory, currently supporting storage in a JSON file. Future improvements will involve leveraging existing FAISS support.

4️⃣ Reflective Mechanism:
Incorporated the reflect.py module within metagpt/learn.

5️⃣ Initialization with Feedback:
Implemented feedback-driven constraints initialization during role setup, marking the initial phase of our journey towards self-improvement.

These updates address several urgent issues, including effective long-term memory utilization, internal evaluation mechanisms, and the integration of historical data into the self-improvement mechanism. And there is still ample room for improvement beyond these updates. 😄

Quick usage: python startup.py "Write a cli snake game" --self_improvement True

Note: Unit tests are pending implementation due to time constraints and will be added in the near days.

@stellaHSR
Copy link
Collaborator

Excellent! It seems that the HANDOVER_FILE is necessary. Could you kindly provide it as well?

@stellaHSR stellaHSR added the enhancement New feature or request label Sep 26, 2023
metagpt/actions/internal_feedback.py Show resolved Hide resolved
"QaEngineer": {"name": "Edward", "next": None, "prev": "Engineer"},
}

def print_with_color(text, color="red"):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

place it in utils

print(f"{color_codes[color]} {text} {color_codes['reset']}")



Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8

"""

async def run(self, handover_msg, *args, **kwargs) -> ActionOutput:
import re
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import it in file header

import re
#prev_role = handover_msg[0].to_dict()["role"]
#prev_msg = handover_msg[0].to_dict()["content"]
if isinstance(handover_msg, list):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dup space

@@ -38,6 +38,22 @@ def invest(self, investment: float):
CONFIG.max_budget = investment
logger.info(f'Investment: ${investment}.')

def improvement(self, initial=False, roles=None):
handover_file = CONFIG.handover_file
if initial:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to do this in CONFIG?

msgs = self.environment.memory.get_by_action(Feedback)
if isinstance(msgs, list):
for msg in msgs:
logger.info(f"{msg.role}'s feedback: {msg.content}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually prints the feedback result, which is different from the function name. Should we optimize the function name?

Now, rewrite your "{role}" constraints in 30 words:
"""

# def print_with_color(text, color="red"):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove useless comments

# }
# print(f"{color_codes[color]} {text} {color_codes['reset']}")

class Reflect():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class Reflect instead of class Reflect()

class Reflect():
def from_feedback(role, constraints):

chat = OpenAIGPTAPI()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use LLM instead


if run_tests:
# developing features: run tests on the spot and identify bugs
# (bug fixing capability comes soon!)
company.hire([QaEngineer()])

company.invest(investment)

if self_improvement:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need add this first, before hire()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants