🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
feat: archive
莘权 马27c731d11a94
diff --git a/metagpt/actions/prepare_documents.py b/metagpt/actions/prepare_documents.pyindex 7cf05c5d1..b0185996b 100644--- a/metagpt/actions/prepare_documents.py+++ b/metagpt/actions/prepare_documents.py@@ -12,4 +12,14 @@ from metagpt.actions import Actionclass PrepareDocuments(Action):def __init__(self, name="", context=None, llm=None):- pass+ super().__init__(name, context, llm)++ async def run(self, with_message, **kwargs):+ parent = self.context.get("parent")+ if not parent:+ raise ValueError("Invalid owner")+ env = parent.get_env()+ if env.git_repository:+ return+ env.git_repository = GitRepository()+ env.git_repository.open(WORKS)diff --git a/metagpt/environment.py b/metagpt/environment.pyindex b3c296dac..df93a818b 100644--- a/metagpt/environment.py+++ b/metagpt/environment.py@@ -12,7 +12,7 @@functionality is to be consolidated into the `Environment` class."""import asyncio-from typing import Iterable, Set+from typing import Iterable, Optional, Setfrom pydantic import BaseModel, Field@@ -20,6 +20,7 @@ from metagpt.logs import loggerfrom metagpt.roles import Rolefrom metagpt.schema import Messagefrom metagpt.utils.common import is_subscribed+from metagpt.utils.git_repository import GitRepositoryclass Environment(BaseModel):@@ -31,6 +32,7 @@ class Environment(BaseModel):roles: dict[str, Role] = Field(default_factory=dict)consumers: dict[Role, Set] = Field(default_factory=dict)history: str = Field(default="") # For debug+ git_repository: Optional[GitRepository] = Noneclass Config:arbitrary_types_allowed = True@@ -111,3 +113,8 @@ class Environment(BaseModel):def set_subscription(self, obj, tags):"""Set the labels for message to be consumed by the object"""self.consumers[obj] = tags++ def dict(self, *args, **kwargs):+ """Generate a dictionary representation of the model, optionally specifying which fields to include or+ exclude."""+ return super(Environment, self).dict(exclude={"git_repository"})diff --git a/metagpt/roles/product_manager.py b/metagpt/roles/product_manager.pyindex a58ea5385..c10aba6d1 100644--- a/metagpt/roles/product_manager.py+++ b/metagpt/roles/product_manager.py@@ -6,6 +6,7 @@@File : product_manager.py"""from metagpt.actions import BossRequirement, WritePRD+from metagpt.actions.prepare_documents import PrepareDocumentsfrom metagpt.roles import Role@@ -37,5 +38,13 @@ class ProductManager(Role):constraints (str): Constraints or limitations for the product manager."""super().__init__(name, profile, goal, constraints)- self._init_actions([WritePRD])+ self._init_actions([PrepareDocuments(context={"parent": self}), WritePRD])self._watch([BossRequirement])++ async def _think(self) -> None:+ """Decide what to do"""+ if self._rc.env.git_repository:+ self._set_state(1)+ else:+ self._set_state(0)+ return self._rc.tododiff --git a/metagpt/roles/role.py b/metagpt/roles/role.pyindex 2e3bcbbd5..d1e65a4e0 100644--- a/metagpt/roles/role.py+++ b/metagpt/roles/role.py@@ -164,6 +164,10 @@ class Role:if env:env.set_subscription(self, self._subscription)+ def get_env(self):+ """Return the environment in which the role works."""+ return self._rc.env+@propertydef profile(self):"""Get the role description (position)"""